-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.sh
executable file
·55 lines (42 loc) · 831 Bytes
/
test.sh
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
#!/bin/sh -eu
# SPDX-License-Identifier: WTFPL
# shellcheck enable=
cd "$(dirname "$0")"
got=$(mktemp favail.XXXXXX)
trap 'rm "$got"' EXIT
init () {
./first-avail-command "$@" > "$got"
}
check () {
diff -u - "$got"
}
error () {
printf "%s\n" "$*"
exit 1
}
# extra args
init sh -- -c "echo foo"
echo foo | check
# extra args 2
init "sh -c" -- "echo foo"
echo foo | check
# ignore non-existing command
init DOESNOTEXIST sh -- -c "echo foo"
echo foo | check
# run "true" first
init true false --
# run "false" first, propagate code
if init false true --
then
error "should have returned 1"
fi
# missing "--"
if init sh 2>/dev/null
then
error "should have failed because of missing --"
fi
# only non-existing commands
if init DOESNOTEXIST -- 2>/dev/null
then
error "should have failed because no command exists"
fi