blob: 09ff98ef9d67ab276fe1d44dcd624adce6e28a47 (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
|
failures=0
check_eq() {
actual=$1
expected=$2
label=$3
if [ "$actual" != "$expected" ]; then
echo "Failed: $label"
echo " expected: $expected"
echo " actual: $actual"
failures=$((failures + 1))
fi
}
check_match() {
actual=$1
pattern=$2
label=$3
case $actual in
$pattern)
;;
*)
echo "Failed: $label"
echo " expected pattern: $pattern"
echo " actual: $actual"
failures=$((failures + 1))
;;
esac
}
mkdir pathbin
cat >pathbin/cmdprobe <<'EOF'
#!/bin/sh
exit 0
EOF
chmod +x pathbin/cmdprobe
probe_dir=$PWD/pathbin
probe_path=$probe_dir/cmdprobe
check_eq "$(PATH=$probe_dir command -V cmdprobe)" \
"cmdprobe is $probe_path" \
'PATH=$probe_dir command -V cmdprobe'
check_eq "$(PATH=$probe_dir command -V cmdprobe; :)" \
"cmdprobe is $probe_path" \
'PATH=$probe_dir command -V cmdprobe; :'
check_eq "$(PATH=$probe_dir command -pv cmdprobe)" \
"" \
'PATH=$probe_dir command -pv cmdprobe'
check_eq "$(PATH=$probe_dir command -pv cmdprobe; :)" \
"" \
'PATH=$probe_dir command -pv cmdprobe; :'
PATH=$probe_dir:$PATH
check_eq "$(command -V cmdprobe)" \
"cmdprobe is $probe_path" \
'PATH prefixed command -V cmdprobe'
check_eq "$(command -V cmdprobe; :)" \
"cmdprobe is $probe_path" \
'PATH prefixed command -V cmdprobe; :'
check_eq "$(command -pv cmdprobe)" \
"" \
'PATH prefixed command -pv cmdprobe'
check_eq "$(command -pv cmdprobe; :)" \
"" \
'PATH prefixed command -pv cmdprobe; :'
PATH=$probe_dir
check_eq "$(command -v ls)" "" 'PATH isolated command -v ls'
check_match "$(command -pv ls)" '/*/ls' 'PATH isolated command -pv ls'
exit $((failures > 0))
|