2 # Run a test script of the coreutils test scripts, picking up the right
3 # interpreter (i.e., perl or the shell) and the right flags for it (e.g.,
4 # perl `-T' flag for perl scripts that must run in tainted mode).
6 # Copyright (C) 2011 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # ---------------------------------- #
23 # Readonly variables and functions #
24 # ---------------------------------- #
26 # Help to avoid typo-related bugs.
34 # Exit with status `99' to inform the testsuite harness that an
35 # hard error occurred.
42 Usage: $me [--help] [--srcdir DIR] [--shell SHELL-CMD] [--perl PERL-CMD]
43 [--test-name NAME-WITHOUT-VPATH] TEST-SCRIPT [ARGS..]
51 assign_optarg_to_var='
52 test $# -gt 1 || fatal_ "option '\''$1'\'' requires an argument"
58 cu_SHELL=/bin/sh # Getting $SHELL from the environment is dangerous.
60 while test $# -gt 0; do
63 --help) print_help_; exit $?;;
64 --shell) var=cu_SHELL;;
66 --srcdir) var=srcdir;;
67 --test-name) var=test_name;;
69 -*) fatal_ "unknown option '$1'";;
72 test -z "$var" || eval "$assign_optarg_to_var"
76 unset assign_optarg_to_var var
79 0) fatal_ "missing argument";;
80 *) test_script=$1; shift;;
83 test -z "$test_name" && test_name=$test_script
85 # --------------------- #
86 # Run the test script #
87 # --------------------- #
89 test -f "$test_script" && test -r "$test_script" \
90 || fatal_ "test script '$test_script' does not exist, or isn't readable"
92 read shebang_line < "$test_script" \
93 || fatal_ "cannot read from the test script '$test_script'"
97 # The test is a perl script.
98 if $cu_PERL -e 'use warnings' > /dev/null 2>&1; then
99 # Perl is available, see if we must run the test with taint
101 case $shebang_line in *\ -T*) T_=T;; *) T_=;; esac
103 exec $cu_PERL -w$T_ -I"$srcdir" -MCoreutils -MCuSkip \
104 -M"CuTmpdir qw($test_name)" \
105 -- "$test_script" ${1+"$@"}
107 # Perl is not available, skip the test.
108 echo "$test_name: skip: no usable version of Perl found"
113 # Assume the test is a shell script.
114 exec $cu_SHELL "$test_script" ${1+"$@"}
121 fatal_ "dead code reached"