| 1 |
#!/usr/bin/perl |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Cwd qw(realpath); |
| 5 |
|
| 6 |
my ($bindir, $sep) = $0 =~ /^(.*)(\\|\/).*/; |
| 7 |
$bindir = realpath $bindir; |
| 8 |
chdir $bindir or die("Error: Could not change directory to $bindir !"); |
| 9 |
|
| 10 |
# Search paths for the binary |
| 11 |
my @binlist = ( |
| 12 |
"../build/src/vislcg3", |
| 13 |
"../../build/VS17/src/Debug/vislcg3", |
| 14 |
"../../build/VS17/src/Release/vislcg3", |
| 15 |
"../src/Debug/vislcg3", |
| 16 |
"../src/Release/vislcg3", |
| 17 |
"../Debug/vislcg3", |
| 18 |
"../Release/vislcg3", |
| 19 |
"../src/vislcg3", |
| 20 |
"../vislcg3", |
| 21 |
); |
| 22 |
my @unlinks = ( |
| 23 |
'diff.txt', |
| 24 |
'output.txt', |
| 25 |
'grammar.cg3b', |
| 26 |
'diff.bin.txt', |
| 27 |
'output.bin.txt', |
| 28 |
'grammar.out.cg3', |
| 29 |
'diff.out.txt', |
| 30 |
'output.out.txt', |
| 31 |
'untraced.txt', |
| 32 |
'untraced.out.txt', |
| 33 |
); |
| 34 |
my $binary = "vislcg3"; |
| 35 |
|
| 36 |
sub run_pl { |
| 37 |
my ($binary,$override,$args) = @_; |
| 38 |
my $good = 1; |
| 39 |
|
| 40 |
# Normal run |
| 41 |
`"$binary" $args $override -g grammar.cg3 -I input.txt -O output.txt >stdout.txt 2>stderr.txt`; |
| 42 |
`diff -B expected.txt output.txt >diff.txt`; |
| 43 |
|
| 44 |
if (-s "diff.txt") { |
| 45 |
print STDERR "Fail "; |
| 46 |
$good = 0; |
| 47 |
} else { |
| 48 |
print STDERR "Success "; |
| 49 |
} |
| 50 |
|
| 51 |
# Write out the parsed grammar, run from the output |
| 52 |
`cat expected.txt | $bindir/../scripts/cg-untrace > untraced.txt`; |
| 53 |
`"$binary" $args $override -g grammar.cg3 --grammar-only --grammar-out grammar.out.cg3 >stdout.out.txt 2>stderr.out.txt`; |
| 54 |
`"$binary" $args $override -g grammar.out.cg3 -I input.txt -O output.out.txt >>stdout.out.txt 2>>stderr.out.txt`; |
| 55 |
`cat output.out.txt | $bindir/../scripts/cg-untrace > untraced.out.txt`; |
| 56 |
`diff -B untraced.txt untraced.out.txt >diff.out.txt`; |
| 57 |
|
| 58 |
if (-s "diff.out.txt") { |
| 59 |
print STDERR "Fail "; |
| 60 |
$good = 0; |
| 61 |
} else { |
| 62 |
print STDERR "Success "; |
| 63 |
} |
| 64 |
|
| 65 |
# Compile the grammar, run from the compiled form |
| 66 |
`"$binary" $args $override -g grammar.cg3 --grammar-only --grammar-bin grammar.cg3b >stdout.bin.txt 2>stderr.bin.txt`; |
| 67 |
my $gf = undef; |
| 68 |
for my $g (glob('*.cg3b*')) { |
| 69 |
`"$binary" $args $override -g '$g' -I input.txt -O output.bin.txt >>stdout.bin.txt 2>>stderr.bin.txt`; |
| 70 |
`diff -B expected.txt output.bin.txt >diff.bin.txt`; |
| 71 |
if (-s "diff.bin.txt") { |
| 72 |
$gf = $g; |
| 73 |
last; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
if (-s "diff.bin.txt") { |
| 78 |
print STDERR "Fail ($gf)\n"; |
| 79 |
$good = 0; |
| 80 |
} else { |
| 81 |
print STDERR "Success\n"; |
| 82 |
} |
| 83 |
|
| 84 |
return $good; |
| 85 |
} |
| 86 |
|
| 87 |
foreach (@binlist) { |
| 88 |
if (-x $_ && int(`$_ --min-binary-revision 2>/dev/null`) >= 10373) { |
| 89 |
$binary = $_; |
| 90 |
last; |
| 91 |
} |
| 92 |
elsif (-x $_.".exe" && int(`$_.exe --min-binary-revision 2>/dev/null`) >= 10373) { |
| 93 |
$binary = $_.".exe"; |
| 94 |
last; |
| 95 |
} |
| 96 |
elsif (-x "../".$_ && int(`../$_ --min-binary-revision 2>/dev/null`) >= 10373) { |
| 97 |
$binary = "../".$_; |
| 98 |
last; |
| 99 |
} |
| 100 |
elsif (-x "../".$_.".exe" && int(`../$_.exe --min-binary-revision 2>/dev/null`) >= 10373) { |
| 101 |
$binary = "../".$_.".exe"; |
| 102 |
last; |
| 103 |
} |
| 104 |
} |
| 105 |
$binary = realpath $binary; |
| 106 |
print STDERR "Binary found at: $binary\n"; |
| 107 |
|
| 108 |
print STDERR "\nRunning tests...\n"; |
| 109 |
|
| 110 |
my $bad = 0; |
| 111 |
|
| 112 |
my $total = 0; |
| 113 |
my $failed = 0; |
| 114 |
|
| 115 |
my @tests = grep { -x } glob('./T_*'); |
| 116 |
foreach (@tests) { |
| 117 |
if ($ARGV[0] && $ARGV[0] ne "" && !(/$ARGV[0]/i)) { |
| 118 |
next; |
| 119 |
} |
| 120 |
chdir $bindir or die("Error: Could not change directory to $bindir !"); |
| 121 |
my ($test) = m/^.*?(T[^\/]+).*$/; |
| 122 |
chdir $test or die("Error: Could not change directory to $test !"); |
| 123 |
print STDERR "$test: "; |
| 124 |
for (my $i=length $test;$i<30;$i++) { |
| 125 |
print STDERR " "; |
| 126 |
} |
| 127 |
if (-s "./$test/byline.txt") { |
| 128 |
print STDERR "(".`cat "./$test/byline.txt"`.") "; |
| 129 |
} |
| 130 |
for my $u (@unlinks) { |
| 131 |
if (-e $u) { |
| 132 |
unlink $u; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
my $c = '""'; |
| 137 |
if ($ARGV[1] && $ARGV[1] ne "") { |
| 138 |
$c = '"'.$ARGV[1].'"'; |
| 139 |
} |
| 140 |
my $args = ''; |
| 141 |
if (-s 'args.txt') { |
| 142 |
$args = `cat args.txt`; |
| 143 |
} |
| 144 |
if (-x 'run.pl') { |
| 145 |
`./run.pl "$binary" \Q$c\E $args`; |
| 146 |
if ($?) { |
| 147 |
$bad = 1; |
| 148 |
$failed += 1; |
| 149 |
} |
| 150 |
} |
| 151 |
else { |
| 152 |
if (!run_pl($binary, $c, $args)) { |
| 153 |
$bad = 1; |
| 154 |
$failed += 1; |
| 155 |
} |
| 156 |
} |
| 157 |
$total += 1; |
| 158 |
} |
| 159 |
|
| 160 |
print STDERR "\n"; |
| 161 |
|
| 162 |
my $success = $total - $failed; |
| 163 |
print STDERR "$success / $total tests passing\n"; |
| 164 |
|
| 165 |
exit($bad); |