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>
96 lines
2.8 KiB
Bash
96 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 head port. src/tests/usr.bin/head does not exist, so these are
|
|
# the cases of head.1: the first count lines of each file, 10 by default,
|
|
# -c for bytes, the "==> XXX <==" header with several files or -v and -q to
|
|
# switch it off, the historic -count syntax, and the exit status.
|
|
#
|
|
# Usage: test.sh HEAD DATADIR
|
|
# HEAD 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 head)
|
|
# Prints one line per case and exits non-zero if one failed.
|
|
|
|
[ $# -eq 2 ] || { echo "usage: $0 HEAD DATADIR" >&2; exit 2; }
|
|
hd=$1
|
|
fails=0
|
|
t=${TMPDIR:-/tmp}/head-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 EXPECTED-FILE: compare $t/out with it
|
|
if cmp -s "$2" "$t/out"; then ok "$1"; else no "$1"; fi
|
|
}
|
|
|
|
# f1: twelve lines l1..l12 (59 bytes), f2: two lines x, y
|
|
printf 'l1\nl2\nl3\nl4\nl5\nl6\nl7\nl8\nl9\nl10\nl11\nl12\n' > f1
|
|
printf 'x\ny\n' > f2
|
|
|
|
# head.1 lines 45-51: the first count lines, 10 if count is omitted
|
|
$hd f1 > out
|
|
printf 'l1\nl2\nl3\nl4\nl5\nl6\nl7\nl8\nl9\nl10\n' > exp
|
|
same default-10 exp
|
|
|
|
# head.1 lines 41, 45-51: -n count, 10 by default
|
|
$hd -n 3 f1 > out
|
|
printf 'l1\nl2\nl3\n' > exp
|
|
same n-3 exp
|
|
|
|
# head.1 lines 42, 52-56: -c counts bytes instead of lines ("l1\nl" = 4 bytes,
|
|
# one more is "l1\nl2")
|
|
$hd -c 5 f1 > out
|
|
printf 'l1\nl2' > exp
|
|
same c-5 exp
|
|
|
|
# head.1 lines 45-48: "This filter displays the first count lines of each of
|
|
# the specified files, or of the standard input if no files are specified"
|
|
$hd -n 2 < f1 > out
|
|
printf 'l1\nl2\n' > exp
|
|
same stdin exp
|
|
|
|
# head.1 lines 58-62: with more than one file each is preceded by
|
|
# "==> XXX <==", and the second and later ones are separated by a blank line
|
|
$hd f1 f2 > out
|
|
{
|
|
printf '==> f1 <==\n'
|
|
printf 'l1\nl2\nl3\nl4\nl5\nl6\nl7\nl8\nl9\nl10\n'
|
|
printf '\n==> f2 <==\n'
|
|
printf 'x\ny\n'
|
|
} > exp
|
|
same two-files-headers exp
|
|
|
|
# head.1 lines 66-68: "The -q flag disables the printing of the header"
|
|
$hd -q f1 f2 > out
|
|
{
|
|
printf 'l1\nl2\nl3\nl4\nl5\nl6\nl7\nl8\nl9\nl10\n'
|
|
printf 'x\ny\n'
|
|
} > exp
|
|
same q-no-headers exp
|
|
|
|
# head.1 lines 58-60: -v prints the header for a single file too
|
|
$hd -v f2 > out
|
|
printf '==> f2 <==\nx\ny\n' > exp
|
|
same v-one-file exp
|
|
|
|
# head.1 COMPATIBILITY lines 70-73: "The historic command line syntax of
|
|
# head is supported" -- -2 means -n 2
|
|
$hd -2 f1 > out
|
|
printf 'l1\nl2\n' > exp
|
|
same historic-2 exp
|
|
|
|
# head.1 EXIT STATUS (Ex -std): >0 if a file cannot be read, and a message
|
|
if $hd no-such-file > out 2> err; then
|
|
no missing-file-exit
|
|
elif [ -s err ]; then
|
|
ok missing-file-exit
|
|
else
|
|
no missing-file-exit
|
|
fi
|
|
|
|
echo "head: $fails failed"
|
|
[ "$fails" -eq 0 ]
|