Instead of adding the line "set --", how about changing "set $(ls $def_sort a B
c)" to "set — $(ls $def_sort a B c)" ?
________________________________
From: coreutils-bounces+williambader=hotmail.com@gnu.org
<coreutils-bounces+williambader=hotmail.com@gnu.org> on behalf of Philip
Rowlands <coreutils@dimebar.com>
Sent: Sunday, January 19, 2025 5:56 PM
To: Pádraig Brady <P@draigbrady.com>; Daniel Hofstetter <dhofstet@gmail.com>;
Leslie S Satenstein via GNU coreutils General Discussion <coreutils@gnu.org>
Subject: Re: [PATCH] tests: fix typo in ls-time.sh
Is this a bug in the test script? I'm mildly surprised that asking for
ls --sort-option-that-doesnt-exist
counts as a pass in this loop.
# Check default name sorting works
for def_sort in '' '--sort=name' '-U --sort=name' '--sort-name -t'; do
set $(ls $def_sort a B c)
test "$*" = 'B a c' || fail=1
done
The problem running under /bin/sh (whether or not it's bash) without the
errexit/nounset options is that we need to check carefully whether a command
worked, or failed with no output:
+ for def_sort in '' '--sort=name' '-U --sort=name' '--sort-name -t'
++ ls --sort-name -t a B c
ls: unrecognized option '--sort-name'
Try 'ls --help' for more information.
+ set
AWK=gawk
BASH=/bin/sh
# etc.
Here we see that `set` called argv-less is, as requested, printing the shell
variables and functions.
The patch below suffices to reset the positional parameters at the end of each
loop, preventing the previous run's output from erroneously passing into the
next loop.
Cheers,
Phil
diff --git a/tests/ls/ls-time.sh b/tests/ls/ls-time.sh
index a261ae118..d385c1c6d 100755
--- a/tests/ls/ls-time.sh
+++ b/tests/ls/ls-time.sh
@@ -40,6 +40,7 @@ touch -m -d "$t1" c || framework_failure_
for def_sort in '' '--sort=name' '-U --sort=name' '-t --sort=name'; do
set $(ls $def_sort a B c)
test "$*" = 'B a c' || fail=1
+ set --
done
touch -a -d "$u3" c || framework_failure_