X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=build%2Ftester;h=6a827b194ffcacbe08829bde52ed189636fb7050;hb=e167c2fc955423dee63194b5e4e51b10dfeb40f3;hp=ae3165a44ba8336d4db485c82e303fabffb55124;hpb=1bcd6e0bef547811d0d153ece976936dea6656c8;p=libucw.git diff --git a/build/tester b/build/tester index ae3165a4..6a827b19 100755 --- a/build/tester +++ b/build/tester @@ -1,6 +1,6 @@ #!/usr/bin/perl # A simple unit testing script -# (c) 2004--2007 Martin Mares +# (c) 2004--2013 Martin Mares # (c) 2007 Pavel Charvat # Tests in the test file have a syntax similar to mail headers, @@ -13,11 +13,20 @@ # replaced by file names of In or Out files (see below). # In: lines to pass to the program as standard input # Out: lines to expect at the program's standard output +# Err: lines to expect at the program's standard error output # In: lines to pass to the program as input file # Out: lines to expect from the program in output file # Both In and Out can be specified simultaneously if we # are testing a program which modifies some of its input files. # Exit: expected exit code of the program (default: 0) +# +# A value of a field can be optionally given as a shell-style here-document: +# +# In <) { ($tt->{$n}) && die "$n already defined"; $tt->{$n} = $v; $append_to = \($tt->{$n}); + } elsif (my ($n,$sep) = /^(\w+)\s*<<(\w+)\s*$/) { + if (!$tt) { + $tt = {}; + push @tests, $tt; + } + ($tt->{$n}) && die "$n already defined"; + $tt->{$n} = ""; + $sep .= "\n"; + while (1) { + my $line = <>; + defined $line or die "Here-document not terminated"; + last if $line eq $sep; + $tt->{$n} .= $line; + } } else { die "Test script syntax error"; } @@ -67,7 +90,6 @@ TEST: foreach $tt (@tests) { my @out_files = (); my @out_checks = (); - my @temps = (); my $redirs = ""; if (defined $tt->{'In'}) { @@ -76,7 +98,6 @@ TEST: foreach $tt (@tests) { print X $tt->{'In'}, "\n"; close X; $redirs .= " <$ifi"; - push @temps, $ifi; } else { $redirs .= " {'Out'}; } else { $redirs .= " >/dev/null"; } + if (defined $tt->{'Err'}) { + my $efi = "tmp/test$i.err"; + unlink "$rundir/$efi"; + $redirs .= " 2>$efi"; + push @out_files, $efi; + push @out_checks, $tt->{'Err'}; + } foreach my $arg (0..9) { my $f = "tmp/test$i.$arg"; if (defined $tt->{"Out$arg"}) { unlink "$rundir/$f"; - push @temps, $f; push @out_files, $f; push @out_checks, $tt->{"Out$arg"}; } @@ -102,7 +128,6 @@ TEST: foreach $tt (@tests) { open X, ">$rundir/$f" or die "Unable to create $f"; print X $tt->{"In$arg"}, "\n"; close X; - push @temps, $f; } } $run =~ s/\$(\d)/tmp\/test$i.$1/g; @@ -130,6 +155,7 @@ TEST: foreach $tt (@tests) { $out = ; } close X; + $out =~ /\n$/s or $out .= "\n"; if ($out ne $out_checks[$i] . "\n") { print "FAILED (see $ofi)\n"; $errors++; @@ -137,9 +163,7 @@ TEST: foreach $tt (@tests) { } } - foreach my $f (@temps) { - unlink "$rundir/$f"; - } + system "rm -f $rundir/tmp/test$i.*"; print "OK\n"; }