summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2020-11-17 21:13:14 +0100
committerUlrich Müller <ulm@gentoo.org>2020-11-23 19:01:12 +0100
commit754aa946555ccc3f6657922d91a1d2c34b419053 (patch)
tree13756e8ce45aa3b1c710f4a09ba41d62eaf2fe42 /eclass/tests
parenteapi8-dosym.eclass: New eclass. (diff)
downloadgentoo-754aa946555ccc3f6657922d91a1d2c34b419053.tar.gz
gentoo-754aa946555ccc3f6657922d91a1d2c34b419053.tar.bz2
gentoo-754aa946555ccc3f6657922d91a1d2c34b419053.zip
eclass/tests: Initial test cases for eapi8-dosym.eclass.
Signed-off-by: Ulrich Müller <ulm@gentoo.org>
Diffstat (limited to 'eclass/tests')
-rwxr-xr-xeclass/tests/eapi8-dosym.sh78
1 files changed, 78 insertions, 0 deletions
diff --git a/eclass/tests/eapi8-dosym.sh b/eclass/tests/eapi8-dosym.sh
new file mode 100755
index 000000000000..e1160c42d875
--- /dev/null
+++ b/eclass/tests/eapi8-dosym.sh
@@ -0,0 +1,78 @@
+#!/bin/bash
+# Copyright 2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+source tests-common.sh
+
+inherit eapi8-dosym
+
+dosym() {
+ echo "$1"
+}
+
+# reference implementation using GNU realpath
+ref_canonicalize() {
+ realpath -m -s "$1"
+}
+
+ref_dosym_r() {
+ local link=$(realpath -m -s "/${2#/}")
+ realpath -m -s --relative-to="$(dirname "${link}")" "$1"
+}
+
+randompath() {
+ dd if=/dev/urandom bs=128 count=1 2>/dev/null | LC_ALL=C sed \
+ -e 's/[^a-zA-M]//g;s/[A-E]/\/.\//g;s/[F-J]/\/..\//g;s/[K-M]/\//g' \
+ -e 's/^/\//;q'
+}
+
+teq() {
+ local expected=$1; shift
+ tbegin "$* -> ${expected}"
+ local got=$("$@")
+ [[ ${got} == "${expected}" ]]
+ tend $? "returned: ${got}"
+}
+
+for f in ref_canonicalize "_dosym8_canonicalize"; do
+ # canonicalize absolute paths
+ teq / ${f} /
+ teq /foo/baz/quux ${f} /foo/bar/../baz/quux
+ teq /foo ${f} /../../../foo
+ teq /bar ${f} /foo//./..///bar
+ teq /baz ${f} /foo/bar/../../../baz
+ teq /a/d/f/g ${f} /a/b/c/../../d/e/../f/g
+done
+
+# canonicalize relative paths (not actually used)
+teq . _dosym8_canonicalize .
+teq foo _dosym8_canonicalize foo
+teq foo _dosym8_canonicalize ./foo
+teq ../foo _dosym8_canonicalize ../foo
+teq ../baz _dosym8_canonicalize foo/bar/../../../baz
+
+for f in ref_dosym_r "dosym8 -r"; do
+ teq ../../bin/foo ${f} /bin/foo /usr/bin/foo
+ teq ../../../doc/foo-1 \
+ ${f} /usr/share/doc/foo-1 /usr/share/texmf-site/doc/fonts/foo
+ teq ../../opt/bar/foo ${f} /opt/bar/foo /usr/bin/foo
+ teq ../c/d/e ${f} /a/b/c/d/e a/b/f/g
+ teq b/f ${f} /a/b///./c/d/../e/..//../f /a/././///g/../h
+ teq ../h ${f} /a/././///g/../h /a/b///./c/d/../e/..//../f
+ teq . ${f} /foo /foo/bar
+ teq .. ${f} /foo /foo/bar/baz
+ teq '../../fo . o/b ar' ${f} '/fo . o/b ar' '/baz / qu .. ux/qu x'
+ teq '../../f"o\o/b$a[]r' ${f} '/f"o\o/b$a[]r' '/ba\z/qu$u"x/qux'
+done
+
+# set RANDOMTESTS to a positive number to enable random tests
+for (( i = 0; i < RANDOMTESTS; i++ )); do
+ targ=$(randompath)
+ link=$(randompath)
+ out=$(ref_dosym_r "${targ}" "${link}")
+ teq "${out}" dosym8 -r "${targ}" "${link}"
+done
+
+texit