]> mj.ucw.cz Git - libucw.git/commitdiff
Tester: Support here-documents
authorMartin Mares <mj@ucw.cz>
Thu, 17 Oct 2013 13:47:47 +0000 (15:47 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 17 Oct 2013 13:47:47 +0000 (15:47 +0200)
build/tester

index ea1a6a317e7631bf14b98586e1c55d62ee323a1d..0fdbeb9f9f7103b7853c1dfaae61545f0aebe789 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,
 #              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,6 +54,20 @@ 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;
+               }
        } else {
                die "Test script syntax error";
        }