]> mj.ucw.cz Git - libucw.git/blobdiff - build/tester
xtypes: xt_double bugfix in parsing of precision
[libucw.git] / build / tester
index fd6cce3fcd620b886260d7178828793b921c1bd8..da4fab3b7587a5cbcedb8b7186fabc78929a1e09 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 # A simple unit testing script
-# (c) 2004--2007 Martin Mares <mj@ucw.cz>
+# (c) 2004--2013 Martin Mares <mj@ucw.cz>
 # (c) 2007 Pavel Charvat <pchar@ucw.cz>
 
 # Tests in the test file have a syntax similar to mail headers,
 #              replaced by file names of In<N> or Out<N> 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<N>:  lines to pass to the program as input file <N>
 #      Out<N>: lines to expect from the program in output file <N>
 #              Both In<N> and Out<N> 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 <<AMEN
+#      multiple
+#      lines
+#      of input
+#      AMEN
 
 use Getopt::Long;
 
@@ -46,11 +55,30 @@ while (<>) {
                ($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;
+               }
+               chomp $tt->{$n};
        } else {
                die "Test script syntax error";
        }
 }
 
+if (! -d "$rundir/tmp") {
+       mkdir "$rundir/tmp" or die "Unable to create $rundir/tmp: $!";
+}
+
 my $i = 0;
 my $errors = 0;
 my $prev_run = undef;
@@ -63,7 +91,6 @@ TEST: foreach $tt (@tests) {
 
        my @out_files = ();
        my @out_checks = ();
-       my @temps = ();
        my $redirs = "";
 
        if (defined $tt->{'In'}) {
@@ -72,7 +99,6 @@ TEST: foreach $tt (@tests) {
                print X $tt->{'In'}, "\n";
                close X;
                $redirs .= " <$ifi";
-               push @temps, $ifi;
        } else {
                $redirs .= " </dev/null";
        }
@@ -80,17 +106,22 @@ TEST: foreach $tt (@tests) {
                my $ofi = "tmp/test$i.out";
                unlink "$rundir/$ofi";
                $redirs .= " >$ofi";
-               push @temps, $ofi;
                push @out_files, $ofi;
                push @out_checks, $tt->{'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"};
                }
@@ -98,7 +129,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;
@@ -126,6 +156,7 @@ TEST: foreach $tt (@tests) {
                        $out = <X>;
                }
                close X;
+               $out =~ /\n$/s or $out .= "\n";
                if ($out ne $out_checks[$i] . "\n") {
                        print "FAILED (see $ofi)\n";
                        $errors++;
@@ -133,9 +164,7 @@ TEST: foreach $tt (@tests) {
                }
        }
 
-       foreach my $f (@temps) {
-               unlink "$rundir/$f";
-       }
+       system "rm -f $rundir/tmp/test$i.*";
        print "OK\n";
 }