From 278242e948d8815bd08de6872de8588ca18f85cf Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 15 Nov 2026 01:30:04 -0600 Subject: [PATCH] Convert more tests (and fix plumbing). --- scripts/runtest.sh | 21 +++++++-------- tests/blkid.test | 67 +++++++++++++++++++--------------------------- tests/bzcat.test | 16 +++++------ tests/cat.test | 38 +++++++++++--------------- 4 files changed, 61 insertions(+), 81 deletions(-) diff --git a/scripts/runtest.sh b/scripts/runtest.sh index e3dfd712..18eff511 100644 --- a/scripts/runtest.sh +++ b/scripts/runtest.sh @@ -45,18 +45,20 @@ fi # Helper functions # Wrapper for "testing", adds command name being tested to start of command line -testcmd() { wrong_args "$@"; testing "$1" "\"$C\" $2" "$3" "$4" "$5"; } -tst() { testing "$1" "$2" "43" '' ''; } -tsc() { testcmd "$1" "$2" "$3" '' ''; } +testcmd() { wrong_args 5 "$@"; testing "${1:-$2}" "\"$C\" $2" "$3" "$4" "$5"; } +tst() { wrong_args 3 "$@"; testing "$1" "$2" "$3" '' ''; } +tsc() { wrong_args 3 "$@"; testcmd "$1" "$2" "$3" '' ''; } skip_all() { echo "$SHOWSKIP: $CMDNAME ($1)"; touch ../continue; exit 0; } # Check if VERBOSE= contains a given string. (This allows combining.) verbose_has() { [ "${VERBOSE/$1/}" != "$VERBOSE" ]; } wrong_args() { - if [ $# -ne 5 ] + local COUNT="$1" + shift + if [ $# -ne $COUNT ] then - printf "%s\n" "Test '$1' has $# arguments" >&2 + printf "%s\n" "Test '$1' has $# arguments (not $COUNT)" >&2 for ((i=1;i<=$#;i++)); do echo "$i:'${@:$i:1}'" >&2; done exit 1 fi @@ -120,10 +122,10 @@ toyonly() # Takes five arguments: "name" "command" "result" "infile" "stdin" testing() { - wrong_args "$@" + wrong_args 5 "$@" - [ -z "$1" ] && NAME="$2" || NAME="$1" - [ "${NAME#$CMDNAME }" == "$NAME" ] && NAME="$CMDNAME $1" + [ ${#1} -eq 0 ] && NAME="$2" || NAME="$1" + [ "${NAME#$CMDNAME }" == "$NAME" ] && NAME="$CMDNAME $NAME" [ -n "$DEBUG" ] && set -x @@ -161,9 +163,6 @@ testing() return 0 } -# Wrapper for "testing", adds command name being tested to start of command line -testcmd() { wrong_args "$@"; testing "$1" "\"$C\" $2" "$3" "$4" "$5"; } - utf8locale() { local i diff --git a/tests/blkid.test b/tests/blkid.test index 420a03b2..53b7bef4 100755 --- a/tests/blkid.test +++ b/tests/blkid.test @@ -14,53 +14,42 @@ function BLKID() rm temp.img } -testing "cramfs" "BLKID cramfs" \ - 'temp.img: LABEL="mycramfs" TYPE="cramfs"\n' "" "" -testing "ext2" "BLKID ext2" \ - 'temp.img: LABEL="myext2" UUID="e59093ba-4135-4fdb-bcc4-f20beae4dfaf" TYPE="ext2"\n' \ - "" "" -testing "ext3" "BLKID ext3" \ - 'temp.img: LABEL="myext3" UUID="79d1c877-1a0f-4e7d-b21d-fc32ae3ef101" SEC_TYPE="ext2" TYPE="ext3"\n' \ - "" "" -testing "ext4" "BLKID ext4" \ - 'temp.img: LABEL="myext4" UUID="dc4b7c00-c0c0-4600-af7e-0335f09770fa" TYPE="ext4"\n' \ - "" "" -testing "f2fs" "BLKID f2fs" \ - 'temp.img: LABEL="myf2fs" UUID="b53d3619-c204-4c0b-8504-36363578491c" TYPE="f2fs"\n' \ - "" "" -testing "iso" "BLKID iso" \ - 'temp.img: LABEL="CDROM" UUID="2023-02-08-04-47-27-00" TYPE="iso9660"\n' \ - "" "" -testing "msdos" "BLKID msdos" \ - 'temp.img: SEC_TYPE="msdos" LABEL="mymsdos" UUID="6E1E-0851" TYPE="vfat"\n' \ - "" "" +tst cramfs 'BLKID cramfs' 'temp.img: LABEL="mycramfs" TYPE="cramfs"\n' +tst ext 'BLKID ext2' \ + 'temp.img: LABEL="myext2" UUID="e59093ba-4135-4fdb-bcc4-f20beae4dfaf" TYPE="ext2"\n' +tst ext3 'BLKID ext3' \ + 'temp.img: LABEL="myext3" UUID="79d1c877-1a0f-4e7d-b21d-fc32ae3ef101" SEC_TYPE="ext2" TYPE="ext3"\n' +tst ext4 "BLKID ext4" \ + 'temp.img: LABEL="myext4" UUID="dc4b7c00-c0c0-4600-af7e-0335f09770fa" TYPE="ext4"\n' +tst f2fs 'BLKID f2fs' \ + 'temp.img: LABEL="myf2fs" UUID="b53d3619-c204-4c0b-8504-36363578491c" TYPE="f2fs"\n' +tst iso 'BLKID iso' \ + 'temp.img: LABEL="CDROM" UUID="2023-02-08-04-47-27-00" TYPE="iso9660"\n' +tst msdos 'BLKID msdos' \ + 'temp.img: SEC_TYPE="msdos" LABEL="mymsdos" UUID="6E1E-0851" TYPE="vfat"\n' # We use -s here because toybox blkid can't do ntfs volume labels yet. -testing "ntfs" "BLKID ntfs -s UUID -s TYPE" \ - 'temp.img: UUID="6EE1BF3808608585" TYPE="ntfs"\n' "" "" -testing "reiserfs" "BLKID reiser3" \ - 'temp.img: LABEL="myreiser" UUID="a5b99bec-45cc-41d7-986e-32f4b6fc28f2" TYPE="reiserfs"\n' \ - "" "" -testing "squashfs" "BLKID squashfs" 'temp.img: TYPE="squashfs"\n' "" "" -testing "vfat" "BLKID vfat" \ - 'temp.img: SEC_TYPE="msdos" LABEL="myvfat" UUID="7356-B91D" TYPE="vfat"\n' \ - "" "" -testing "fat32" "BLKID fat32" \ - 'temp.img: LABEL="myfat32" UUID="2E7D-E046" TYPE="vfat"\n' \ - "" "" -testing "xfs" "BLKID xfs" \ - 'temp.img: LABEL="XFS_test" UUID="d63a1dc3-27d5-4dd4-8b38-f4f97f495c6f" TYPE="xfs"\n' \ - "" "" +tst ntfs 'BLKID ntfs -s UUID -s TYPE' \ + 'temp.img: UUID="6EE1BF3808608585" TYPE="ntfs"\n' +tst reiserfs 'BLKID reiser3' \ + 'temp.img: LABEL="myreiser" UUID="a5b99bec-45cc-41d7-986e-32f4b6fc28f2" TYPE="reiserfs"\n' +tst squashfs 'BLKID squashfs' 'temp.img: TYPE="squashfs"\n' +tst vfat 'BLKID vfat' \ + 'temp.img: SEC_TYPE="msdos" LABEL="myvfat" UUID="7356-B91D" TYPE="vfat"\n' +tst fat32 'BLKID fat32' \ + 'temp.img: LABEL="myfat32" UUID="2E7D-E046" TYPE="vfat"\n' +tst xfs 'BLKID xfs' \ + 'temp.img: LABEL="XFS_test" UUID="d63a1dc3-27d5-4dd4-8b38-f4f97f495c6f" TYPE="xfs"\n' # Unlike util-linux's blkid, toybox blkid can read from stdin. -toyonly testing "stdin" "bzcat $FILES/blkid/squashfs.bz2 | blkid -" \ - '-: TYPE="squashfs"\n' "" "" +toyonly tst stdin 'bzcat "$FILES"/blkid/squashfs.bz2 | blkid -' \ + '-: TYPE="squashfs"\n' #testing "minix" 'bzcat "$BDIR"/minix.bz2 | blkid -' #adfs bfs btrfs cramfs jfs nilfs romfs #vfat // fat32 fat12 fat16 bzcat $FILES/blkid/ext3.bz2 > temp.img -testcmd "-o value -s" "-o value -s TYPE temp.img" 'ext3\n' "" "" -testcmd "-o export" "-o export temp.img" 'DEVNAME=temp.img\nLABEL=myext3\nUUID=79d1c877-1a0f-4e7d-b21d-fc32ae3ef101\nSEC_TYPE=ext2\nTYPE=ext3\n' "" "" +tsc '-o value -s' '-o value -s TYPE temp.img' 'ext3\n' +tsc '-o export' '-o export temp.img' 'DEVNAME=temp.img\nLABEL=myext3\nUUID=79d1c877-1a0f-4e7d-b21d-fc32ae3ef101\nSEC_TYPE=ext2\nTYPE=ext3\n' rm temp.img diff --git a/tests/bzcat.test b/tests/bzcat.test index fcccf76e..2b6cdd8c 100755 --- a/tests/bzcat.test +++ b/tests/bzcat.test @@ -3,13 +3,13 @@ [ -f testing.sh ] && . testing.sh #testing "name" "command" "result" "infile" "stdin" -testcmd "2 known files" \ +tsc '2 known files' \ '"$FILES/blkid/"{minix,ntfs}.bz2 | sha1sum | sed s/\ .\*//' \ - 'c0b7469c9660d6056a988ef8a7fe73925efc9266\n' '' '' -testcmd "overflow" \ - '"$FILES/bzcat/overflow.bz2" >/dev/null 2>/dev/null || echo bad' 'bad\n' '' '' -testcmd "overflow2" \ + 'c0b7469c9660d6056a988ef8a7fe73925efc9266\n' +tsc overflow \ + '"$FILES/bzcat/overflow.bz2" >/dev/null 2>/dev/null || echo bad' 'bad\n' +tsc overflow2 \ '"$FILES/bzcat/runcnt_overflow.bz2" >/dev/null 2>/dev/null || echo bad' \ - 'bad\n' '' '' -testcmd "badcrc" \ - '"$FILES/bzcat/badcrc.bz2" > /dev/null 2>/dev/null || echo bad' 'bad\n' '' '' + 'bad\n' +tsc badcrc \ + '"$FILES/bzcat/badcrc.bz2" > /dev/null 2>/dev/null || echo bad' 'bad\n' diff --git a/tests/cat.test b/tests/cat.test index ab05840f..dd6dd728 100755 --- a/tests/cat.test +++ b/tests/cat.test @@ -4,28 +4,20 @@ #testing "name" "command" "result" "infile" "stdin" -echo "one" > file1 -echo "two" > file2 -testing "cat" "cat && echo yes" "oneyes\n" "" "one" -testing "-" "cat - && echo yes" "oneyes\n" "" "one" -testing "file1 file2" "cat file1 file2" "one\ntwo\n" "" "" -testing "- file" "cat - file1" "zero\none\n" "" "zero\n" -testing "file -" "cat file1 -" "one\nzero\n" "" "zero\n" - -testing "file1 notfound file2" \ - "cat file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \ - "one\ntwo\ncat: notfound: No such file or directory\n" "" "" - -testing "binary" \ - 'cat "$C" > file1 && cmp "$C" file1 && echo yes' "yes\n" "" "" - -testing "- file1" \ - "cat - file1 | diff -a -U 0 - file1 | tail -n 1" \ - "-hello\n" "" "hello\n" - +echo one > file1 +echo two > file2 +testcmd cat '&& echo yes' 'oneyes\n' '' one +testcmd - '- && echo yes' 'oneyes\n' '' one +tsc '' 'file1 file2' 'one\ntwo\n' +testcmd '' '- file1' 'zero\none\n' '' 'zero\n' +testcmd '' 'file1 -' 'one\nzero\n' '' 'zero\n' +tsc 'file1 notfound file2' \ + 'file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr' \ + 'one\ntwo\ncat: notfound: No such file or directory\n' +tsc binary '"$C" > file1 && cmp "$C" file1 && echo yes' 'yes\n' +testcmd '- file1' '- file1 | diff -a -U 0 - file1 | tail -n 1' \ + '-hello\n' '' 'hello\n' skipnot [ -e /dev/full ] -testing "> /dev/full" \ - "cat - > /dev/full 2>/dev/null || echo failed" \ - "failed\n" "" "zero\n" - +testcmd '> /dev/full' '- > /dev/full 2>/dev/null || echo failed' \ + 'failed\n' '' 'zero\n' rm file1 file2 -- 2.39.5