blob: c750310b72deaf643b1ab6c6e073d665bee5abd8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/bin/sh
set -e
cd "${0%/*}"
exec 2>&1
check() {
for arg in $1; do
read -r line || { echo "FAIL: insufficient output" >&2; return 1; }
echo "GOT: $line"
case "$arg" in
[a-z]) case "$line" in "in $arg "*) ;; *) echo "FAIL: expected $arg" >&2; return 1; esac;;
err) case "$line" in nextbin*failed*) ;; *) echo "FAIL: expected err" >&2; return 1; esac;;
*) echo "INVALID TEST" >&2; exit 1
esac
done
if read -r line; then
echo "FAIL: too much output" >&2
return 1
fi
echo "OK"
}
try() {
# shellcheck disable=SC2016
printf 'TEST: PATH="%s:$PATH:%s" %s, expect %s\n' "${PWD%/test}" "$@"
PATH="$PATH:$1" "$2" 2>&1 | check "$3"
# shellcheck disable=SC2016
printf 'TEST: PATH="%s:%s:$PATH" %s, expect %s\n' "${PWD%/test}" "$@"
PATH="$1:$PATH" "$2" 2>&1 | check "$3"
}
do_try() {
try "$1" "$2/x" "$3"
try "$1" "$2//x" "$3"
try "$1" "./$2/x" "$3"
try "$1" "$PWD/$2/x" "$3"
try "$1" "$2/../$2/x" "$3"
try "$1" "./$2/../$2/x" "$3"
try "$1" "$PWD/$2/../$2/x" "$3"
echo
}
# use do_try2 if x in PATH
do_try2() {
try "$1" "x" "$3"
do_try "$@"
}
export PATH="${PWD%/test}:$PATH"
do_try "" a "a err"
do_try2 "$PWD/a" a "a err"
do_try "$PWD/b" a "a b err"
do_try2 "$PWD/a:$PWD/b" a "a b err"
do_try "$PWD/a:$PWD/b" b "b err"
do_try2 "$PWD/a:$PWD/b:$PWD/c" a "a b c"
do_try "$PWD/a:$PWD/b:$PWD/c" b "b c"
do_try2 "$PWD/a:$PWD/a" a "a err"
echo "ALL TESTS COMPLETED SUCCESSFULLY :)"
|