+2011-08-05 Stefano Lattarini <stefano.lattarini@gmail.com>
+
+ check: small cleanups and refactorings in test harness and drivers
+ * lib/tap-driver (yn): New subroutine, converts a boolean value to
+ a "yes" or "no" string.
+ (write_test_results): Use it, and related reformatting.
+ * lib/test-driver (trap): Also remove the `.trs' file on signals,
+ for extra safety.
+ (fatal): Remove this function, it's never used.
+ ($logfile, $trsfile): Renamed ...
+ ($log_file, $trs_file): ... to these, for clarity, and in order to
+ be more consistent with the `tap-driver' script.
+ Improve a couple of comments.
+ * automake.in (handle_tests): Don't define anymore the now-obsolete
+ make macro `$(TEST_LOGS_TMP)', nor add it to the list of files to
+ be removed upon "make mostlyclean".
+ * lib/am/check.am ($(TEST_SUITE_LOG)): New shell function `f_ok',
+ tells whether a path refers to an existing, regular, readable file.
+ Use it throughout.
+ (recheck): Be safer w.r.t. make implementation that run recipes
+ with `errexit' shell flag active.
+
2011-08-05 Stefano Lattarini <stefano.lattarini@gmail.com>
testsuite: use AM_TESTS_FD_REDIRECT where appropriate
am__EXEEXT => $am_exeext);
}
}
-
- # FIXME: this is partly out-of-date w.r.t. the rest of the
- # FIXME: code now ... what is the best fix?
- define_variable ('TEST_LOGS_TMP', '$(TEST_LOGS:.log=.log-t)', INTERNAL);
- $clean_files{'$(TEST_LOGS_TMP)'} = MOSTLY_CLEAN;
-
$clean_files{'$(TEST_LOGS)'} = MOSTLY_CLEAN;
$clean_files{'$(am__TEST_BASES:=.trs)'} = MOSTLY_CLEAN;
$clean_files{'$(TEST_SUITE_LOG)'} = MOSTLY_CLEAN;
TEST_LOGS = $(am__test_logs1:.pl.log=.log)
PL_LOG_DRIVER = $(SHELL) $(top_srcdir)/lib/test-driver
PL_LOG_COMPILE = $(PL_LOG_COMPILER) $(AM_PL_LOG_FLAGS) $(PL_LOG_FLAGS)
-TEST_LOGS_TMP = $(TEST_LOGS:.log=.log-t)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
$(TEST_SUITE_LOG): $(TEST_LOGS)
@$(am__sh_e_setup); $(am__tty_colors); \
+ f_ok () { test -f "$$1" && test -r "$$1"; }; \
bases='$(am__TEST_BASES)'; \
ws='[ ]'; \
redo_bases=`for b in $$bases; do \
- test -f $$b.trs && test -r $$b.trs \
- && test -f $$b.log && test -r $$b.log \
- || echo $$b; \
+ f_ok $$b.trs && f_ok $$b.log || echo $$b; \
done`; \
if test -n "$$redo_bases"; then \
redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \
st=0; \
for b in $$redo_bases; do \
for e in trs log; do \
- if test ! -f $$b.$$e || test ! -r $$b.$$e; then \
+ f_ok $$b.$$e || { \
echo "fatal: making $@: failed to create $$b.$$e" >&2; \
st=1; \
- fi; \
+ }; \
done; \
done; \
test $$st -eq 0 || exit 1; \
target=`echo $@ | sed 's,^re,,'`; \
bases='$(am__TEST_BASES)'; \
list=`for b in $$bases; do \
- test ! -f $$b.trs && test ! -f $$b.log && continue; \
+ test -f $$b.trs || test -f $$b.log || continue; \
grep "^$$ws*:recheck:$$ws*no$$ws*$$" $$b.trs \
>/dev/null 2>&1 || echo $$b.log; \
done | tr '\012\015' ' '`; \
fi
mostlyclean-generic:
-test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS)
- -test -z "$(TEST_LOGS_TMP)" || rm -f $(TEST_LOGS_TMP)
-test -z "$(TEST_SUITE_HTML)" || rm -f $(TEST_SUITE_HTML)
-test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
-test -z "$(am__TEST_BASES:=.trs)" || rm -f $(am__TEST_BASES:=.trs)
$(TEST_SUITE_LOG): $(TEST_LOGS)
@$(am__sh_e_setup); $(am__tty_colors); \
+## Helper shell function, tells whether a path refers to an existing,
+## regular, readable file.
+ f_ok () { test -f "$$1" && test -r "$$1"; }; \
bases='$(am__TEST_BASES)'; \
ws='[ ]'; \
## We need to ensures that all the required `.trs' and `.log' files will
## the `.log' files are readable, and worse, they don't ensure that the
## `.trs' files even exist.
redo_bases=`for b in $$bases; do \
- test -f $$b.trs && test -r $$b.trs \
- && test -f $$b.log && test -r $$b.log \
- || echo $$b; \
+ f_ok $$b.trs && f_ok $$b.log || echo $$b; \
done`; \
if test -n "$$redo_bases"; then \
## Uh-oh, either some `.log' files were unreadable, or some `.trs' files
st=0; \
for b in $$redo_bases; do \
for e in trs log; do \
- if test ! -f $$b.$$e || test ! -r $$b.$$e; then \
+ f_ok $$b.$$e || { \
echo "fatal: making $@: failed to create $$b.$$e" >&2; \
st=1; \
- fi; \
+ }; \
done; \
done; \
test $$st -eq 0 || exit 1; \
list=`for b in $$bases; do \
## Skip tests that haven't been run, but recover gracefully from deleted
## `.trs' files.
- test ! -f $$b.trs && test ! -f $$b.log && continue; \
+ test -f $$b.trs || test -f $$b.log || continue; \
## FIXME: one fork per test -- this is horrendously inefficient!
grep "^$$ws*:recheck:$$ws*no$$ws*$$" $$b.trs \
>/dev/null 2>&1 || echo $$b.log; \
}
}
+# Convert a boolean to a "yes"/"no" string.
+sub yn ($)
+{
+ my $bool = shift;
+ return $bool ? "yes" : "no";
+}
+
TAP_PEEKING :
{
my @tap_lines = ();
sub write_test_results ()
{
open RES, ">", $trs_file or die "opening $trs_file: $!\n";
- print RES ":global-test-result: " .
- get_global_test_result . "\n";
- print RES ":recheck: " .
- (must_recheck ? "yes" : "no") . "\n";
- print RES ":copy-in-global-log: " .
- (copy_in_global_log ? "yes" : "no") . "\n";
+ print RES ":global-test-result: " . get_global_test_result . "\n";
+ print RES ":recheck: " . yn (must_recheck) . "\n";
+ print RES ":copy-in-global-log: " . yn (copy_in_global_log) . "\n";
foreach my $result (get_test_results)
{
print RES ":test-result: $result\n";
# helps a lot in preventing typo-related bugs.
set -u
-fatal ()
-{
- echo "$0: fatal: $*" >&2
- exit 1
-}
-
usage_error ()
{
echo "$0: $*" >&2
}
# TODO: better error handling in option parsing (in particular, ensure
-# TODO: $logfile, $trsfile and $test_name are defined).
+# TODO: $log_file, $trs_file and $test_name are defined).
test_name= # Used for reporting.
-logfile= # Where to save the output of the test script.
-trsfile= # Where to save the result(s) the test script.
+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
enable_hard_errors=yes
--help) print_usage; exit $?;;
--version) echo "test-driver $scriptversion"; exit $?;;
--test-name) test_name=$2; shift;;
- --log-file) logfile=$2; shift;;
- --trs-file) trsfile=$2; shift;;
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
--color-tests) color_tests=$2; shift;;
--expect-failure) expect_failure=$2; shift;;
--enable-hard-errors) enable_hard_errors=$2; shift;;
red= grn= lgn= blu= mgn= std=
fi
-do_exit='rm -f $logfile; (exit $st); exit $st'
+do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
trap "st=129; $do_exit" 1
trap "st=130; $do_exit" 2
trap "st=141; $do_exit" 13
trap "st=143; $do_exit" 15
# Test script is run here.
-"$@" >$logfile 2>&1
+"$@" >$log_file 2>&1
estatus=$?
if test $enable_hard_errors = no && test $estatus -eq 99; then
estatus=1
echo "${col}${res}${std}: $test_name"
# Register the test result, and other relevant metadata.
-echo ":test-result: $res" > $trsfile
-echo ":global-test-result: $res" >> $trsfile
-echo ":recheck: $recheck" >> $trsfile
-echo ":copy-in-global-log: $gcopy" >> $trsfile
+echo ":test-result: $res" > $trs_file
+echo ":global-test-result: $res" >> $trs_file
+echo ":recheck: $recheck" >> $trs_file
+echo ":copy-in-global-log: $gcopy" >> $trs_file
# Local Variables:
# mode: shell-script
TEST_LOGS = $(am__test_logs2:.tap.log=.log)
TAP_LOG_COMPILE = $(TAP_LOG_COMPILER) $(AM_TAP_LOG_FLAGS) \
$(TAP_LOG_FLAGS)
-TEST_LOGS_TMP = $(TEST_LOGS:.log=.log-t)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
$(TEST_SUITE_LOG): $(TEST_LOGS)
@$(am__sh_e_setup); $(am__tty_colors); \
+ f_ok () { test -f "$$1" && test -r "$$1"; }; \
bases='$(am__TEST_BASES)'; \
ws='[ ]'; \
redo_bases=`for b in $$bases; do \
- test -f $$b.trs && test -r $$b.trs \
- && test -f $$b.log && test -r $$b.log \
- || echo $$b; \
+ f_ok $$b.trs && f_ok $$b.log || echo $$b; \
done`; \
if test -n "$$redo_bases"; then \
redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \
st=0; \
for b in $$redo_bases; do \
for e in trs log; do \
- if test ! -f $$b.$$e || test ! -r $$b.$$e; then \
+ f_ok $$b.$$e || { \
echo "fatal: making $@: failed to create $$b.$$e" >&2; \
st=1; \
- fi; \
+ }; \
done; \
done; \
test $$st -eq 0 || exit 1; \
target=`echo $@ | sed 's,^re,,'`; \
bases='$(am__TEST_BASES)'; \
list=`for b in $$bases; do \
- test ! -f $$b.trs && test ! -f $$b.log && continue; \
+ test -f $$b.trs || test -f $$b.log || continue; \
grep "^$$ws*:recheck:$$ws*no$$ws*$$" $$b.trs \
>/dev/null 2>&1 || echo $$b.log; \
done | tr '\012\015' ' '`; \
fi
mostlyclean-generic:
-test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS)
- -test -z "$(TEST_LOGS_TMP)" || rm -f $(TEST_LOGS_TMP)
-test -z "$(TEST_SUITE_HTML)" || rm -f $(TEST_SUITE_HTML)
-test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
-test -z "$(am__TEST_BASES:=.trs)" || rm -f $(am__TEST_BASES:=.trs)