Lines Matching +full:test +full:- +full:shell
3 # Copyright (C) 2009-2016 Free Software Foundation, Inc.
18 # Using this file in a test
21 # The typical skeleton of a test looks like this:
29 # test invokes programs residing in the initial directory.
30 # For example, if the programs you want to test are in src/, and this test
31 # script is named tests/test-1, then you would use "path_prepend_ ../src",
39 # Executing a test that uses this file
42 # Running a single test:
43 # $ make check TESTS=test-foo.sh
45 # Running a single test, with verbose output:
46 # $ make check TESTS=test-foo.sh VERBOSE=yes
48 # Running a single test, with single-stepping:
49 # 1. Go into a sub-shell:
54 # 3. Execute the commands from the test, copy&pasting them one by one:
71 # export ...ENVVAR_SETTINGS...; $(SHELL) 9>&2
86 test $stderr_fileno_ = 2 \
91 fail_ () { warn_ "$ME_: failed test: $@"; Exit 1; }
92 skip_ () { warn_ "$ME_: skipped test: $@"; Exit 77; }
94 framework_failure_ () { warn_ "$ME_: set-up failure: $@"; Exit 99; }
109 test $? -eq $exp_exit && ret_=0 || ret_=1
111 if test "$VERBOSE" = yes && test "$gl_set_x_corrupts_stderr_" = false; then
112 set -x
117 # Sanitize this shell to POSIX mode, if possible.
119 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
122 alias -g '${1+"$@"}'='"$@"'
125 case `(set -o) 2>/dev/null` in
126 *posix*) set -o posix ;;
131 # We require a few additional shell features only when $EXEEXT is nonempty,
133 # - hyphen-containing alias names
134 # - we prefer to use ${var#...} substitution, rather than having
136 # The following code attempts to find a shell with support for these features.
137 # If the current shell passes the test, we're done. Otherwise, test other
138 # shells until we find one that passes. If one is found, re-exec it.
139 # If no acceptable shell is found, skip the current test.
141 # The "...set -x; P=1 true 2>err..." test is to disqualify any shell that
144 # Use "9" to indicate success (rather than 0), in case some shell acts
147 # Eval this code in a subshell to determine a shell's suitability.
148 # 10 - passes all tests; ok to use
149 # 9 - ok, but enabling "set -x" corrupts app stderr; prefer higher score
150 # ? - not ok
152 test $(echo y) = y || exit 1
155 if test "$VERBOSE" = yes; then
156 test -n "$( (exec 3>&1; set -x; P=1 true 2>&3) 2> /dev/null)" && score_=9
158 test -z "$EXEEXT" && exit $score_
159 shopt -s expand_aliases
160 alias a-b="echo zoo"
162 test ${v%x} = ab \
163 && test ${v#a} = bx \
164 && test $(a-b) = zoo \
168 if test "x$1" = "x--no-reexec"; then
171 # Assume a working shell. Export to subshells (setup_ needs this).
175 # Record the first marginally acceptable shell.
178 # Search for a shell that meets our requirements.
179 for re_shell_ in __current__ "${CONFIG_SHELL:-no_shell}" \
182 test "$re_shell_" = no_shell && continue
185 # finding even a marginal shell, skip this test.
186 if test "$re_shell_" = fail; then
187 test -z "$marginal_" && skip_ failed to find an adequate shell
192 # When testing the current shell, simply "eval" the test code.
193 # Otherwise, run it via $re_shell_ -c ...
194 if test "$re_shell_" = __current__; then
200 "$re_shell_" -c "$gl_shell_test_script_" 2>/dev/null
206 if test $st_ = 10; then
211 # If this is our first marginally acceptable shell, remember it.
212 if test "$st_:$marginal_" = 9: ; then
218 if test "$re_shell_" != __current__; then
219 # Found a usable shell. Preserve -v and -x.
220 case $- in
221 *v*x* | *x*v*) opts_=-vx ;;
222 *v*) opts_=-v ;;
223 *x*) opts_=-x ;;
228 exec "$re_shell_" $opts_ "$0" --no-reexec "$@"
235 test -n "$BASH_VERSION" && unalias -a
238 # PROG_NAME.exe), we want to support hyphen-containing names like test-acos.
239 # That is part of the shell-selection test above. Why use aliases rather
240 # than functions? Because support for hyphen-containing aliases is more
241 # widespread than that for hyphen-containing function names.
242 test -n "$EXEEXT" && shopt -s expand_aliases
244 # Enable glibc's malloc-perturbing option.
246 # malloc-related functions often return memory that is mostly zeroed.
252 # interrupt). Override it with a per-test function, e.g., to unmount
256 # Emit a header similar to that from diff -u; Print the simulated "diff"
260 printf '%s\n' "diff -u $*" \
261 "--- $1 1970-01-01" \
262 "+++ $2 1970-01-01"
273 test $# = 2 || return 2
275 if test "x$1" = x/dev/null; then
276 test -s "$2" || return 0
281 if test "x$2" = x/dev/null; then
282 test -s "$1" || return 0
283 emit_diff_u_header_ "$@"; sed 's/^/-/' "$1"
290 if diff_out_=`exec 2>/dev/null; diff -u "$0" "$0" < /dev/null` \
291 && diff -u Makefile "$0" 2>/dev/null | grep '^[+]#!' >/dev/null; then
292 # diff accepts the -u option and does not (like AIX 7 'diff') produce an
294 if test -z "$diff_out_"; then
295 compare_ () { diff -u "$@"; }
299 if diff -u "$@" > diff.out; then
302 rm -f diff.out
306 rm -f diff.out
312 for diff_opt_ in -U3 -c '' no; do
313 test "$diff_opt_" = no && break
316 test "$diff_opt_" != no
318 if test -z "$diff_out_"; then
324 # No differences were found, but AIX and HP-UX 'diff' produce output
327 rm -f diff.out
331 rm -f diff.out
336 elif cmp -s /dev/null /dev/null 2>/dev/null; then
337 compare_ () { cmp -s "$@"; }
350 # fail in a "set -e" environment.
361 # An arbitrary prefix to help distinguish test directories.
364 # Run the user-overridable cleanup_ function, remove the temporary
372 chmod -R u+rwx "$test_dir_"
374 rm -rf "$test_dir_" || { test $__st = 0 && __st=1; }
380 # a space-separated list of those names and return 0. Otherwise, don't
390 # was deleted between the above glob expansion and the existence test
392 test "x$feb_file_" = "x$feb_dir_/*.exe" && test ! -f "$feb_file_" \
395 # we can't invoke [ by PATH search anyways due to shell builtins.
396 test "x$feb_file_" = "x$feb_dir_/[.exe" && continue
398 *[!-a-zA-Z/0-9_.+]*) feb_fail_=1; break;;
406 test $feb_fail_ = 0 && printf %s "$feb_result_"
426 if test -n "$base_names_"; then
436 # specified, possibly-$initial_cwd_-relative, directory.
439 while test $# != 0; do
461 if test "$VERBOSE" = yes; then
462 # Test whether set -x may cause the selected shell to corrupt an
463 # application's stderr. Many do, including zsh-4.3.10 and the /bin/sh
468 warn_ "using SHELL=$SHELL with 'set -x' corrupts stderr"
470 set -x
477 test_dir_=`mktempd_ "$initial_cwd_" "$pfx_-$ME_.XXXX"` \
481 # As autoconf-generated configure scripts do, ensure that IFS
495 # Create a temporary directory, much like mktemp -d does.
501 # Failing that, we'll roll our own mktemp-like function:
502 # - try to get random bytes from /dev/urandom
503 # - failing that, generate output from a combination of quickly-varying
504 # sources and gzip. Ignore non-varying gzip header, and extract
506 # - given those bits, map to file-name bytes using tr, and try to create
508 # - make only $MAX_TRIES_ attempts
510 # Helper function. Print $N pseudo-random bytes from a-zA-Z0-9.
515 # Maybe try openssl rand -base64 $n_prime_|tr '+/=\012' abcd first?
520 if test -r "$dev_rand_"; then
521 # Note: 256-length($chars_) == 194; 3 copies of $chars_ is 186 + 8 = 194.
523 | LC_ALL=C tr -c $chars_ 01234567$chars_$chars_$chars_
528 cmds_='date; date +%N; free; who -a; w; ps auxww; ps ef; netstat -n'
533 len_=`echo "$data_"|wc -c`
534 test $n_plus_50_ -le $len_ && break;
540 | LC_ALL=C tr -c $chars_ 01234567$chars_$chars_$chars_
556 # it would subvert the post-mktemp "case"-based destdir test.
570 d=`unset TMPDIR; { mktemp -d -t -p "$destdir_" "$template_"; } 2>/dev/null` &&
576 test -d "$d" &&
579 perms=`ls -dgo "$d" 2>/dev/null` &&
580 case $perms in drwx--[-S]---*) :;; *) false;; esac && {
591 template_length_=`echo "$template_" | wc -c`
592 nx_=`echo "$base_template_" | wc -c`
593 nx_=`expr $template_length_ - $nx_`
600 err_=`mkdir -m 0700 "$candidate_dir_" 2>&1` \
602 test $MAX_TRIES_ -le $i_ && break;
610 test -f "$srcdir/init.cfg" \
615 # shells run the exit trap at shell function exit, rather than script exit.