40 lines
1.2 KiB
Bash
40 lines
1.2 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
tool=${1:-zig-out/bin/have}
|
|
mkdir -p .zig-cache/have-smoke/bin
|
|
cat > .zig-cache/have-smoke/bin/ok <<'SCRIPT'
|
|
#!/bin/sh
|
|
exit 0
|
|
SCRIPT
|
|
chmod +x .zig-cache/have-smoke/bin/ok
|
|
printf 'nope' > .zig-cache/have-smoke/bin/not-exec
|
|
|
|
PATH=.zig-cache/have-smoke/bin "$tool" > .zig-cache/have-list.out
|
|
grep -q '^ok$' .zig-cache/have-list.out
|
|
if grep -q '^not-exec$' .zig-cache/have-list.out; then
|
|
echo 'have: listed non-executable file' >&2
|
|
exit 1
|
|
fi
|
|
PATH=.zig-cache/have-smoke/bin "$tool" ok missing > .zig-cache/have-query.out && {
|
|
echo 'have: query succeeded despite missing command' >&2
|
|
exit 1
|
|
}
|
|
grep -q '^ok$' .zig-cache/have-query.out
|
|
if grep -q '^missing$' .zig-cache/have-query.out; then
|
|
echo 'have: printed missing command' >&2
|
|
exit 1
|
|
fi
|
|
|
|
"$tool" --help > .zig-cache/have-help.out 2> .zig-cache/have-help.err
|
|
grep -q '^usage: have \[NAME\.\.\.\]' .zig-cache/have-help.out
|
|
if [ -s .zig-cache/have-help.err ]; then
|
|
echo 'have: --help wrote stderr' >&2
|
|
exit 1
|
|
fi
|
|
"$tool" -h > .zig-cache/have-help-short.out 2> .zig-cache/have-help-short.err
|
|
grep -q '^usage: have \[NAME\.\.\.\]' .zig-cache/have-help-short.out
|
|
if [ -s .zig-cache/have-help-short.err ]; then
|
|
echo 'have: -h wrote stderr' >&2
|
|
exit 1
|
|
fi
|