consmirror.c: the BSD notice is replaced (Makronix's own file). Files with changes of other sessions pending are left for their commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
84 lines
2.8 KiB
Bash
84 lines
2.8 KiB
Bash
#!/bin/sh
|
|
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
#
|
|
# Test of the tee port. src/tests/usr.bin/tee does not exist, so these are
|
|
# the cases of tee.1: standard input copied to standard output and to zero or
|
|
# more files, -a to append instead of overwriting, -i to ignore SIGINT, and
|
|
# the exit status when a file cannot be opened.
|
|
#
|
|
# Usage: test.sh TEE DATADIR
|
|
# TEE the command that runs the port (a path, or "qemu-aarch64 -L
|
|
# <sysroot> <path>"; tools/userland-test.sh passes it)
|
|
# DATADIR unused (NetBSD has no test for tee)
|
|
# Prints one line per case and exits non-zero if one failed.
|
|
|
|
[ $# -eq 2 ] || { echo "usage: $0 TEE DATADIR" >&2; exit 2; }
|
|
t_=$1
|
|
fails=0
|
|
t=${TMPDIR:-/tmp}/tee-test.$$
|
|
mkdir -p "$t" || exit 1
|
|
trap 'rm -rf "$t"' EXIT
|
|
cd "$t" || exit 1
|
|
|
|
ok() { echo "PASS $1"; }
|
|
no() { echo "FAIL $1"; fails=$((fails + 1)); }
|
|
same() { # NAME FILE EXPECTED-FILE: compare FILE with EXPECTED-FILE
|
|
if cmp -s "$2" "$3"; then ok "$1"; else no "$1"; fi
|
|
}
|
|
|
|
# tee.1 lines 48-49: the input is "copied ... to standard output, making a
|
|
# copy in zero or more files" -- with no file operand only the standard
|
|
# output is written
|
|
printf 'a\nb\n' > exp
|
|
printf 'a\nb\n' | $t_ > out
|
|
same stdout-only out exp
|
|
|
|
# tee.1 lines 65-67: a file operand is "a pathname of an output file"
|
|
printf 'x\ny\n' > exp2
|
|
printf 'x\ny\n' | $t_ f1 > out
|
|
same one-file-stdout out exp2
|
|
same one-file-file f1 exp2
|
|
|
|
# tee.1 lines 48-49, 63-67: several files, each a copy of the input
|
|
printf 'p\nq\n' > exp3
|
|
printf 'p\nq\n' | $t_ f2 f3 > out
|
|
same two-files-stdout out exp3
|
|
same two-files-first f2 exp3
|
|
same two-files-second f3 exp3
|
|
|
|
# tee.1 lines 54-56: -a appends "rather than overwriting"; the file's
|
|
# earlier content stays in front of what is copied now
|
|
printf '1\n' > f4
|
|
printf '2\n' | $t_ -a f4 > out
|
|
printf '1\n2\n' > exp4
|
|
same append-file f4 exp4
|
|
printf '2\n' > exp5
|
|
same append-stdout out exp5
|
|
|
|
# tee.1 lines 57-60: -i ignores SIGINT. The signal itself is not sent here
|
|
# (it needs a way to signal the running port that survives qemu); the option
|
|
# must be accepted and the copy happens as without it.
|
|
printf 'z\n' | $t_ -i f5 > out
|
|
printf 'z\n' > exp6
|
|
same ignore-sigint-file f5 exp6
|
|
same ignore-sigint-stdout out exp6
|
|
|
|
# tee.1 lines 76-77, EXIT STATUS (Ex -std tee): >0 "if an error occurs". A file that
|
|
# cannot be opened in a directory that does not exist is an error, and it is
|
|
# reported on the standard error.
|
|
if printf 'q\n' | $t_ nodir/f6 > out 2> err; then
|
|
no unopenable-file-exit
|
|
elif [ -s err ]; then
|
|
ok unopenable-file-exit
|
|
else
|
|
no unopenable-file-exit
|
|
fi
|
|
|
|
# tee.1 lines 48-49: the standard output still gets its copy, the file that
|
|
# failed being the only thing lost
|
|
printf 'q\n' > exp7
|
|
same unopenable-file-stdout out exp7
|
|
|
|
echo "tee: $fails failed"
|
|
[ "$fails" -eq 0 ]
|