Skip to content

Commit

Permalink
Adjust various tests to pass on TEST_HOST debian bookworm.
Browse files Browse the repository at this point in the history
  • Loading branch information
landley committed Jan 6, 2025
1 parent b099b26 commit 58500b8
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 21 deletions.
4 changes: 3 additions & 1 deletion scripts/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ skipnot()
# Skip this test (rest of command line) when not running toybox.
toyonly()
{
IS_TOYBOX="$("$C" --version 2>/dev/null)"
[ -z "$TEST_HOST" ] && IS_TOYBOX=toybox
: ${IS_TOYBOX:=$("$C" --version 2>/dev/null | grep -o toybox)} \
${IS_TOYBOX:="$(basename $(readlink -f "$C"))"}
# Ideally we'd just check for "toybox", but toybox sed lies to make autoconf
# happy, so we have at least two things to check for.
case "$IS_TOYBOX" in
Expand Down
6 changes: 3 additions & 3 deletions tests/cut.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ testcmd "-b overlaps" "-b 1-3,2-5,7-9,9-10 abc.txt" \
"one:to:th\nalphabeta\nthe qick \n" "" ""
testcmd "-b encapsulated" "-b 3-8,4-6 abc.txt" "e:two:\npha:be\ne quic\n" \
"" ""
testcmd "-bO overlaps" "-O ' ' -b 1-3,2-5,7-9,9-10 abc.txt" \
toyonly testcmd "-bO overlaps" "-O ' ' -b 1-3,2-5,7-9,9-10 abc.txt" \
"one:t o:th\nalpha beta\nthe q ick \n" "" ""
testcmd "high-low error" "-b 8-3 abc.txt 2>/dev/null || echo err" "err\n" \
"" ""
Expand All @@ -36,7 +36,7 @@ toyonly testcmd "-c japan.txt" '-c 3-6,9-12 "$FILES/utf8/japan.txt"' \
toyonly testcmd "-C test1.txt" '-C -1 "$FILES/utf8/test1.txt"' "l̴̗̞̠\n" "" ""

# substitute for awk
testcmd "-DF" "-DF 2,7,5" \
toyonly testcmd "-DF" "-DF 2,7,5" \
"said and your\nare\nis demand. supply\nforecast :\nyou you better,\n\nEm: Took hate\n" "" \
"Bother, said Pooh. It's your husband, and he has a gun.
Cheerios are donut seeds.
Expand All @@ -45,7 +45,7 @@ Weather forecast for tonight : dark.
Apple: you can buy better, but you can't pay more.
Subcalifragilisticexpialidocious.
Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy."
testcmd "-DF 2" "-DF 7,1,3-6,2-5" \
toyonly testcmd "-DF 2" "-DF 7,1,3-6,2-5" \
"seven one three four five six two three four five\n" "" \
"one two three four five six seven eight nine\n"

Expand Down
2 changes: 1 addition & 1 deletion tests/echo.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ testcmd "-e \p" "-e '\\p'" "\\p\n" "" ""
testcmd "-En" "-En 'one\ntwo'" 'one\\ntwo' "" ""
testcmd "-eE" "-eE '\e'" '\\e\n' "" ""

# This is how bash's built-in echo behaves, but now how /bin/echo behaves.
# This is how bash's built-in echo behaves, but not how /bin/echo behaves.
toyonly testcmd "" "-e 'a\x123\ufb3bbc' | od -An -tx1" \
" 61 12 33 ef ac bb 62 63 0a\n" "" ""

Expand Down
4 changes: 2 additions & 2 deletions tests/factor.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ testing "10000000019" "factor 10000000019" \
testing "3 6 from stdin" "factor" "3: 3\n6: 2 3\n" "" "3 6"
testing "stdin newline" "factor" "3: 3\n6: 2 3\n" "" "3\n6\n"

testing "-h" "factor -h $(((1<<63)-26))" \
toyonly testing "-h" "factor -h $(((1<<63)-26))" \
"9223372036854775782: 2 3^4 17 23 319279 456065899\n" "" ""
testing "-x" "factor -x $(((1<<63)-20))" \
toyonly testing "-x" "factor -x $(((1<<63)-20))" \
"7fffffffffffffec: 2 2 3 283 43f2ba978e663\n" "" ""

20 changes: 11 additions & 9 deletions tests/file.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ rm -f empty
testing "script" "file input | grep -o ' script'" " script\n" "#!/bin/bash\n" ""
testing "script with spaces" "file input | grep -o ' script'" " script\n" \
"#! /bin/bash\n" ""
testing "env script" "file input | egrep -o '(python|script)' | sort" \
testing "env script" "file input | tr P p | egrep -o '(python|script)' | sort" \
"python\nscript\n" "#! /usr/bin/env python\n" ""
testing "ascii" "file input" "input: ASCII text\n" "Hello, world!\n" ""
testing "utf-8" \
"file \"$FILES\"/utf8/japan.txt | egrep -o '(UTF-8|text)' | LANG=c sort" \
"UTF-8\ntext\n" "" ""
"file \"$FILES\"/utf8/japan.txt | egrep -o 'UTF-8 text' | LANG=c sort" \
"UTF-8 text\n" "" ""

# TODO each of these has multiple options we could test
testing "java class" \
"file \"$FILES\"/java.class | egrep -o '(Java class|version 53.0)'"\
"Java class\nversion 53.0\n" "" ""

echo "cafebabe000000020100000700000003000040000000d9300000000e0100000c8000000200014000000098500000000e" | xxd -r -p > universal
testcmd "mach-o universal" "universal" \
"universal: Mach-O universal binary with 2 architectures: [x86_64] [arm64]\n" "" ""
testcmd "mach-o universal" \
"universal | egrep -o '(Mach-O|universal|x86_64|arm64)' | sort -u" \
"Mach-O\narm64\nuniversal\nx86_64\n" "" ""
rm universal

test_line "tar file" "tar/tar.tar" "POSIX tar archive (GNU)\n" "" ""
Expand All @@ -65,13 +66,14 @@ rm -f android.dex
# These actually test a lot of the ELF code: 32-/64-bit, arm/arm64, PT_INTERP,
# the two kinds of NDK ELF note, BuildID, and stripped/not stripped.
toyonly test_line "Android NDK full ELF note" "elf/ndk-elf-note-full" \
"ELF shared object, 64-bit LSB arm64, dynamic (/system/bin/linker64), for Android 24, built by NDK r19b (5304403), BuildID=0c712b8af424d57041b85326f0000fadad38ee0a, not stripped\n" "" ""
"ELF shared object, 64-bit LSB arm64, dynamic (/system/bin/linker64), for Android 24, built by NDK r19b (5304403), BuildID=0c712b8af424d57041b85326f0000fadad38ee0a, not stripped\n" "" ""
toyonly test_line "Android NDK short ELF note" "elf/ndk-elf-note-short" \
"ELF shared object, 32-bit LSB arm, EABI5, soft float, dynamic (/system/bin/linker), for Android 28, BuildID=da6a5f4ca8da163b9339326e626d8a3c, stripped\n" "" ""
"ELF shared object, 32-bit LSB arm, EABI5, soft float, dynamic (/system/bin/linker), for Android 28, BuildID=da6a5f4ca8da163b9339326e626d8a3c, stripped\n" "" ""
toyonly test_line "ELF static fdpic" "elf/fdstatic" \
"ELF executable (fdpic), 32-bit MSB sh, static, stripped\n" "" ""
"ELF executable (fdpic), 32-bit MSB sh, static, stripped\n" "" ""
echo -ne '\x7fELF\00000000000000000000000000000000000000000000' > bad-bits
testing "ELF bad bits" "file bad-bits" "bad-bits: ELF (bad type 12336), (bad class -1) (bad endian 48) unknown arch 12336\n" "" ""
testing "ELF bad bits" "file bad-bits | egrep -o '(ELF|unknown)'" \
"ELF\nunknown\n" "" ""
rm -f bad-bits

testing "broken symlink" "file dangler" "dangler: broken symbolic link to $BROKEN\n" "" ""
Expand Down
1 change: 1 addition & 0 deletions tests/hexdump.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[ -f testing.sh ] && . testing.sh

[ -n "$TEST_HOST" ] && NOSPACE=1
testcmd "simple file" "input" "0000000 6973 706d 656c 000a\n0000007\n" "simple\\n" ""
testcmd "simple file -b" "-b input" "0000000 163 151 155 160 154 145 012\n0000007\n" "simple\\n" ""
testcmd "simple file -c" "-c input" "0000000 s i m p l e \\\\n\n0000007\n" "simple\\n" ""
Expand Down
2 changes: 1 addition & 1 deletion tests/iconv.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
echo -ne "\x24\xe2\x82\xac\xf0\x90\x90\xb7" > chars

#testing "name" "command" "result" "infile" "stdin"

utf8locale
testing "" "iconv chars | xxd -p" "24e282acf09090b7\n" "" ""
testing "-t UTF-16BE" "iconv -t UTF-16BE chars | xxd -p" "002420acd801dc37\n" "" ""
testing "-t UTF-16LE" "iconv -t UTF-16LE chars | xxd -p" "2400ac2001d837dc\n" "" ""
Expand Down
1 change: 1 addition & 0 deletions tests/sed.test
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ testcmd '\n too high' '-E "s/(.*)/\2/p" 2>/dev/null || echo OK' "OK\n" "" "foo"

toyonly testcmd 's///x' '"s/(hello )?(world)/\2/x"' "world" "" "hello world"

SKIP=1
# Performance test
X=x; Y=20; while [ $Y -gt 0 ]; do X=$X$X; Y=$(($Y-1)); done
testing 'megabyte s/x/y/g (20 sec timeout)' \
Expand Down
7 changes: 3 additions & 4 deletions tests/test.test
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@ testing "<2" 'test def \< abc || echo yes' "yes\n" "" ""
testing ">1" 'test abc \> def || echo yes' "yes\n" "" ""
testing ">2" 'test def \> abc && echo yes' "yes\n" "" ""

# toyonly doesn't work with TOYFLAG_NOHELP
# bash only has this for [[ ]] but extra tests to _exclude_ silly...
#toyonly testcmd "=~" 'abc =~ a.c && echo yes' "yes\n" "" ""
#toyonly testcmd "=~ fail" 'abc =~ d.c; echo $?' '1\n' "" ""
#toyonly testcmd "=~ zero length match" 'abc =~ "1*" && echo yes' 'yes\n' '' ''
toyonly testcmd "=~" 'abc =~ a.c && echo yes' "yes\n" "" ""
toyonly testcmd "=~ fail" 'abc =~ d.c; echo $?' '1\n' "" ""
toyonly testcmd "=~ zero length match" 'abc =~ "1*" && echo yes' 'yes\n' '' ''

# test ! = -o a
# test ! \( = -o a \)
Expand Down

0 comments on commit 58500b8

Please sign in to comment.