From 39ef06544335b0178df38aa6af2c95e317c22a0c Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 21 Nov 2010 05:47:48 -0800 Subject: [PATCH] Refactor all.do and test.do in various directories. Now 'redo test' runs the tests, but 'redo t' just builds the programs. Also removed wvtest stuff; we're not really using it properly anyway and it's not helping our testing right now. It might come back later. --- runtests.do | 5 - t/all.do | 3 +- t/curse/{all.do => test.do} | 0 t/deps/.gitignore | 1 + t/deps/all.do | 1 - t/deps/clean.do | 2 +- t/deps/t2.do | 1 + t/deps/test.do | 2 + t/deps/test2.do | 8 ++ t/runtests.do | 3 - t/test.do | 4 + test.do | 5 +- wvtest.sh | 134 -------------------------- wvtestrun | 186 ------------------------------------ 14 files changed, 20 insertions(+), 335 deletions(-) delete mode 100644 runtests.do rename t/curse/{all.do => test.do} (100%) delete mode 100644 t/deps/all.do create mode 100644 t/deps/t2.do create mode 100644 t/deps/test.do create mode 100644 t/deps/test2.do delete mode 100644 t/runtests.do create mode 100644 t/test.do delete mode 100644 wvtest.sh delete mode 100755 wvtestrun diff --git a/runtests.do b/runtests.do deleted file mode 100644 index e6c5a13..0000000 --- a/runtests.do +++ /dev/null @@ -1,5 +0,0 @@ -. ./wvtest.sh - -redo t/all -WVSTART "t/runtests" -WVPASS redo t/runtests diff --git a/t/all.do b/t/all.do index 417d89f..2169f2a 100644 --- a/t/all.do +++ b/t/all.do @@ -1,2 +1 @@ -redo-ifchange hello yellow bellow c d -redo example/all curse/all deps/all +redo-ifchange hello yellow bellow c d example/ diff --git a/t/curse/all.do b/t/curse/test.do similarity index 100% rename from t/curse/all.do rename to t/curse/test.do diff --git a/t/deps/.gitignore b/t/deps/.gitignore index 1c802f3..9463dda 100644 --- a/t/deps/.gitignore +++ b/t/deps/.gitignore @@ -1 +1,2 @@ t1a +t2.count diff --git a/t/deps/all.do b/t/deps/all.do deleted file mode 100644 index 3f5418f..0000000 --- a/t/deps/all.do +++ /dev/null @@ -1 +0,0 @@ -redo test1 diff --git a/t/deps/clean.do b/t/deps/clean.do index a0946c9..7898c96 100644 --- a/t/deps/clean.do +++ b/t/deps/clean.do @@ -1 +1 @@ -rm -f *~ .*~ t1a +rm -f *~ .*~ *.count t1a diff --git a/t/deps/t2.do b/t/deps/t2.do new file mode 100644 index 0000000..8897346 --- /dev/null +++ b/t/deps/t2.do @@ -0,0 +1 @@ +echo $$ >>t2.count \ No newline at end of file diff --git a/t/deps/test.do b/t/deps/test.do new file mode 100644 index 0000000..17d436e --- /dev/null +++ b/t/deps/test.do @@ -0,0 +1,2 @@ +redo test1 test2 + diff --git a/t/deps/test2.do b/t/deps/test2.do new file mode 100644 index 0000000..0c8c7a7 --- /dev/null +++ b/t/deps/test2.do @@ -0,0 +1,8 @@ +rm -f t2.count +redo t2 +redo t2 +OUT=$(cat t2.count | wc -l) +if [ "$OUT" != 2 ]; then + echo "t2: expected 2" + exit 43 +fi diff --git a/t/runtests.do b/t/runtests.do deleted file mode 100644 index cec28ef..0000000 --- a/t/runtests.do +++ /dev/null @@ -1,3 +0,0 @@ -redo-ifchange all -./hello >&2 -redo deltest deltest2 test.args test2.args diff --git a/t/test.do b/t/test.do new file mode 100644 index 0000000..04fb6a8 --- /dev/null +++ b/t/test.do @@ -0,0 +1,4 @@ +redo-ifchange all +./hello >&2 +redo deltest deltest2 test.args test2.args curse/test deps/test + diff --git a/test.do b/test.do index e1165d7..cdb6580 100644 --- a/test.do +++ b/test.do @@ -1,3 +1,2 @@ -redo-ifchange t/c.c t/all -echo >&2 -./wvtestrun "$REDO" runtests >&2 +redo-ifchange t/c.c t/test + diff --git a/wvtest.sh b/wvtest.sh deleted file mode 100644 index 0cfc6b2..0000000 --- a/wvtest.sh +++ /dev/null @@ -1,134 +0,0 @@ -# -# Include this file in your shell script by using: -# #!/bin/sh -# . ./wvtest.sh -# - -# we don't quote $TEXT in case it contains newlines; newlines -# aren't allowed in test output. However, we set -f so that -# at least shell glob characters aren't processed. -_wvtextclean() -{ - ( set -f; echo $* ) -} - - -if [ -n "$BASH_VERSION" ]; then - _wvfind_caller() - { - LVL=$1 - WVCALLER_FILE=${BASH_SOURCE[2]} - WVCALLER_LINE=${BASH_LINENO[1]} - } -else - _wvfind_caller() - { - LVL=$1 - WVCALLER_FILE="unknown" - WVCALLER_LINE=0 - } -fi - - -_wvcheck() -{ - CODE="$1" - TEXT=$(_wvtextclean "$2") - OK=ok - if [ "$CODE" -ne 0 ]; then - OK=FAILED - fi - echo "! $WVCALLER_FILE:$WVCALLER_LINE $TEXT $OK" >&2 - if [ "$CODE" -ne 0 ]; then - exit $CODE - else - return 0 - fi -} - - -WVPASS() -{ - TEXT="$*" - - _wvfind_caller - if "$@"; then - _wvcheck 0 "$TEXT" - return 0 - else - _wvcheck 1 "$TEXT" - # NOTREACHED - return 1 - fi -} - - -WVFAIL() -{ - TEXT="$*" - - _wvfind_caller - if "$@"; then - _wvcheck 1 "NOT($TEXT)" - # NOTREACHED - return 1 - else - _wvcheck 0 "NOT($TEXT)" - return 0 - fi -} - - -_wvgetrv() -{ - ( "$@" >&2 ) - echo -n $? -} - - -WVPASSEQ() -{ - _wvfind_caller - _wvcheck $(_wvgetrv [ "$#" -eq 2 ]) "exactly 2 arguments" - echo "Comparing:" >&2 - echo "$1" >&2 - echo "--" >&2 - echo "$2" >&2 - _wvcheck $(_wvgetrv [ "$1" = "$2" ]) "'$1' = '$2'" -} - - -WVPASSNE() -{ - _wvfind_caller - _wvcheck $(_wvgetrv [ "$#" -eq 2 ]) "exactly 2 arguments" - echo "Comparing:" >&2 - echo "$1" >&2 - echo "--" >&2 - echo "$2" >&2 - _wvcheck $(_wvgetrv [ "$1" != "$2" ]) "'$1' != '$2'" -} - - -WVPASSRC() -{ - RC=$? - _wvfind_caller - _wvcheck $(_wvgetrv [ $RC -eq 0 ]) "return code($RC) == 0" -} - - -WVFAILRC() -{ - RC=$? - _wvfind_caller - _wvcheck $(_wvgetrv [ $RC -ne 0 ]) "return code($RC) != 0" -} - - -WVSTART() -{ - echo >&2 - _wvfind_caller - echo "Testing \"$*\" in $WVCALLER_FILE:" >&2 -} diff --git a/wvtestrun b/wvtestrun deleted file mode 100755 index 248a1c5..0000000 --- a/wvtestrun +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/perl -w -# -# WvTest: -# Copyright (C)2007-2009 Versabanq Innovations Inc. and contributors. -# Licensed under the GNU Library General Public License, version 2. -# See the included file named LICENSE for license information. -# -use strict; -use Time::HiRes qw(time); - -# always flush -$| = 1; - -if (@ARGV < 1) { - print STDERR "Usage: $0 \n"; - exit 127; -} - -print STDERR "Testing \"all\" in @ARGV:\n"; - -my $pid = open(my $fh, "-|"); -if (!$pid) { - # child - setpgrp(); - open STDERR, '>&STDOUT' or die("Can't dup stdout: $!\n"); - exec(@ARGV); - exit 126; # just in case -} - -my $istty = -t STDOUT; -my @log = (); -my ($gpasses, $gfails) = (0,0); - -sub bigkill($) -{ - my $pid = shift; - - if (@log) { - print "\n" . join("\n", @log) . "\n"; - } - - print STDERR "\n! Killed by signal FAILED\n"; - - ($pid > 0) || die("pid is '$pid'?!\n"); - - local $SIG{CHLD} = sub { }; # this will wake us from sleep() faster - kill 15, $pid; - sleep(2); - - if ($pid > 1) { - kill 9, -$pid; - } - kill 9, $pid; - - exit(125); -} - -# parent -local $SIG{INT} = sub { bigkill($pid); }; -local $SIG{TERM} = sub { bigkill($pid); }; -local $SIG{ALRM} = sub { - print STDERR "Alarm timed out! No test results for too long.\n"; - bigkill($pid); -}; - -sub colourize($) -{ - my $result = shift; - my $pass = ($result eq "ok"); - - if ($istty) { - my $colour = $pass ? "\e[32;1m" : "\e[31;1m"; - return "$colour$result\e[0m"; - } else { - return $result; - } -} - -sub mstime($$$) -{ - my ($floatsec, $warntime, $badtime) = @_; - my $ms = int($floatsec * 1000); - my $str = sprintf("%d.%03ds", $ms/1000, $ms % 1000); - - if ($istty && $ms > $badtime) { - return "\e[31;1m$str\e[0m"; - } elsif ($istty && $ms > $warntime) { - return "\e[33;1m$str\e[0m"; - } else { - return "$str"; - } -} - -sub resultline($$) -{ - my ($name, $result) = @_; - return sprintf("! %-65s %s", $name, colourize($result)); -} - -my $allstart = time(); -my ($start, $stop); - -sub endsect() -{ - $stop = time(); - if ($start) { - printf " %s %s\n", mstime($stop - $start, 500, 1000), colourize("ok"); - } -} - -while (<$fh>) -{ - chomp; - s/\r//g; - - if (/^\s*Testing "(.*)" in (.*):\s*$/) - { - alarm(120); - my ($sect, $file) = ($1, $2); - - endsect(); - - printf("! %s %s: ", $file, $sect); - @log = (); - $start = $stop; - } - elsif (/^!\s*(.*?)\s+(\S+)\s*$/) - { - alarm(120); - - my ($name, $result) = ($1, $2); - my $pass = ($result eq "ok"); - - if (!$start) { - printf("\n! Startup: "); - $start = time(); - } - - push @log, resultline($name, $result); - - if (!$pass) { - $gfails++; - if (@log) { - print "\n" . join("\n", @log) . "\n"; - @log = (); - } - } else { - $gpasses++; - print "."; - } - } - else - { - push @log, $_; - } -} - -endsect(); - -my $newpid = waitpid($pid, 0); -if ($newpid != $pid) { - die("waitpid returned '$newpid', expected '$pid'\n"); -} - -my $code = $?; -my $ret = ($code >> 8); - -# return death-from-signal exits as >128. This is what bash does if you ran -# the program directly. -if ($code && !$ret) { $ret = $code | 128; } - -if ($ret && @log) { - print "\n" . join("\n", @log) . "\n"; -} - -if ($code != 0) { - print resultline("Program returned non-zero exit code ($ret)", "FAILED"); -} - -my $gtotal = $gpasses+$gfails; -printf("\nWvTest: %d test%s, %d failure%s, total time %s.\n", - $gtotal, $gtotal==1 ? "" : "s", - $gfails, $gfails==1 ? "" : "s", - mstime(time() - $allstart, 2000, 5000)); -print STDERR "\nWvTest result code: $ret\n"; -exit( $ret ? $ret : ($gfails ? 125 : 0) );