maint: update copyright year for 2013 (in branch maint)
[platform/upstream/automake.git] / t / ax / test-lib.sh
index f711f1e..81f9170 100644 (file)
@@ -1,6 +1,6 @@
 # -*- shell-script -*-
 #
-# Copyright (C) 1996-2012 Free Software Foundation, Inc.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 ###  IMPORTANT NOTE: keep this file 'set -e' clean.  ###
 ########################################################
 
+# Do not source several times.
+test ${test_lib_sourced-no} = yes && return 0
+test_lib_sourced=yes
+
+# CDPATH is evil if used in non-interactive scripts (and even more
+# evil if exported in the environment).
+CDPATH=; unset CDPATH
+
+# Be more Bourne compatible.
+# (Snippet inspired to configure's initialization in Autoconf 2.64)
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  setopt NO_GLOB_SUBST
+  # If Zsh is not started directly in POSIX-compatibility mode, it has some
+  # incompatibilities in the handling of $0 that conflict with our usage;
+  # i.e., $0 inside a file sourced with the '.' builtin is temporarily set
+  # to the name of the sourced file.  Work around that.
+  # Note that a bug in some versions of Zsh prevents us from resetting $0
+  # in a sourced script, so the use of $argv0.  For more info see:
+  #   <http://www.zsh.org/mla/workers/2009/msg01140.html>
+  # The apparently useless 'eval' here is needed by at least dash 0.5.2,
+  # to prevent it from bailing out with an error like:
+  #   "Syntax error: Bad substitution".
+  eval 'argv0=${functrace[-1]%:*}' && test -f "$argv0" || {
+    echo "Cannot determine the path of running test script." >&2
+    echo "Your Zsh (version $ZSH_VERSION) is probably too old." >&2
+    exit 99
+  }
+else
+  argv0=$0
+  # Ignore command substitution failure, for it might cause problems
+  # with "set -e" on some shells.
+  am_shell_opts=$(set -o) || :
+  case $am_shell_opts in *posix*) set -o posix;; esac
+  unset am_shell_opts
+fi
+
 # A single whitespace character.
 sp=' '
 # A tabulation character.
@@ -31,7 +70,14 @@ nl='
 # is defined initially, so that saving and restoring $IFS works.
 IFS=$sp$tab$nl
 
-# Source extra configuration.
+# The name of the current test (without the '.sh' or '.tap' suffix).
+me=${argv0##*/} # Strip all directory components.
+case $me in     # Strip test suffix.
+   *.tap) me=${me%.tap};;
+    *.sh) me=${me%.sh} ;;
+ esac
+
+# Source extra package-specific configuration.
 . test-defs.sh
 # And fail hard if something went wrong.
 test $? -eq 0 || exit 99
@@ -81,7 +127,7 @@ framework_failure_ () { warn_ "$me: set-up failure: $@"; exit 99; }
 # For compatibility with TAP functions.
 skip_all_ () { skip_ "$@"; }
 
-if test $am_using_tap = yes; then
+if test $am_test_protocol = tap; then
   . tap-functions.sh
 fi
 
@@ -176,7 +222,7 @@ am_exit_trap ()
   exit_status=$1
   set +e
   cd "$am_top_builddir"
-  if test $am_using_tap = yes; then
+  if test $am_test_protocol = tap; then
     if test "$planned_" = later && test $exit_status -eq 0; then
       plan_ "now"
     fi