Gentoo Archives: gentoo-dev

From: "Ulrich Müller" <ulm@g.o>
To: gentoo-dev@l.g.o
Cc: "Ulrich Müller" <ulm@g.o>
Subject: [gentoo-dev] [PATCH 2/2] eclass/tests: Initial test cases for eapi8-dosym.eclass.
Date: Thu, 19 Nov 2020 10:33:08
Message-Id: 20201119103150.22841-2-ulm@gentoo.org
In Reply to: [gentoo-dev] [PATCH 1/2] eapi8-dosym.eclass: New eclass. by "Ulrich Müller"
1 Signed-off-by: Ulrich Müller <ulm@g.o>
2 ---
3 eclass/tests/eapi8-dosym.sh | 78 +++++++++++++++++++++++++++++++++++++
4 1 file changed, 78 insertions(+)
5 create mode 100755 eclass/tests/eapi8-dosym.sh
6
7 diff --git a/eclass/tests/eapi8-dosym.sh b/eclass/tests/eapi8-dosym.sh
8 new file mode 100755
9 index 000000000000..ac1defc6c5f1
10 --- /dev/null
11 +++ b/eclass/tests/eapi8-dosym.sh
12 @@ -0,0 +1,78 @@
13 +#!/bin/bash
14 +# Copyright 2020 Gentoo Authors
15 +# Distributed under the terms of the GNU General Public License v2
16 +
17 +EAPI=7
18 +
19 +source tests-common.sh
20 +
21 +inherit eapi8-dosym
22 +
23 +dosym() {
24 + echo "$1"
25 +}
26 +
27 +# reference implementation using GNU realpath
28 +ref_canonicalize() {
29 + realpath -m -s "$1"
30 +}
31 +
32 +ref_dosym_r() {
33 + local link=$(realpath -m -s "/${2#/}")
34 + realpath -m -s --relative-to="$(dirname "${link}")" "$1"
35 +}
36 +
37 +randompath() {
38 + dd if=/dev/urandom bs=128 count=1 2>/dev/null | LC_ALL=C sed \
39 + -e 's/[^a-zA-M]//g;s/[A-E]/\/.\//g;s/[F-J]/\/..\//g;s/[K-M]/\//g' \
40 + -e 's/^/\//;q'
41 +}
42 +
43 +teq() {
44 + local expected=$1; shift
45 + tbegin "$* -> ${expected}"
46 + local got=$("$@")
47 + [[ ${got} == "${expected}" ]]
48 + tend $? "returned: ${got}"
49 +}
50 +
51 +for f in ref_canonicalize "_dosym8_canonicalize"; do
52 + # canonicalize absolute paths
53 + teq / ${f} /
54 + teq /foo/baz/quux ${f} /foo/bar/../baz/quux
55 + teq /foo ${f} /../../../foo
56 + teq /bar ${f} /foo//./..///bar
57 + teq /baz ${f} /foo/bar/../../../baz
58 + teq /a/d/f/g ${f} /a/b/c/../../d/e/../f/g
59 +
60 + # canonicalize relative paths (not actually used)
61 + teq . _dosym8_canonicalize .
62 + teq foo _dosym8_canonicalize foo
63 + teq foo _dosym8_canonicalize ./foo
64 + teq ../foo _dosym8_canonicalize ../foo
65 + teq ../baz _dosym8_canonicalize foo/bar/../../../baz
66 +done
67 +
68 +for f in ref_dosym_r "dosym8 -r"; do
69 + teq ../../bin/foo ${f} /bin/foo /usr/bin/foo
70 + teq ../../../doc/foo-1 \
71 + ${f} /usr/share/doc/foo-1 /usr/share/texmf-site/doc/fonts/foo
72 + teq ../../opt/bar/foo ${f} /opt/bar/foo /usr/bin/foo
73 + teq ../c/d/e ${f} /a/b/c/d/e a/b/f/g
74 + teq b/f ${f} /a/b///./c/d/../e/..//../f /a/././///g/../h
75 + teq ../h ${f} /a/././///g/../h /a/b///./c/d/../e/..//../f
76 + teq . ${f} /foo /foo/bar
77 + teq .. ${f} /foo /foo/bar/baz
78 + teq '../../fo . o/b ar' ${f} '/fo . o/b ar' '/baz / qu .. ux/qu x'
79 + teq '../../f"o\o/b$a[]r' ${f} '/f"o\o/b$a[]r' '/ba\z/qu$u"x/qux'
80 +done
81 +
82 +# set RANDOMTESTS to a positive number to enable random tests
83 +for (( i = 0; i < RANDOMTESTS; i++ )); do
84 + targ=$(randompath)
85 + link=$(randompath)
86 + out=$(ref_dosym_r "${targ}" "${link}")
87 + teq "${out}" dosym8 -r "${targ}" "${link}"
88 +done
89 +
90 +texit
91 --
92 2.29.2