bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tests: use "Exit $fail", not (exit $fail); exit $fail


From: Jim Meyering
Subject: [PATCH] tests: use "Exit $fail", not (exit $fail); exit $fail
Date: Wed, 10 Sep 2008 13:17:09 +0200

This is a big clean-up-only change, but almost completely mechanical.
I've omitted the repetitive parts.
Thanks again for the new Exit function definition, Ralf.

>From bb32a495794efea452b3cae8f333304e2ceda4c1 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 7 Sep 2008 10:31:27 +0200
Subject: [PATCH] tests: use "Exit $fail", not (exit $fail); exit $fail

* tests/test-lib.sh (Exit): New function by Ralf Wildenhues in automake
http://git.sv.gnu.org/gitweb/?p=automake.git;a=commitdiff;h=20594c08f63
* tests/**: Convert all uses:

This restrictive change converted the vast majority:

  git grep -l '^(exit \$fail); exit \$fail$' \
    | xargs perl -pi -e 's/'^\(exit \$fail\); exit \$fail$/Exit \$fail/'

And this did the rest, plus a few undesirable ones, so I manually
backed out the changes to ChangeLog-* and build-aux/check.mk:

  git grep -l -E '\(exit [^)]+\); exit ' \
    | xargs perl -pi -e 's/\(exit (.+?)\); exit \1/Exit $1/'
---
 maint.mk                              |    6 +++---
 tests/chgrp/basic                     |    2 +-
 tests/chgrp/default-no-deref          |    2 +-
 tests/chgrp/deref                     |    2 +-
 tests/chgrp/no-x                      |    2 +-
 tests/chgrp/posix-H                   |    2 +-
 tests/chgrp/recurse                   |    2 +-
 tests/chmod/c-option                  |    2 +-
 tests/chmod/equal-x                   |    2 +-
 tests/chmod/equals                    |    2 +-
 tests/chmod/inaccessible              |    2 +-
 tests/chmod/no-x                      |    2 +-
 tests/chmod/octal                     |    2 +-
 tests/chmod/setgid                    |    2 +-
 tests/chmod/thru-dangling             |    2 +-
 tests/chmod/umask-x                   |    2 +-
 tests/chmod/usage                     |    2 +-
 tests/chown/basic                     |    2 +-
 tests/chown/deref                     |    2 +-
 tests/chown/preserve-root             |    2 +-
 tests/chown/separator                 |    2 +-
 tests/cp/abuse                        |    2 +-
 tests/cp/acl                          |    2 +-
 tests/cp/backup-1                     |    2 +-
 tests/cp/backup-dir                   |    2 +-
 tests/cp/backup-is-src                |    2 +-
 tests/cp/cp-HL                        |    2 +-
 tests/cp/cp-a-selinux                 |    2 +-
 tests/cp/cp-deref                     |    2 +-
 tests/cp/cp-i                         |    2 +-
 tests/cp/cp-mv-backup                 |    2 +-
 tests/cp/cp-parents                   |    2 +-
 tests/cp/deref-slink                  |    2 +-
 tests/cp/dir-rm-dest                  |    2 +-
 tests/cp/dir-slash                    |    2 +-
 tests/cp/dir-vs-file                  |    2 +-
 tests/cp/existing-perm-race           |    2 +-
 tests/cp/fail-perm                    |    2 +-
 tests/cp/file-perm-race               |    2 +-
 tests/cp/into-self                    |    2 +-
 tests/cp/link                         |    2 +-
 tests/cp/link-no-deref                |    2 +-
 tests/cp/link-preserve                |    2 +-
 tests/cp/no-deref-link1               |    2 +-
 tests/cp/no-deref-link2               |    2 +-
 tests/cp/no-deref-link3               |    2 +-
 tests/cp/parent-perm                  |    2 +-
 tests/cp/parent-perm-race             |    2 +-
 tests/cp/perm                         |    2 +-
 tests/cp/preserve-2                   |    2 +-
 tests/cp/preserve-gid                 |    4 ++--
 tests/cp/proc-zero-len                |    2 +-
 tests/cp/r-vs-symlink                 |    2 +-
 tests/cp/same-file                    |    2 +-
 tests/cp/slink-2-slink                |    2 +-
 tests/cp/sparse                       |    2 +-
 tests/cp/special-bits                 |    2 +-
 tests/cp/special-f                    |    2 +-
 tests/cp/src-base-dot                 |    2 +-
 tests/cp/symlink-slash                |    2 +-
 tests/cp/thru-dangling                |    2 +-
 tests/dd/misc                         |    2 +-
 tests/dd/not-rewound                  |    2 +-
 tests/dd/skip-seek2                   |    2 +-
 tests/dd/unblock-sync                 |    2 +-
 tests/df/total                        |    2 +-
 tests/df/total-awk                    |    2 +-
 tests/du/2g                           |    2 +-
 tests/du/8gb                          |    2 +-
 tests/du/basic                        |    2 +-
 tests/du/deref                        |    2 +-
 tests/du/deref-args                   |    2 +-
 tests/du/exclude                      |    2 +-
 tests/du/fd-leak                      |    2 +-
 tests/du/hard-link                    |    2 +-
 tests/du/inacc-dest                   |    2 +-
 tests/du/inacc-dir                    |    2 +-
 tests/du/inaccessible-cwd             |    2 +-
 tests/du/long-from-unreadable         |    2 +-
 tests/du/long-sloop                   |    2 +-
 tests/du/no-deref                     |    2 +-
 tests/du/no-x                         |    2 +-
 tests/du/one-file-system              |    2 +-
 tests/du/restore-wd                   |    2 +-
 tests/du/slash                        |    2 +-
 tests/du/slink                        |    2 +-
 tests/du/trailing-slash               |    2 +-
 tests/du/two-args                     |    2 +-
 tests/install/basic-1                 |    2 +-
 tests/install/create-leading          |    2 +-
 tests/install/d-slashdot              |    2 +-
 tests/install/strip-program           |    2 +-
 tests/install/trap                    |    2 +-
 tests/ln/backup-1                     |    2 +-
 tests/ln/hard-backup                  |    2 +-
 tests/ln/misc                         |    2 +-
 tests/ln/sf-1                         |    2 +-
 tests/ln/target-1                     |    2 +-
 tests/ls/capability                   |    2 +-
 tests/ls/color-dtype-dir              |    2 +-
 tests/ls/dangle                       |    2 +-
 tests/ls/dired                        |    2 +-
 tests/ls/file-type                    |    2 +-
 tests/ls/follow-slink                 |    2 +-
 tests/ls/infloop                      |    2 +-
 tests/ls/inode                        |    2 +-
 tests/ls/m-option                     |    2 +-
 tests/ls/nameless-uid                 |    2 +-
 tests/ls/no-arg                       |    2 +-
 tests/ls/proc-selinux-segfault        |    2 +-
 tests/ls/recursive                    |    2 +-
 tests/ls/rt-1                         |    2 +-
 tests/ls/stat-dtype                   |    2 +-
 tests/ls/stat-failed                  |    2 +-
 tests/ls/stat-free-symlinks           |    2 +-
 tests/ls/stat-vs-dirent               |    2 +-
 tests/ls/symlink-slash                |    2 +-
 tests/ls/x-option                     |    2 +-
 tests/misc/arch                       |    2 +-
 tests/misc/cat-proc                   |    2 +-
 tests/misc/chcon                      |    2 +-
 tests/misc/chcon-fail                 |    2 +-
 tests/misc/close-stdout               |    2 +-
 tests/misc/csplit                     |    2 +-
 tests/misc/date-sec                   |    2 +-
 tests/misc/df                         |    2 +-
 tests/misc/df-P                       |    2 +-
 tests/misc/false-status               |    2 +-
 tests/misc/fmt-long-line              |    2 +-
 tests/misc/groups-dash                |    2 +-
 tests/misc/groups-version             |    2 +-
 tests/misc/head-c                     |    2 +-
 tests/misc/head-pos                   |    2 +-
 tests/misc/help-version               |    4 ++--
 tests/misc/id-context                 |    2 +-
 tests/misc/ls-time                    |    4 ++--
 tests/misc/mknod                      |    2 +-
 tests/misc/nice                       |    2 +-
 tests/misc/nl                         |    2 +-
 tests/misc/nohup                      |    2 +-
 tests/misc/od-N                       |    2 +-
 tests/misc/od-multiple-t              |    2 +-
 tests/misc/od-x8                      |    2 +-
 tests/misc/pathchk1                   |    2 +-
 tests/misc/printf                     |    2 +-
 tests/misc/printf-hex                 |    2 +-
 tests/misc/printf-surprise            |    2 +-
 tests/misc/ptx-overrun                |    2 +-
 tests/misc/pwd-long                   |    2 +-
 tests/misc/pwd-unreadable-parent      |    2 +-
 tests/misc/readlink-fp-loop           |    2 +-
 tests/misc/runcon-no-reorder          |    2 +-
 tests/misc/selinux                    |    2 +-
 tests/misc/shred-exact                |    2 +-
 tests/misc/shred-remove               |    2 +-
 tests/misc/shuf                       |    2 +-
 tests/misc/sort-compress              |    2 +-
 tests/misc/sort-rand                  |    2 +-
 tests/misc/sort-version               |    2 +-
 tests/misc/split-a                    |    2 +-
 tests/misc/split-fail                 |    2 +-
 tests/misc/split-l                    |    2 +-
 tests/misc/stat-fmt                   |    2 +-
 tests/misc/stty                       |    2 +-
 tests/misc/stty-invalid               |    2 +-
 tests/misc/stty-row-col               |    2 +-
 tests/misc/sum-sysv                   |    2 +-
 tests/misc/tac-continue               |    8 ++++----
 tests/misc/tee                        |    2 +-
 tests/misc/tee-dash                   |    2 +-
 tests/misc/timeout                    |    2 +-
 tests/misc/timeout-parameters         |    2 +-
 tests/misc/truncate-dangling-symlink  |    2 +-
 tests/misc/truncate-dir-fail          |    2 +-
 tests/misc/truncate-fail-diag         |    2 +-
 tests/misc/truncate-fifo              |    2 +-
 tests/misc/truncate-no-create-missing |    2 +-
 tests/misc/truncate-overflow          |    2 +-
 tests/misc/truncate-owned-by-other    |    2 +-
 tests/misc/truncate-parameters        |    2 +-
 tests/misc/truncate-relative          |    2 +-
 tests/misc/wc-files0                  |    2 +-
 tests/mkdir/p-1                       |    2 +-
 tests/mkdir/p-2                       |    2 +-
 tests/mkdir/p-3                       |    2 +-
 tests/mkdir/p-slashdot                |    2 +-
 tests/mkdir/p-thru-slink              |    2 +-
 tests/mkdir/p-v                       |    2 +-
 tests/mkdir/parents                   |    2 +-
 tests/mkdir/perm                      |    2 +-
 tests/mkdir/selinux                   |    2 +-
 tests/mkdir/special-1                 |    2 +-
 tests/mkdir/t-slash                   |    2 +-
 tests/mkdir/writable-under-readonly   |    2 +-
 tests/mv/acl                          |    2 +-
 tests/mv/atomic                       |    2 +-
 tests/mv/atomic2                      |    2 +-
 tests/mv/backup-dir                   |    2 +-
 tests/mv/backup-is-src                |    2 +-
 tests/mv/childproof                   |    2 +-
 tests/mv/diag                         |    2 +-
 tests/mv/dir-file                     |    2 +-
 tests/mv/dir2dir                      |    2 +-
 tests/mv/dup-source                   |    2 +-
 tests/mv/force                        |    2 +-
 tests/mv/hard-2                       |    2 +-
 tests/mv/hard-3                       |    2 +-
 tests/mv/hard-4                       |    2 +-
 tests/mv/hard-link-1                  |    2 +-
 tests/mv/hard-verbose                 |    2 +-
 tests/mv/i-2                          |    2 +-
 tests/mv/i-3                          |    2 +-
 tests/mv/i-4                          |    2 +-
 tests/mv/i-5                          |    2 +-
 tests/mv/i-link-no                    |    2 +-
 tests/mv/into-self                    |    2 +-
 tests/mv/into-self-2                  |    2 +-
 tests/mv/into-self-3                  |    2 +-
 tests/mv/into-self-4                  |    2 +-
 tests/mv/leak-fd                      |    2 +-
 tests/mv/mv-special-1                 |    2 +-
 tests/mv/no-target-dir                |    2 +-
 tests/mv/part-fail                    |    2 +-
 tests/mv/part-hardlink                |    2 +-
 tests/mv/part-rename                  |    2 +-
 tests/mv/part-symlink                 |    2 +-
 tests/mv/partition-perm               |    2 +-
 tests/mv/perm-1                       |    2 +-
 tests/mv/reply-no                     |    2 +-
 tests/mv/sticky-to-xpart              |    2 +-
 tests/mv/to-symlink                   |    2 +-
 tests/mv/trailing-slash               |    2 +-
 tests/mv/update                       |    2 +-
 tests/readlink/can-e                  |    2 +-
 tests/readlink/can-f                  |    2 +-
 tests/readlink/can-m                  |    2 +-
 tests/readlink/rl-1                   |    2 +-
 tests/require-perl                    |    2 +-
 tests/rm/cycle                        |    2 +-
 tests/rm/dangling-symlink             |    2 +-
 tests/rm/deep-1                       |    2 +-
 tests/rm/deep-2                       |    2 +-
 tests/rm/dir-no-w                     |    2 +-
 tests/rm/dir-nonrecur                 |    2 +-
 tests/rm/dot-rel                      |    2 +-
 tests/rm/empty-inacc                  |    2 +-
 tests/rm/f-1                          |    2 +-
 tests/rm/fail-2eperm                  |    2 +-
 tests/rm/fail-eacces                  |    2 +-
 tests/rm/hash                         |    2 +-
 tests/rm/i-1                          |    2 +-
 tests/rm/i-never                      |    2 +-
 tests/rm/i-no-r                       |    2 +-
 tests/rm/ignorable                    |    2 +-
 tests/rm/inaccessible                 |    2 +-
 tests/rm/interactive-always           |    2 +-
 tests/rm/interactive-once             |    2 +-
 tests/rm/ir-1                         |    2 +-
 tests/rm/isatty                       |    2 +-
 tests/rm/no-give-up                   |    2 +-
 tests/rm/one-file-system              |    2 +-
 tests/rm/r-1                          |    2 +-
 tests/rm/r-2                          |    2 +-
 tests/rm/r-3                          |    2 +-
 tests/rm/r-4                          |    2 +-
 tests/rm/readdir-bug                  |    2 +-
 tests/rm/rm1                          |    2 +-
 tests/rm/rm2                          |    2 +-
 tests/rm/rm3                          |    2 +-
 tests/rm/rm4                          |    2 +-
 tests/rm/rm5                          |    2 +-
 tests/rm/sunos-1                      |    2 +-
 tests/rm/unread2                      |    2 +-
 tests/rm/unread3                      |    2 +-
 tests/rm/v-slash                      |    2 +-
 tests/rmdir/fail-perm                 |    2 +-
 tests/rmdir/ignore                    |    2 +-
 tests/rmdir/t-slash                   |    2 +-
 tests/sample-test                     |    2 +-
 tests/tail-2/append-only              |    2 +-
 tests/tail-2/assert                   |    2 +-
 tests/tail-2/assert-2                 |    2 +-
 tests/tail-2/big-4gb                  |    2 +-
 tests/tail-2/infloop-1                |    2 +-
 tests/tail-2/proc-ksyms               |    2 +-
 tests/tail-2/start-middle             |    2 +-
 tests/tail-2/tail-n0f                 |    2 +-
 tests/test-lib.sh                     |   20 ++++++++++++++++----
 tests/touch/dangling-symlink          |    2 +-
 tests/touch/dir-1                     |    2 +-
 tests/touch/empty-file                |    2 +-
 tests/touch/fail-diag                 |    2 +-
 tests/touch/fifo                      |    2 +-
 tests/touch/no-create-missing         |    2 +-
 tests/touch/no-rights                 |    2 +-
 tests/touch/not-owner                 |    2 +-
 tests/touch/now-owned-by-other        |    2 +-
 tests/touch/obsolescent               |    2 +-
 tests/touch/read-only                 |    2 +-
 tests/touch/relative                  |    2 +-
 300 files changed, 323 insertions(+), 311 deletions(-)

diff --git a/maint.mk b/maint.mk
index eb241b6..492fb0f 100644
--- a/maint.mk
+++ b/maint.mk
@@ -377,18 +377,18 @@ sc_program_name:
        fi

 # Require that the final line of each test-lib.sh-using test be this one:
-# (exit $fail); exit $fail
+# Exit $fail
 # Note: this test requires GNU grep's --label= option.
 sc_require_test_exit_idiom:
        @if test -f $(srcdir)/tests/test-lib.sh; then                   \
          die=0;                                                        \
          for i in $$(grep -l -F /../test-lib.sh $$($(VC_LIST) tests)); do \
-           tail -n1 $$i | grep '^(exit \$$fail); exit \$$fail$$' > /dev/null \
+           tail -n1 $$i | grep '^Exit \$$fail$$' > /dev/null \
              && : || { die=1; echo $$i; }                              \
          done;                                                         \
          test $$die = 1 &&                                             \
            { echo 1>&2 '$(ME): the final line in each of the above is not:'; \
-             echo 1>&2 '(exit $$fail); exit $$fail';                   \
+             echo 1>&2 'Exit $$fail';                  \
              exit 1; } || :;                                           \
        fi

diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index f0e1070..e7ec80e 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -5,13 +5,13 @@ unset function_test
 eval 'function_test() { return 11; }; function_test'
 if test $? != 11; then
   echo "$0: /bin/sh lacks support for functions; skipping this test." 1>&2
-  (exit 77); exit 77
+  Exit 77
 fi

 skip_test_()
 {
   echo "$0: skipping test: $@" 1>&2
-  (exit 77); exit 77
+  Exit 77
 }

 require_acl_()
@@ -184,7 +184,7 @@ require_root_()
 }

 skip_if_root_() { uid_is_privileged_ && skip_test_ "must be run as non-root"; }
-error_() { echo "$0: $@" 1>&2; (exit 1); exit 1; }
+error_() { echo "$0: $@" 1>&2; Exit 1; }
 framework_failure() { error_ 'failure in testing framework'; }

 # Set `groups' to a space-separated list of at least two groups
@@ -271,6 +271,18 @@ working_umask_or_skip_()
   esac
 }

+# We use a trap below for cleanup.  This requires us to go through
+# hoops to get the right exit status transported through the signal.
+# So use `Exit STATUS' instead of `exit STATUS' inside of the tests.
+# Turn off errexit here so that we don't trip the bug with OSF1/Tru64
+# sh inside this function.
+Exit ()
+{
+  set +e
+  (exit $1)
+  exit $1
+}
+
 test_dir_=$(pwd)

 this_test_() { echo "./$0" | sed 's,.*/,,'; }
@@ -294,7 +306,7 @@ remove_tmp_()
 # Run each test from within a temporary sub-directory named after the
 # test itself, and arrange to remove it upon exception or normal exit.
 trap remove_tmp_ 0
-trap '(exit $?); exit $?' 1 2 13 15
+trap 'Exit $?' 1 2 13 15

 cd "$t_" || error_ "failed to cd to $t_"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]