automake-patches
[Top][All Lists]
Advanced

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

[PATCH] test-driver: optionally run in test directory


From: Philipp A. Hartmann
Subject: [PATCH] test-driver: optionally run in test directory
Date: Fri, 25 Oct 2013 11:34:55 +0200

In case the actual TESTS are organised in sub-directories, some
(potentially) required files are often located in the same
directory.  Correctly loading such auxiliary data would require
explicit environment handling in the tests.

Secondly, test scripts may produce intermediate files with
non-unique names, leading to races and conflicts when running
tests in parallel in the same (top-level) tests directory.

This patch adds an option '--change-dir={yes|no}' to the
test-driver to change to the sub-directory of the given
test script (directory component taken from the script
name, if any) before running the script.

This option can then be passed via AM_LOG_DRIVER_FLAGS to
the test driver invocation.

Notes:
 * The dirname emulation is borrowed from `install-sh'.
 * It should not have any effect in case of local filenames.
 * The '$log_file' already contains the correct path and the
   output redirection is not part of the sub-shell.

Signed-off-by: Philipp A. Hartmann <address@hidden>
---
 lib/test-driver | 46 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/lib/test-driver b/lib/test-driver
index 32bf39e..2724b18 100755
--- a/lib/test-driver
+++ b/lib/test-driver
@@ -44,7 +44,8 @@ print_usage ()
 Usage:
   test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
               [--expect-failure={yes|no}] [--color-tests={yes|no}]
-              [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT
+              [--enable-hard-errors={yes|no}] [--change-dir={yes|no}]
+              [--] TEST-SCRIPT
 The '--test-name', '--log-file' and '--trs-file' options are mandatory.
 END
 }
@@ -56,6 +57,7 @@ log_file=  # Where to save the output of the test script.
 trs_file=  # Where to save the metadata of the test run.
 expect_failure=no
 color_tests=no
+change_dir=no
 enable_hard_errors=yes
 while test $# -gt 0; do
   case $1 in
@@ -64,6 +66,7 @@ while test $# -gt 0; do
   --test-name) test_name=$2; shift;;
   --log-file) log_file=$2; shift;;
   --trs-file) trs_file=$2; shift;;
+  --change-dir) change_dir=$2; shift;;
   --color-tests) color_tests=$2; shift;;
   --expect-failure) expect_failure=$2; shift;;
   --enable-hard-errors) enable_hard_errors=$2; shift;;
@@ -91,9 +94,44 @@ trap "st=130; $do_exit" 2
 trap "st=141; $do_exit" 13
 trap "st=143; $do_exit" 15
 
-# Test script is run here.
-"$@" >$log_file 2>&1
-estatus=$?
+# Optionally switch to directory of test script before running it.
+if test $change_dir = yes; then
+  tstbin=`basename "$@"`
+  # Prefer dirname, but fall back on a substitute if dirname fails.
+  tstdir=`
+       (dirname "$@") 2>/dev/null ||
+       expr X"$@" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+            X"$@" : 'X\(//\)[^/]' \| \
+            X"$@" : 'X\(//\)$' \| \
+            X"$@" : 'X\(/\)' \| . 2>/dev/null ||
+       echo X"$@" |
+           sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+                  s//\1/
+                  q
+                }
+                /^X\(\/\/\)[^/].*/{
+                  s//\1/
+                  q
+                }
+                /^X\(\/\/\)$/{
+                  s//\1/
+                  q
+                }
+                /^X\(\/\).*/{
+                  s//\1/
+                  q
+                }
+                s/.*/./; q'
+  `
+  # Test script is run here (in the directory of the script).
+  (cd "$tstdir" ; "./$tstbin") >$log_file 2>&1
+  estatus=$?
+else
+  # Test script is run here.
+  "$@" >$log_file 2>&1
+  estatus=$?
+fi
+
 if test $enable_hard_errors = no && test $estatus -eq 99; then
   estatus=1
 fi
-- 
1.8.4.rc3




reply via email to

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