diff options
| author | Pádraig Brady <P@draigBrady.com> | 2025-01-20 15:21:58 +0000 |
|---|---|---|
| committer | Pádraig Brady <P@draigBrady.com> | 2025-01-20 15:21:58 +0000 |
| commit | dcc896e6c3d7fdcb75f493e216f94a2af558740b (patch) | |
| tree | 7ebd0dab8fd1ba9905d76aae4ca17aa5a6aece86 | |
| parent | tests: fix typo in tests/ls/ls-time.sh (diff) | |
| download | coreutils-dcc896e6c3d7fdcb75f493e216f94a2af558740b.tar.gz coreutils-dcc896e6c3d7fdcb75f493e216f94a2af558740b.zip | |
tests: remove use of unprotected 'set'
* cfg.mk (sc_prohibit_bare_set): A new syntax check to
ensure we protect use of set with '--', so that args
beginning with '-' are not interpreted as options,
and if no args are present, all existing args are cleared.
* tests/cp/symlink-slash.sh: Add -- to unprotected use of set.
* tests/ls/ls-time.sh: Likewise.
* tests/ls/symlink-slash.sh: Likewise.
* tests/mkdir/perm.sh: Likewise.
* tests/mkdir/selinux.sh: Likewise.
* tests/mkdir/smack-no-root.sh: Likewise.
* tests/mkdir/smack-root.sh: Likewise.
* tests/mv/part-hardlink.sh: Likewise.
* tests/nice/nice.sh: Likewise.
* tests/stty/stty-row-col.sh: Likewise.
| -rw-r--r-- | cfg.mk | 6 | ||||
| -rwxr-xr-x | tests/cp/symlink-slash.sh | 2 | ||||
| -rwxr-xr-x | tests/ls/ls-time.sh | 16 | ||||
| -rwxr-xr-x | tests/ls/symlink-slash.sh | 2 | ||||
| -rwxr-xr-x | tests/mkdir/perm.sh | 2 | ||||
| -rwxr-xr-x | tests/mkdir/selinux.sh | 2 | ||||
| -rwxr-xr-x | tests/mkdir/smack-no-root.sh | 2 | ||||
| -rwxr-xr-x | tests/mkdir/smack-root.sh | 2 | ||||
| -rwxr-xr-x | tests/mv/part-hardlink.sh | 4 | ||||
| -rwxr-xr-x | tests/nice/nice.sh | 2 | ||||
| -rwxr-xr-x | tests/stty/stty-row-col.sh | 2 |
11 files changed, 24 insertions, 18 deletions
@@ -498,6 +498,12 @@ sc_prohibit_NULL: halt='use nullptr instead' \ $(_sc_search_regexp) +sc_prohibit_bare_set: + @prohibit='^ *set [`$$]' \ + in_vc_files='\.sh$$' \ + halt='use set -- $$args instead of set $$args' \ + $(_sc_search_regexp) + # Don't use "indent-tabs-mode: nil" anymore. No longer needed. sc_prohibit_emacs__indent_tabs_mode__setting: @prohibit='^( *[*#] *)?indent-tabs-mode:' \ diff --git a/tests/cp/symlink-slash.sh b/tests/cp/symlink-slash.sh index f25eb7400..84891169a 100755 --- a/tests/cp/symlink-slash.sh +++ b/tests/cp/symlink-slash.sh @@ -24,7 +24,7 @@ mkdir dir || framework_failure_ ln -s dir symlink || framework_failure_ cp -dR symlink/ s || fail=1 -set $(ls -l s) +set -- $(ls -l s) # Prior to fileutils-4.0q, the following would have output ...'s -> dir' # because the trailing slash was removed unconditionally (now you have to diff --git a/tests/ls/ls-time.sh b/tests/ls/ls-time.sh index a261ae118..ef72644d3 100755 --- a/tests/ls/ls-time.sh +++ b/tests/ls/ls-time.sh @@ -38,7 +38,7 @@ touch -m -d "$t1" c || framework_failure_ # Check default name sorting works for def_sort in '' '--sort=name' '-U --sort=name' '-t --sort=name'; do - set $(ls $def_sort a B c) + set -- $(ls $def_sort a B c) test "$*" = 'B a c' || fail=1 done @@ -53,9 +53,9 @@ touch -a -d "$u1" a || framework_failure_ # A has ctime more recent than C. -set $(ls -t -c a c) +set -- $(ls -t -c a c) test "$*" = 'a c' || fail=1 -set $(ls -c a c) # Not specified by POSIX +set -- $(ls -c a c) # Not specified by POSIX test "$*" = 'a c' || fail=1 # Sleep so long in an attempt to avoid spurious failures @@ -101,20 +101,20 @@ EOF ;; esac -set $(ls -ut a B c) +set -- $(ls -ut a B c) test "$*" = 'c B a' || fail=1 -set $(ls -u a B c) # not specified by POSIX +set -- $(ls -u a B c) # not specified by POSIX test "$*" = 'c B a' || fail=1 test $fail = 1 && ls -l --full-time --time=access a B c -set $(ls -t a B c) +set -- $(ls -t a B c) test "$*" = 'a B c' || fail=1 -set $(ls --time=mtime a B c) +set -- $(ls --time=mtime a B c) test "$*" = 'a B c' || fail=1 test $fail = 1 && ls -l --full-time a B c # Now, C should have ctime more recent than A. -set $(ls -ct a c) +set -- $(ls -ct a c) if test "$*" = 'c a'; then : ok else diff --git a/tests/ls/symlink-slash.sh b/tests/ls/symlink-slash.sh index 5a168463b..88dd60133 100755 --- a/tests/ls/symlink-slash.sh +++ b/tests/ls/symlink-slash.sh @@ -22,7 +22,7 @@ print_ver_ ls mkdir dir || framework_failure_ ln -s dir symlink || framework_failure_ -set $(ls -l symlink/) +set -- $(ls -l symlink/) # Prior to fileutils-4.0k, the following would have output '... symlink -> dir'. test "$*" = 'total 0' && : || fail=1 diff --git a/tests/mkdir/perm.sh b/tests/mkdir/perm.sh index 613c5829c..cdfe29b5f 100755 --- a/tests/mkdir/perm.sh +++ b/tests/mkdir/perm.sh @@ -47,7 +47,7 @@ for p in empty -p; do old_IFS=$IFS IFS=':' - set $colon_tests + set -- $colon_tests IFS=$old_IFS while :; do diff --git a/tests/mkdir/selinux.sh b/tests/mkdir/selinux.sh index 58bf7b092..d7d63c663 100755 --- a/tests/mkdir/selinux.sh +++ b/tests/mkdir/selinux.sh @@ -33,7 +33,7 @@ for cmd_w_arg in 'mkdir dir' 'mknod b p' 'mkfifo f'; do # In OpenBSD's /bin/sh, mknod is a shell built-in. # Running via "env" ensures we run our program and not the built-in. env -- $cmd_w_arg --context=$c 2> out && fail=1 - set $cmd_w_arg; cmd=$1 + set -- $cmd_w_arg; cmd=$1 echo "$cmd: $msg" > exp || framework_failure_ # Some systems fail with ENOTSUP, EINVAL, ENOENT, or even diff --git a/tests/mkdir/smack-no-root.sh b/tests/mkdir/smack-no-root.sh index cb98e355f..f19d1a291 100755 --- a/tests/mkdir/smack-no-root.sh +++ b/tests/mkdir/smack-no-root.sh @@ -28,7 +28,7 @@ msg="failed to set default file creation context to '$c':" for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do $cmd --context="$c" 2> out && fail=1 - set $cmd + set -- $cmd echo "$1: $msg" > exp || framework_failure_ sed -e 's/ Operation not permitted$//' out > k || framework_failure_ diff --git a/tests/mkdir/smack-root.sh b/tests/mkdir/smack-root.sh index e1fe71ae9..373d5df34 100755 --- a/tests/mkdir/smack-root.sh +++ b/tests/mkdir/smack-root.sh @@ -28,7 +28,7 @@ c=arbitrary-smack-label for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do $cmd --context="$c" || { fail=1; continue; } - set $cmd + set -- $cmd ls -dZ $2 > out || fail=1 test "$(cut -f1 -d' ' out)" = "$c" || { cat out; fail=1; } done diff --git a/tests/mv/part-hardlink.sh b/tests/mv/part-hardlink.sh index 8229c27fa..738426604 100755 --- a/tests/mv/part-hardlink.sh +++ b/tests/mv/part-hardlink.sh @@ -35,9 +35,9 @@ mv f g "$other_partition_tmpdir" || fail=1 mv a b "$other_partition_tmpdir" || fail=1 cd "$other_partition_tmpdir" -set $(ls -Ci f g) +set -- $(ls -Ci f g) test $1 = $3 || fail=1 -set $(ls -Ci a/1 b/1) +set -- $(ls -Ci a/1 b/1) test $1 = $3 || fail=1 Exit $fail diff --git a/tests/nice/nice.sh b/tests/nice/nice.sh index 1b9a1bdd4..7e274ca0d 100755 --- a/tests/nice/nice.sh +++ b/tests/nice/nice.sh @@ -42,7 +42,7 @@ tests=' 19 --1:-12 12 NA LAST NA ' -set $tests +set -- $tests # Require that this test be run at 'nice' level 0. niceness=$(nice) diff --git a/tests/stty/stty-row-col.sh b/tests/stty/stty-row-col.sh index 75e98581d..ccf8e5380 100755 --- a/tests/stty/stty-row-col.sh +++ b/tests/stty/stty-row-col.sh @@ -53,7 +53,7 @@ tests=' 11 rows_036 30_80 NA LAST NA ' -set $tests +set -- $tests saved_size=$(stty size) && test -n "$saved_size" \ || skip_ "can't get window size" |
