Initial import
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
#!/bin/sh
|
||||
# POSIX smoke for the agent-facing lines tool.
|
||||
# req: cli/001
|
||||
# req: cli/001.e1
|
||||
# req: cli/002
|
||||
# req: robustness/001
|
||||
# req: robustness/002
|
||||
# req: robustness/003
|
||||
# req: robustness/004
|
||||
# req: robustness/005
|
||||
# req: verification/001
|
||||
# req: verification/002
|
||||
|
||||
set -eu
|
||||
|
||||
bin=${1:-zig-out/bin/lines}
|
||||
tmp=${TMPDIR:-/tmp}/lines-smoke.$$
|
||||
trap 'rm -f "$tmp".*' EXIT HUP INT TERM
|
||||
|
||||
printf 'a\nb\nc\n' > "$tmp.in"
|
||||
printf 'b\nc\n' > "$tmp.want"
|
||||
"$bin" "$tmp.in" 2 3 > "$tmp.out"
|
||||
cmp "$tmp.want" "$tmp.out"
|
||||
|
||||
"$bin" --help > "$tmp.out"
|
||||
grep 'stdout: selected file lines only' "$tmp.out" >/dev/null
|
||||
grep 'exit status:' "$tmp.out" >/dev/null
|
||||
grep 'No writes, no regex, no program language' "$tmp.out" >/dev/null
|
||||
|
||||
: > "$tmp.empty"
|
||||
"$bin" "$tmp.empty" 1 > "$tmp.out"
|
||||
[ ! -s "$tmp.out" ]
|
||||
|
||||
printf 'tail-no-newline' > "$tmp.nonewline"
|
||||
printf 'tail-no-newline' > "$tmp.want"
|
||||
"$bin" "$tmp.nonewline" 1 > "$tmp.out"
|
||||
cmp "$tmp.want" "$tmp.out"
|
||||
|
||||
printf 'a\r\nb\r\n' > "$tmp.crlf"
|
||||
printf 'b\r\n' > "$tmp.want"
|
||||
"$bin" "$tmp.crlf" 2 > "$tmp.out"
|
||||
cmp "$tmp.want" "$tmp.out"
|
||||
|
||||
awk 'BEGIN { for (i = 0; i < 70000; i++) printf "x"; printf "\nsecond\n" }' > "$tmp.long"
|
||||
awk 'BEGIN { for (i = 0; i < 70000; i++) printf "x"; printf "\n" }' > "$tmp.want"
|
||||
"$bin" "$tmp.long" 1 > "$tmp.out"
|
||||
cmp "$tmp.want" "$tmp.out"
|
||||
|
||||
printf 'ok\n\377\000x\n' > "$tmp.binary"
|
||||
printf '\377\000x\n' > "$tmp.want"
|
||||
"$bin" "$tmp.binary" 2 > "$tmp.out"
|
||||
cmp "$tmp.want" "$tmp.out"
|
||||
|
||||
"$bin" "$tmp.in" 18446744073709551615 > "$tmp.out"
|
||||
[ ! -s "$tmp.out" ]
|
||||
|
||||
if "$bin" "$tmp.in" 0 > "$tmp.out" 2> "$tmp.err"; then
|
||||
echo 'smoke: invalid START unexpectedly succeeded' >&2
|
||||
exit 1
|
||||
fi
|
||||
[ ! -s "$tmp.out" ]
|
||||
grep 'START must be positive' "$tmp.err" >/dev/null
|
||||
|
||||
if "$bin" "$tmp.in" 3 2 > "$tmp.out" 2> "$tmp.err"; then
|
||||
echo 'smoke: END < START unexpectedly succeeded' >&2
|
||||
exit 1
|
||||
fi
|
||||
[ ! -s "$tmp.out" ]
|
||||
grep 'END must be >= START' "$tmp.err" >/dev/null
|
||||
|
||||
if "$bin" "$tmp.missing" 1 > "$tmp.out" 2> "$tmp.err"; then
|
||||
echo 'smoke: missing file unexpectedly succeeded' >&2
|
||||
exit 1
|
||||
fi
|
||||
[ ! -s "$tmp.out" ]
|
||||
grep 'lines: .*missing' "$tmp.err" >/dev/null
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
printf 'secret\n' > "$tmp.denied"
|
||||
chmod 000 "$tmp.denied"
|
||||
if "$bin" "$tmp.denied" 1 > "$tmp.out" 2> "$tmp.err"; then
|
||||
chmod 600 "$tmp.denied"
|
||||
echo 'smoke: permission-denied file unexpectedly succeeded' >&2
|
||||
exit 1
|
||||
fi
|
||||
chmod 600 "$tmp.denied"
|
||||
[ ! -s "$tmp.out" ]
|
||||
grep 'lines: .*denied' "$tmp.err" >/dev/null
|
||||
fi
|
||||
|
||||
"$bin" "$tmp.long" 1 2 2> "$tmp.err" | head -n 1 > /dev/null
|
||||
[ ! -s "$tmp.err" ]
|
||||
Reference in New Issue
Block a user