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>
76 lines
2.6 KiB
Bash
76 lines
2.6 KiB
Bash
#!/bin/sh
|
|
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
#
|
|
# Test of the fold port. src/tests/usr.bin/fold does not exist, so there is
|
|
# no NetBSD test to translate; the cases are the ones fold(1) documents: the
|
|
# default width of 80, -w, -s ("Fold line after the last blank character
|
|
# within the first width ... If a blank character does not exist within the
|
|
# width, then a longer line will still be split at the width"), and -b
|
|
# ("Count width in bytes rather than column positions").
|
|
#
|
|
# The input is made here, since the port has no test data in src/.
|
|
#
|
|
# Usage: test.sh FOLD DATADIR
|
|
# FOLD the command that runs the port (a path, or "qemu-aarch64 -L
|
|
# <sysroot> <path>"; tools/userland-test.sh passes it)
|
|
# DATADIR unused (src/tests/usr.bin/fold does not exist)
|
|
# Prints one line per case and exits non-zero if one failed.
|
|
|
|
[ $# -eq 2 ] || { echo "usage: $0 FOLD DATADIR" >&2; exit 2; }
|
|
fold=$1 d=$2
|
|
fails=0
|
|
t=${TMPDIR:-/tmp}/fold-test.$$
|
|
mkdir -p "$t" || exit 1
|
|
trap 'rm -rf "$t"' EXIT
|
|
LC_ALL=C
|
|
export LC_ALL
|
|
|
|
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
|
|
}
|
|
rep() { # rep COUNT STRING: STRING repeated COUNT times
|
|
_n=$1 _s=
|
|
while [ "$_n" -gt 0 ]; do _s="$_s$2"; _n=$((_n - 1)); done
|
|
printf '%s' "$_s"
|
|
}
|
|
|
|
# fold(1): "breaking the lines to have a maximum of 80 characters" -- 100
|
|
# characters become 80 and 20.
|
|
rep 100 a > "$t/in"
|
|
printf '\n' >> "$t/in"
|
|
{ rep 80 a; printf '\n'; rep 20 a; printf '\n'; } > "$t/exp"
|
|
$fold < "$t/in" > "$t/out"
|
|
same default-width "$t/exp"
|
|
|
|
# fold(1) -w width: 7 characters at width 4 become 4 and 3.
|
|
printf 'abcdefg\n' > "$t/in"
|
|
printf 'abcd\nefg\n' > "$t/exp"
|
|
$fold -w 4 < "$t/in" > "$t/out"
|
|
same width-option "$t/exp"
|
|
|
|
# fold(1) -s: the line is folded "after the last blank character within the
|
|
# first width column positions", and that blank is dropped.
|
|
printf 'aaaa bbbb cccc\n' > "$t/in"
|
|
printf 'aaaa bbbb\ncccc\n' > "$t/exp"
|
|
$fold -s -w 10 < "$t/in" > "$t/out"
|
|
same split-at-blank "$t/exp"
|
|
|
|
# fold(1) -s without a blank in the width: "a longer line will still be split
|
|
# at the width".
|
|
printf 'abcdefgh\n' > "$t/in"
|
|
printf 'abcd\nefgh\n' > "$t/exp"
|
|
$fold -s -w 4 < "$t/in" > "$t/out"
|
|
same split-without-blank "$t/exp"
|
|
|
|
# fold(1) -b: "Count width in bytes rather than column positions" -- a line
|
|
# of six bytes is cut after the fourth byte, tab included as one byte.
|
|
printf 'a\tbcd\n' > "$t/in"
|
|
printf 'a\tbc\nd\n' > "$t/exp"
|
|
$fold -b -w 4 < "$t/in" > "$t/out"
|
|
same width-in-bytes "$t/exp"
|
|
|
|
echo "fold: $fails failed"
|
|
[ "$fails" -eq 0 ]
|