on master help sign in
Merge pull request #518 from tauli/master

runtest.pl revised and cleaned up

commita434e829b9f81f8b0830db3139a8e98a8baa42cf authorEdwin Brady <edwin.brady@gmail.com> dateSat 5 Oct 2013, 09:09 (13 years ago) parent2bdb46bf90e2d7
1 file changed+64−62
test/runtest.pl+64−62
test/runtest.pl+64−62
@@ -1,8 +1,10 @@
11#!/usr/bin/perl
22
3+use strict;
34use Cwd;
45
56my $exitstatus = 0;
7+my @idrOpts = ();
68
79sub runtest {
810 my ($test, $update) = @_;
@@ -10,101 +12,101 @@ sub runtest {
1012 chdir($test);
1113
1214 print "Running $test...\n";
13− $got = `sh ./run @idrOpts`;
14− $exp = `cat expected`;
15+ my $got = `sh ./run @idrOpts`;
16+ my $exp = `cat expected`;
1517
16− open(OUT,">output");
17− print OUT $got;
18− close(OUT);
18+ open my $out, '>', 'output';
19+ print $out $got;
20+ close $out;
1921
20−# $ok = system("diff output expected &> /dev/null");
21−# Mangle newlines in $got and $exp
22+ # $ok = system("diff output expected &> /dev/null");
23+ # Mangle newlines in $got and $exp
2224 $got =~ s/\r\n/\n/g;
2325 $exp =~ s/\r\n/\n/g;
2426
25−# Normalize paths in $got and $exp, so the expected outcomes don't change between platforms
26− while($got =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms)
27− {
27+ # Normalize paths in $got and $exp, so the expected outcomes don't
28+ # change between platforms
29+ while($got =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms) {
2830 $got = "$1$2/$3:$4:$5";
2931 }
30− while($exp =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms)
31− {
32+ while($exp =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms) {
3233 $exp = "$1$2/$3:$4:$5";
3334 }
3435
3536 if ($got eq $exp) {
36− print "Ran $test...success\n";
37− } else {
38− if ($update == 0) {
39− $exitstatus = 1;
40− print "Ran $test...FAILURE\n";
41− } else {
42− system("cp output expected");
43− print "Ran $test...UPDATED\n";
44− }
37+ print "Ran $test...success\n";
38+ }
39+ else {
40+ if ($update == 0) {
41+ $exitstatus = 1;
42+ print "Ran $test...FAILURE\n";
43+ } else {
44+ system("cp output expected");
45+ print "Ran $test...UPDATED\n";
46+ }
4547 }
46− chdir("..");
48+ chdir "..";
4749}
4850
51+my ( @tests, @opts );
52+
4953if ($#ARGV>=0) {
50− $test=shift(@ARGV);
54+ my $test = shift @ARGV;
5155 if ($test eq "all") {
52− opendir(DIR, ".");
53− @list = readdir(DIR);
54− foreach $file (@list) {
55− if ($file =~ /[0-9][0-9][0-9]/) {
56− push(@tests,$file);
57− }
58− }
59− @tests = sort @tests;
56+ opendir my $dir, ".";
57+ my @list = readdir $dir;
58+ foreach my $file (@list) {
59+ if ($file =~ /[0-9][0-9][0-9]/) {
60+ push @tests, $file;
61+ }
62+ }
63+ @tests = sort @tests;
6064 }
61− else
62− {
63− push(@tests, $test);
65+ else {
66+ push @tests, $test;
6467 }
6568 @opts = @ARGV;
66−} else {
69+}
70+else {
6771 print "Give a test name, or 'all' to run all.\n";
6872 exit;
6973}
7074
71−$update=0;
72−$diff=0;
73−$show=0;
74−$usejava = 0;
75−@idrOpts=();
75+my $update = 0;
76+my $diff = 0;
77+my $show = 0;
78+my $usejava = 0;
7679
77−while ($opt=shift(@opts)) {
78− if ($opt eq "-u") { $update = 1; }
80+while (my $opt = shift @opts) {
81+ if ($opt eq "-u") { $update = 1; }
7982 elsif ($opt eq "-d") { $diff = 1; }
8083 elsif ($opt eq "-s") { $show = 1; }
8184 else { push(@idrOpts, $opt); }
8285}
8386
84−my $idris = $ENV{IDRIS};
85−my $path = $ENV{PATH};
86−$ENV{PATH}=cwd() . "/" . $idris . ":" . $path;
87−
88−foreach $test (@tests) {
87+my $idris = $ENV{IDRIS};
88+my $path = $ENV{PATH};
89+$ENV{PATH} = cwd() . "/" . $idris . ":" . $path;
8990
91+foreach my $test (@tests) {
9092 if ($diff == 0 && $show == 0) {
91− runtest($test,$update);
93+ runtest($test,$update);
9294 }
9395 else {
94− chdir($test);
95−
96− if ($show == 1) {
97− system("cat output");
98− }
99− if ($diff == 1) {
100− print "Differences in $test:\n";
101− $ok = system("diff output expected");
102− if ($ok == 0) {
103− print "No differences found.\n";
104− }
105− }
106− chdir("..");
96+ chdir $test;
97+
98+ if ($show == 1) {
99+ system "cat output";
100+ }
101+ if ($diff == 1) {
102+ print "Differences in $test:\n";
103+ my $ok = system "diff output expected";
104+ if ($ok == 0) {
105+ print "No differences found.\n";
106+ }
107+ }
108+ chdir "..";
107109 }
108−
109110}
111+
110112exit $exitstatus;