logo

utils-std

Collection of commonly available Unix tools
commit: fe8dc8259541bc2815bd553b87da11c3fc729f68
parent ee95a30e5438e0aa61294e84892122a310770f43
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat, 15 Jun 2024 21:44:03 +0200

test-cmd/*.sh: Use literal newline instead of $'\n'

While dollar-single-quote is part of POSIX.1-2024/SUSv8 it is absent
from OpenBSD ksh 7.5 which is used in bootstrap-initrd.

Diffstat:

Mtest-cmd/arch.sh3++-
Mtest-cmd/basename.sh27++++++++++++++++++---------
Mtest-cmd/chmod.sh22++++++++++++++--------
Mtest-cmd/date.sh51+++++++++++++++++++++++++++++++++------------------
Mtest-cmd/dirname.sh30++++++++++++++++++++----------
Mtest-cmd/echo.sh9++++++---
Mtest-cmd/env.sh15++++++++++-----
Mtest-cmd/logname.sh3++-
Mtest-cmd/uname.sh15++++++++++-----
9 files changed, 115 insertions(+), 60 deletions(-)

diff --git a/test-cmd/arch.sh b/test-cmd/arch.sh @@ -6,4 +6,5 @@ target="$(dirname "$0")/../cmd/arch" plans=1 . "$(dirname "$0")/tap.sh" -t 'no args' '' "$(uname -m)"$'\n' +t 'no args' '' "$(uname -m) +" diff --git a/test-cmd/basename.sh b/test-cmd/basename.sh @@ -6,15 +6,24 @@ target="$(dirname "$0")/../cmd/basename" plans=9 . "$(dirname "$0")/tap.sh" -t 'no args' '' $'.\n' -t '/usr/bin' '/usr/bin' $'bin\n' -t '/usr//bin' '/usr//bin' $'bin\n' -t '-- /usr//bin' '-- /usr//bin' $'bin\n' -t 'suffix' '/usr//bin-test -test' $'bin\n' -t '-' '-' $'-\n' -t '--' '--' $'.\n' -t '---' '---' $'---\n' -t '--a a' '--a a' $'--\n' +t 'no args' '' '. +' +t '/usr/bin' '/usr/bin' 'bin +' +t '/usr//bin' '/usr//bin' 'bin +' +t '-- /usr//bin' '-- /usr//bin' 'bin +' +t 'suffix' '/usr//bin-test -test' 'bin +' +t '-' '-' '- +' +t '--' '--' '. +' +t '---' '---' '--- +' +t '--a a' '--a a' '-- +' #atf_test_case usage #usage_body() { diff --git a/test-cmd/chmod.sh b/test-cmd/chmod.sh @@ -10,14 +10,20 @@ tmpfile="${TMPDIR-/tmp}/test_chmod_$(date +%s)" touch "$tmpfile" || exit 1 -t '0' "-v 0 $tmpfile" "chmod: Permissions changed from 00644/-rw-r--r-- to 00000/---------- for '${tmpfile}'"$'\n' -t '00' "-v 00 $tmpfile" "chmod: Permissions already set to 00000/---------- for '${tmpfile}'"$'\n' -t '000' "-v 000 $tmpfile" "chmod: Permissions already set to 00000/---------- for '${tmpfile}'"$'\n' -t '0000' "-v 0000 $tmpfile" "chmod: Permissions already set to 00000/---------- for '${tmpfile}'"$'\n' - -t '0444' "-v 0444 $tmpfile" "chmod: Permissions changed from 00000/---------- to 00444/-r--r--r-- for '${tmpfile}'"$'\n' - -t '0777' "-v 0777 $tmpfile" "chmod: Permissions changed from 00444/-r--r--r-- to 00777/-rwxrwxrwx for '${tmpfile}'"$'\n' +t '0' "-v 0 $tmpfile" "chmod: Permissions changed from 00644/-rw-r--r-- to 00000/---------- for '${tmpfile}' +" +t '00' "-v 00 $tmpfile" "chmod: Permissions already set to 00000/---------- for '${tmpfile}' +" +t '000' "-v 000 $tmpfile" "chmod: Permissions already set to 00000/---------- for '${tmpfile}' +" +t '0000' "-v 0000 $tmpfile" "chmod: Permissions already set to 00000/---------- for '${tmpfile}' +" + +t '0444' "-v 0444 $tmpfile" "chmod: Permissions changed from 00000/---------- to 00444/-r--r--r-- for '${tmpfile}' +" + +t '0777' "-v 0777 $tmpfile" "chmod: Permissions changed from 00444/-r--r--r-- to 00777/-rwxrwxrwx for '${tmpfile}' +" # atf_check -s not-exit:0 -e "inline:chmod: Failed parsing mode '0888': contains digit outside of [0-7]\n" ../cmd/chmod -v 0888 "${TMPDIR}/chmod_octal" diff --git a/test-cmd/date.sh b/test-cmd/date.sh @@ -8,24 +8,39 @@ plans=15 unset TZ -t 'noargs' '' "$(date +%c)"$'\n' -t 'epoch' '-u -d @1155544496 +%s' '1155544496'$'\n' -t 'rfc3339' '-u -d @1155544496 +%FT%T%z' '2006-08-14T08:34:56+0000'$'\n' -t 'rfc5322' '-u -d @1155544496 -R' 'Mon, 14 Aug 2006 08:34:56 +0000'$'\n' -t 'empty' '+' ''$'\n' -t 'echolike' '+hello_world' 'hello_world'$'\n' - -t '@0' '-u -d @0 +%FT%T' '1970-01-01T00:00:00'$'\n' -t '@69' '-u -d @69 +%FT%T' '1970-01-01T00:01:09'$'\n' -t '@-69' '-u -d @-69 +%FT%T' '1969-12-31T23:58:51'$'\n' - -t '1970-01-01T00:00:00Z' '-u -d 1970-01-01T00:00:00Z +%s' '0'$'\n' -t '1970-01-01T00:01:09Z' '-u -d 1970-01-01T00:01:09Z +%s' '69'$'\n' -t '1969-12-31T23:58:51Z' '-u -d 1969-12-31T23:58:51Z +%s' '-69'$'\n' -t '1969-12-31T23:58:51.00Z' '-u -d 1969-12-31T23:58:51.00Z +%s' '-69'$'\n' -t '1969-12-31T23:58:51,00Z' '-u -d 1969-12-31T23:58:51,00Z +%s' '-69'$'\n' - -t 'f_option' '-u -f %Y-%m-%dT%H:%M:%S 2006-08-14T08:34:56 +%s' '1155544496'$'\n' +t 'noargs' '' "$(date +%c) +" +t 'epoch' '-u -d @1155544496 +%s' '1155544496 +' +t 'rfc3339' '-u -d @1155544496 +%FT%T%z' '2006-08-14T08:34:56+0000 +' +t 'rfc5322' '-u -d @1155544496 -R' 'Mon, 14 Aug 2006 08:34:56 +0000 +' +t 'empty' '+' ' +' +t 'echolike' '+hello_world' 'hello_world +' + +t '@0' '-u -d @0 +%FT%T' '1970-01-01T00:00:00 +' +t '@69' '-u -d @69 +%FT%T' '1970-01-01T00:01:09 +' +t '@-69' '-u -d @-69 +%FT%T' '1969-12-31T23:58:51 +' + +t '1970-01-01T00:00:00Z' '-u -d 1970-01-01T00:00:00Z +%s' '0 +' +t '1970-01-01T00:01:09Z' '-u -d 1970-01-01T00:01:09Z +%s' '69 +' +t '1969-12-31T23:58:51Z' '-u -d 1969-12-31T23:58:51Z +%s' '-69 +' +t '1969-12-31T23:58:51.00Z' '-u -d 1969-12-31T23:58:51.00Z +%s' '-69 +' +t '1969-12-31T23:58:51,00Z' '-u -d 1969-12-31T23:58:51,00Z +%s' '-69 +' + +t 'f_option' '-u -f %Y-%m-%dT%H:%M:%S 2006-08-14T08:34:56 +%s' '1155544496 +' #usage="\ #date [-uR] [-d datetime] [+format] diff --git a/test-cmd/dirname.sh b/test-cmd/dirname.sh @@ -8,15 +8,25 @@ plans=10 # atf_check -e "inline:usage: dirname string\n" -s exit:1 ../cmd/dirname -t '/usr/bin' '/usr/bin' $'/usr\n' -t '/usr//bin' '/usr//bin' $'/usr\n' -t '-- /usr//bin' '/usr//bin' $'/usr\n' -t '.' '.' $'.\n' -t '-' '-' $'.\n' -t '/' '/' $'/\n' -t '///' '///' $'/\n' -t '---' '---' $'.\n' -t '--foo' '--foo' $'.\n' -t './foobar' './foobar' $'.\n' +t '/usr/bin' '/usr/bin' '/usr +' +t '/usr//bin' '/usr//bin' '/usr +' +t '-- /usr//bin' '/usr//bin' '/usr +' +t '.' '.' '. +' +t '-' '-' '. +' +t '/' '/' '/ +' +t '///' '///' '/ +' +t '---' '---' '. +' +t '--foo' '--foo' '. +' +t './foobar' './foobar' '. +' # atf_check -s exit:1 -e "inline:usage: dirname string\n" ../cmd/dirname -a "/usr//bin" diff --git a/test-cmd/echo.sh b/test-cmd/echo.sh @@ -6,9 +6,12 @@ target="$(dirname "$0")/../cmd/echo" plans=7 . "$(dirname "$0")/tap.sh" -t 'empty' '' $'\n' -t 'hello' 'hello' $'hello\n' -t '-- hello' '-- hello' $'-- hello\n' +t 'empty' '' ' +' +t 'hello' 'hello' 'hello +' +t '-- hello' '-- hello' '-- hello +' t '-n' '-n' '' t '-n foo' '-n foo' 'foo' diff --git a/test-cmd/env.sh b/test-cmd/env.sh @@ -15,12 +15,17 @@ target="$(dirname "$0")/../cmd/env" plans=6 . "$(dirname "$0")/tap.sh" -t reset '-i FOO=BAR' $'FOO=BAR\n' -t reset_chain "-i FOO=BAR $target" $'FOO=BAR\n' -t uflag "-i FOOZ=BARZ $target -u FOOZ FOO=BAR" $'FOO=BAR\n' -t unsetflag "-i FOOZ=BARZ $target --unset=FOOZ FOO=BAR" $'FOO=BAR\n' +t reset '-i FOO=BAR' 'FOO=BAR +' +t reset_chain "-i FOO=BAR $target" 'FOO=BAR +' +t uflag "-i FOOZ=BARZ $target -u FOOZ FOO=BAR" 'FOO=BAR +' +t unsetflag "-i FOOZ=BARZ $target --unset=FOOZ FOO=BAR" 'FOO=BAR +' t exec_true 'true' '' -t exec_echo 'echo' $'\n' +t exec_echo 'echo' ' +' # atf_check -s not-exit:0 -e "inline:env: Error: Unrecognised option: '-f'\nenv [-i] [-u key | --unset=key] [key=value ...] [command [args]]\n" ../cmd/env -f # atf_check -s exit:127 -e 'inline:env: execvp("/var/empty/e/no/ent", ...): No such file or directory\n' ../cmd/env /var/empty/e/no/ent diff --git a/test-cmd/logname.sh b/test-cmd/logname.sh @@ -9,5 +9,6 @@ plans=1 if ! test -n "${LOGNAME}"; then skip basic '$LOGNAME not set (wtf)' else - t basic '' "${LOGNAME}"$'\n' + t basic '' "${LOGNAME} +" fi diff --git a/test-cmd/uname.sh b/test-cmd/uname.sh @@ -13,8 +13,13 @@ plans=5 . "$(dirname "$0")/tap.sh" -t 'no args' '' "$(uname -s)"$'\n' -t '-s' '-s' "$(uname -s)"$'\n' -t '-a' '-a' "$(uname -s) $(uname -n) $(uname -r) $(uname -v) $(uname -m)"$'\n' -t '-n' '-n' "$(hostname)"$'\n' -if has_cmd arch; then t '-m' '-m' "$(arch)"$'\n'; else skip '-m' "no arch command"; fi +t 'no args' '' "$(uname -s) +" +t '-s' '-s' "$(uname -s) +" +t '-a' '-a' "$(uname -s) $(uname -n) $(uname -r) $(uname -v) $(uname -m) +" +t '-n' '-n' "$(hostname) +" +if has_cmd arch; then t '-m' '-m' "$(arch) +"; else skip '-m' "no arch command"; fi