Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added test validation tool, useful to check tests when equation ord…
…er changes. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9910 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
use FindBin qw($Bin); | ||
|
||
if($#ARGV < 0) { | ||
print "Usage: validatetest.pl testcase.\n"; | ||
exit 0; | ||
} | ||
|
||
my $test = $ARGV[0]; | ||
my @output; | ||
my @expected_output; | ||
|
||
# Check that the test case actually exists. | ||
unless(-e $test) { | ||
print "Test case $test does not exist!\n"; | ||
exit -1; | ||
} | ||
|
||
# Run omc on the test case and redirect the output to the @output list. | ||
open TESTRUN, "omc $test |" or die "Failed to open pipeline"; | ||
while(<TESTRUN>) { | ||
push @output, $_; | ||
} | ||
|
||
# Open the test case and read the expected output into the @expected_output list. | ||
open TESTCASE, "<", $test or die "Couldn't open $test, did it delete itself?"; | ||
# Read until we find the result section. | ||
while(<TESTCASE>) { | ||
last if /\s*\/\/\s*Result:\s*$/; | ||
} | ||
while(<TESTCASE>) { | ||
# Stop once we reach endResult. | ||
last if /\s*\/\/\s*endResult\s*$/; | ||
|
||
# Strip the // before each line and push it into @expected_output. | ||
if(/\/\/ (.*)/) { | ||
push @expected_output, "$1\n"; | ||
} | ||
} | ||
|
||
# Sort both lists. | ||
@output = sort @output; | ||
@expected_output = sort @expected_output; | ||
|
||
# Go through each line in the output. For each line, search the expected output | ||
# for an equivalent line and delete both if found. If the output matches the | ||
# expected output the result will be two empty lists, otherwise any excess or | ||
# missing output will be left in the lists. | ||
my $eoi = 0; | ||
for(my $i = 0; $i <= $#output; $i++) { | ||
for(; $eoi <= $#expected_output; $eoi++) { | ||
if ($output[$i] eq $expected_output[$eoi]) { | ||
splice @expected_output, $eoi, 1; | ||
splice @output, $i, 1; | ||
$i--; | ||
last; | ||
} | ||
elsif ($output[$i] lt $expected_output[$eoi]) { | ||
last; | ||
} | ||
} | ||
} | ||
|
||
# Print the result. | ||
if(@output or @expected_output) { | ||
if(@output) { | ||
print "Excess output [" . scalar(@output) . "]:\n"; | ||
print @output; | ||
} | ||
if(@expected_output) { | ||
print "Missing output [" . scalar(@expected_output) . "]:\n"; | ||
print @expected_output; | ||
} | ||
print "Update testcase? y/N\n"; | ||
chomp(my $input = <STDIN>); | ||
|
||
if($input eq "y") { | ||
print "Updating test case...\n"; | ||
system("$Bin/rtest -b $test"); | ||
print "Test case updated.\n"; | ||
} | ||
} else { | ||
print "Output matching, updating test case...\n"; | ||
system("$Bin/rtest -b $test"); | ||
print "Test case updated.\n"; | ||
} |