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>
107 lines
3.0 KiB
Bash
107 lines
3.0 KiB
Bash
#!/bin/sh
|
|
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
#
|
|
# Test of the test port. src/tests/bin/test does not exist in our tree, so
|
|
# there is nothing from atf to translate; every case below is a primary or
|
|
# an operator of test(1) (src/bin/test/test.1) with the exit status the man
|
|
# page gives it.
|
|
#
|
|
# test(1) is not the only test on the system -- every sh has it as a
|
|
# builtin -- so the port is always run as "$test ...", never as "test ...".
|
|
#
|
|
# Usage: test.sh TEST DATADIR
|
|
# TEST the command that runs the port
|
|
# DATADIR unused: test(1) has no test data (src/tests/bin/test is absent)
|
|
# Prints one line per case and exits non-zero if one failed.
|
|
|
|
[ $# -eq 2 ] || { echo "usage: $0 TEST DATADIR" >&2; exit 2; }
|
|
test=$1
|
|
fails=0
|
|
t=${TMPDIR:-/tmp}/test-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)); }
|
|
# chk NAME EXPECTED-EXIT-STS operand...
|
|
chk() {
|
|
n=$1 e=$2
|
|
shift 2
|
|
$test "$@"
|
|
s=$?
|
|
if [ "$s" -eq "$e" ]; then ok "$n"; else no "$n"; fi
|
|
}
|
|
|
|
echo content > file
|
|
: > empty
|
|
mkdir dir
|
|
printf '#!/bin/sh\n' > script
|
|
chmod +x script
|
|
touch -t 202001010000 older
|
|
touch -t 202101010000 newer
|
|
ln file hardlink
|
|
ln -s file symlink
|
|
|
|
# "If expression is not given, test also returns 1 (false)."
|
|
chk no-argument 1
|
|
|
|
# String primaries.
|
|
chk string-nonempty 0 -n abc
|
|
chk string-nonempty-empty 1 -n ""
|
|
chk string-empty 0 -z ""
|
|
chk string-empty-nonempty 1 -z abc
|
|
# "string True if string is not the null string."
|
|
chk string-alone 0 abc
|
|
chk string-alone-empty 1 ""
|
|
chk string-eq 0 ab = ab
|
|
chk string-ne 0 ab '!=' cd
|
|
chk string-ne-false 1 ab '!=' ab
|
|
# "based on the ASCII value of their characters"
|
|
chk string-lt 0 abc '<' abd
|
|
chk string-gt 1 abc '>' abd
|
|
chk string-gt-true 0 abd '>' abc
|
|
|
|
# Integer primaries, algebraic.
|
|
chk int-eq 0 5 -eq 5
|
|
chk int-eq-false 1 5 -eq 6
|
|
chk int-ne 0 5 -ne 6
|
|
chk int-gt 1 5 -gt 9
|
|
chk int-ge 0 5 -ge 5
|
|
chk int-lt 0 -3 -lt 0
|
|
chk int-le 1 6 -le 5
|
|
|
|
# File primaries.
|
|
chk file-regular 0 -f file
|
|
chk file-regular-missing 1 -f nosuch
|
|
chk file-directory 0 -d dir
|
|
chk file-directory-not 1 -d file
|
|
chk file-exists 0 -e file
|
|
chk file-size 0 -s file
|
|
chk file-size-empty 1 -s empty
|
|
chk file-exec 0 -x script
|
|
chk file-exec-not 1 -x file
|
|
chk file-readable 0 -r file
|
|
chk file-writable 0 -w file
|
|
chk file-symlink 0 -h symlink
|
|
chk file-symlink-not 1 -h file
|
|
|
|
# "True if file1 exists and is newer than file2.", older, and the same file.
|
|
chk newer-than 0 newer -nt older
|
|
chk older-than 0 older -ot newer
|
|
chk same-file 0 file -ef hardlink
|
|
|
|
# Operators: "! expression", "expression1 -a expression2", "expression1
|
|
# -o expression2", "( expression )", and "-a has higher precedence than -o".
|
|
chk not 0 '!' -f nosuch
|
|
chk not-false 1 '!' -f file
|
|
chk and 0 -f file -a -d dir
|
|
chk and-false 1 -f file -a -f nosuch
|
|
chk or 1 -f nosuch -o -f nosuch2
|
|
chk or-true 0 -f nosuch -o -f file
|
|
chk parens 0 '(' -f nosuch -o -d dir ')'
|
|
chk precedence 0 -f nosuch -o -f file -a -d dir
|
|
|
|
echo "test: $fails failed"
|
|
[ "$fails" -eq 0 ]
|