|
| 1 | +#!/usr/bin/perl -w |
| 2 | + |
| 3 | +use strict; |
| 4 | + |
| 5 | +# use of SRCDIR/SUBDIR is required for supporting VPath builds |
| 6 | +my $srcdir = $ENV{'SRCDIR'} or die 'SRCDIR environment variable is not set'; |
| 7 | +my $subdir = $ENV{'SUBDIR'} or die 'SUBDIR environment variable is not set'; |
| 8 | + |
| 9 | +my $regress_in = "$srcdir/$subdir/regress.in"; |
| 10 | +my $expected_out = "$srcdir/$subdir/expected.out"; |
| 11 | + |
| 12 | +# the output file should land in the build_dir of VPath, or just in |
| 13 | +# the current dir, if VPath isn't used |
| 14 | +my $regress_out = "regress.out"; |
| 15 | + |
| 16 | +# open input file first, so possible error isn't sent to redirected STDERR |
| 17 | +open(REGRESS_IN, "<", $regress_in) |
| 18 | + or die "can't open $regress_in for reading: $!"; |
| 19 | + |
| 20 | +# save STDOUT/ERR and redirect both to regress.out |
| 21 | +open(OLDOUT, ">&", \*STDOUT) or die "can't dup STDOUT: $!"; |
| 22 | +open(OLDERR, ">&", \*STDERR) or die "can't dup STDERR: $!"; |
| 23 | + |
| 24 | +open(STDOUT, ">", $regress_out) |
| 25 | + or die "can't open $regress_out for writing: $!"; |
| 26 | +open(STDERR, ">&", \*STDOUT) or die "can't dup STDOUT: $!"; |
| 27 | + |
| 28 | +# read lines from regress.in and run uri-regress on them |
| 29 | +while (<REGRESS_IN>) |
| 30 | + { |
| 31 | + chomp; |
| 32 | + print "trying $_\n"; |
| 33 | + system("./uri-regress \"$_\""); |
| 34 | + print "\n"; |
| 35 | +} |
| 36 | + |
| 37 | +# restore STDOUT/ERR so we can print the outcome to the user |
| 38 | +open(STDERR, ">&", \*OLDERR) or die; # can't complain as STDERR is still duped |
| 39 | +open(STDOUT, ">&", \*OLDOUT) or die "Can't restore STDOUT: $!"; |
| 40 | + |
| 41 | +# just in case |
| 42 | +close REGRESS_IN; |
| 43 | + |
| 44 | +my $diff_status = system( |
| 45 | + "diff -c \"$srcdir/$subdir/expected.out\" regress.out >regress.diff"); |
| 46 | +if ($diff_status == 0) |
| 47 | + { |
| 48 | + print "=" x 70, "\n"; |
| 49 | + print "All tests passed\n"; |
| 50 | + exit 0; |
| 51 | +} |
| 52 | +else |
| 53 | + { |
| 54 | + print "=" x 70, "\n"; |
| 55 | + print <<EOF; |
| 56 | +FAILED: the test result differs from the expected output |
| 57 | +
|
| 58 | +Review the difference in "$subdir/regress.diff" |
| 59 | +EOF |
| 60 | + print "=" x 70, "\n"; |
| 61 | + exit 1; |
| 62 | +} |
0 commit comments