This repository has been archived on 2026-07-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
facts/smoke.sh
T
2026-07-04 20:44:28 +02:00

118 lines
3.9 KiB
Bash
Executable File

#!/bin/sh
set -eu
tool=${1:-zig-out/bin/facts}
work=.zig-cache/facts-smoke
mkdir -p "$work/dir"
printf abc > "$work/a.txt"
wait_for_line() {
pattern=$1
file=$2
label=$3
i=0
while [ "$i" -lt 50 ]; do
if grep -q "$pattern" "$file" 2>/dev/null; then
return 0
fi
i=$((i + 1))
sleep 0.1
done
echo "facts smoke: timed out waiting for $label" >&2
if [ -n "${stream_pid:-}" ]; then
kill "$stream_pid" 2>/dev/null || true
fi
exit 1
}
"$tool" "$work/a.txt" "$work/dir" > "$work/arg.out"
head -n 1 "$work/arg.out" | grep -q '^path kind size mode mtime_ns$'
grep -q "^$work/a.txt file 3 " "$work/arg.out"
grep -q "^$work/dir dir " "$work/arg.out"
printf '%s\n' "$work/a.txt" | "$tool" > "$work/stdin.out"
grep -q "^$work/a.txt file 3 " "$work/stdin.out"
tab_path="$work/tab name"
printf x > "$tab_path"
if "$tool" "$tab_path" > "$work/tab-argv.out" 2> "$work/tab-argv.err"; then
echo 'facts: argv tab path unexpectedly succeeded' >&2
exit 1
fi
test "$(wc -l < "$work/tab-argv.out" | tr -d ' ')" -eq 1
grep -q '^path kind size mode mtime_ns$' "$work/tab-argv.out"
grep -q 'contains tab' "$work/tab-argv.err"
if printf '%s\n' "$tab_path" | "$tool" > "$work/tab-stdin.out" 2> "$work/tab-stdin.err"; then
echo 'facts: stdin tab path unexpectedly succeeded' >&2
exit 1
fi
test "$(wc -l < "$work/tab-stdin.out" | tr -d ' ')" -eq 1
grep -q '^path kind size mode mtime_ns$' "$work/tab-stdin.out"
grep -q 'contains tab' "$work/tab-stdin.err"
newline_path=$(printf '%s/new\nname' "$work")
printf y > "$newline_path"
if "$tool" "$newline_path" > "$work/newline-argv.out" 2> "$work/newline-argv.err"; then
echo 'facts: argv newline path unexpectedly succeeded' >&2
exit 1
fi
test "$(wc -l < "$work/newline-argv.out" | tr -d ' ')" -eq 1
grep -q '^path kind size mode mtime_ns$' "$work/newline-argv.out"
grep -q 'contains newline' "$work/newline-argv.err"
cr_path=$(printf '%s/cr\rname' "$work")
printf z > "$cr_path"
if "$tool" "$cr_path" > "$work/cr-argv.out" 2> "$work/cr-argv.err"; then
echo 'facts: argv carriage-return path unexpectedly succeeded' >&2
exit 1
fi
test "$(wc -l < "$work/cr-argv.out" | tr -d ' ')" -eq 1
grep -q '^path kind size mode mtime_ns$' "$work/cr-argv.out"
grep -q 'contains carriage return' "$work/cr-argv.err"
if printf '%s\r\n' "$work/a.txt" | "$tool" > "$work/cr-stdin.out" 2> "$work/cr-stdin.err"; then
echo 'facts: stdin carriage-return path unexpectedly succeeded' >&2
exit 1
fi
test "$(wc -l < "$work/cr-stdin.out" | tr -d ' ')" -eq 1
grep -q '^path kind size mode mtime_ns$' "$work/cr-stdin.out"
grep -q 'contains carriage return' "$work/cr-stdin.err"
stream_in=$work/stream.in
rm -f "$stream_in"
mkfifo "$stream_in"
stream_out=$work/stream.out
stream_err=$work/stream.err
: > "$stream_out"
: > "$stream_err"
stream_pid=
"$tool" < "$stream_in" > "$stream_out" 2> "$stream_err" &
stream_pid=$!
exec 3> "$stream_in"
wait_for_line '^path kind size mode mtime_ns$' "$stream_out" 'streaming header before stdin EOF'
printf '%s\n' "$work/a.txt" >&3
wait_for_line "^$work/a.txt file 3 " "$stream_out" 'first streaming record before stdin EOF'
kill -0 "$stream_pid"
printf '%s\n' "$work/dir" >&3
wait_for_line "^$work/dir dir " "$stream_out" 'second streaming record before stdin EOF'
exec 3>&-
wait "$stream_pid"
stream_pid=
rm -f "$stream_in"
if [ -s "$stream_err" ]; then
cat "$stream_err" >&2
exit 1
fi
"$tool" --help > "$work/help.out"
grep -q '^usage: facts \[PATH\.\.\.\]' "$work/help.out"
! grep -q '^path kind size mode mtime_ns$' "$work/help.out"
"$tool" -h > "$work/help-short.out"
grep -q '^usage: facts \[PATH\.\.\.\]' "$work/help-short.out"
! grep -q '^path kind size mode mtime_ns$' "$work/help-short.out"
if "$tool" "$work/a.txt" "$work/missing" > "$work/error.out" 2> "$work/error.err"; then
echo 'facts: missing path unexpectedly succeeded' >&2
exit 1
fi
grep -q "^$work/a.txt file 3 " "$work/error.out"
grep -q "^facts: $work/missing: " "$work/error.err"