on master help sign in
Merge pull request #518 from tauli/master
a434e82Edwin Brady
test/runtest.pl+64−62
@@ -1,8 +1,10 @@
1#!/usr/bin/perl
1#!/usr/bin/perl
2
2
3+use strict;
3use Cwd;
4use Cwd;
4
5
5my $exitstatus = 0;
6my $exitstatus = 0;
7+my @idrOpts = ();
6
8
7sub runtest {
9sub runtest {
8 my ($test, $update) = @_;
10 my ($test, $update) = @_;
@@ -10,101 +12,101 @@ sub runtest {
10 chdir($test);
12 chdir($test);
11
13
12 print "Running $test...\n";
14 print "Running $test...\n";
13− $got = `sh ./run @idrOpts`;
15+ my $got = `sh ./run @idrOpts`;
14− $exp = `cat expected`;
16+ my $exp = `cat expected`;
15
17
16− open(OUT,">output");
18+ open my $out, '>', 'output';
17− print OUT $got;
19+ print $out $got;
18− close(OUT);
20+ close $out;
19
21
20−# $ok = system("diff output expected &> /dev/null");
22+ # $ok = system("diff output expected &> /dev/null");
21−# Mangle newlines in $got and $exp
23+ # Mangle newlines in $got and $exp
22 $got =~ s/\r\n/\n/g;
24 $got =~ s/\r\n/\n/g;
23 $exp =~ s/\r\n/\n/g;
25 $exp =~ s/\r\n/\n/g;
24
26
25−# Normalize paths in $got and $exp, so the expected outcomes don't change between platforms
27+ # Normalize paths in $got and $exp, so the expected outcomes don't
28+ # change between platforms
26− while($got =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms)
29+ while($got =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms) {
27− {
28 $got = "$1$2/$3:$4:$5";
30 $got = "$1$2/$3:$4:$5";
29 }
31 }
30− while($exp =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms)
32+ while($exp =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms) {
31− {
32 $exp = "$1$2/$3:$4:$5";
33 $exp = "$1$2/$3:$4:$5";
33 }
34 }
34
35
35 if ($got eq $exp) {
36 if ($got eq $exp) {
36− print "Ran $test...success\n";
37+ print "Ran $test...success\n";
38+ }
37− } else {
39+ else {
38− if ($update == 0) {
40+ if ($update == 0) {
39− $exitstatus = 1;
41+ $exitstatus = 1;
40− print "Ran $test...FAILURE\n";
42+ print "Ran $test...FAILURE\n";
41− } else {
43+ } else {
42− system("cp output expected");
44+ system("cp output expected");
43− print "Ran $test...UPDATED\n";
45+ print "Ran $test...UPDATED\n";
44− }
46+ }
45 }
47 }
46− chdir("..");
48+ chdir "..";
47}
49}
48
50
51+my ( @tests, @opts );
52+
49if ($#ARGV>=0) {
53if ($#ARGV>=0) {
50− $test=shift(@ARGV);
54+ my $test = shift @ARGV;
51 if ($test eq "all") {
55 if ($test eq "all") {
52− opendir(DIR, ".");
56+ opendir my $dir, ".";
53− @list = readdir(DIR);
57+ my @list = readdir $dir;
54− foreach $file (@list) {
58+ foreach my $file (@list) {
55− if ($file =~ /[0-9][0-9][0-9]/) {
59+ if ($file =~ /[0-9][0-9][0-9]/) {
56− push(@tests,$file);
60+ push @tests, $file;
57− }
61+ }
58− }
62+ }
59− @tests = sort @tests;
63+ @tests = sort @tests;
60 }
64 }
61− else
65+ else {
62− {
63− push(@tests, $test);
66+ push @tests, $test;
64 }
67 }
65 @opts = @ARGV;
68 @opts = @ARGV;
69+}
66−} else {
70+else {
67 print "Give a test name, or 'all' to run all.\n";
71 print "Give a test name, or 'all' to run all.\n";
68 exit;
72 exit;
69}
73}
70
74
71−$update=0;
75+my $update = 0;
72−$diff=0;
76+my $diff = 0;
73−$show=0;
77+my $show = 0;
74−$usejava = 0;
78+my $usejava = 0;
75−@idrOpts=();
76
79
77−while ($opt=shift(@opts)) {
80+while (my $opt = shift @opts) {
78− if ($opt eq "-u") { $update = 1; }
81+ if ($opt eq "-u") { $update = 1; }
79 elsif ($opt eq "-d") { $diff = 1; }
82 elsif ($opt eq "-d") { $diff = 1; }
80 elsif ($opt eq "-s") { $show = 1; }
83 elsif ($opt eq "-s") { $show = 1; }
81 else { push(@idrOpts, $opt); }
84 else { push(@idrOpts, $opt); }
82}
85}
83
86
84−my $idris = $ENV{IDRIS};
87+my $idris = $ENV{IDRIS};
85−my $path = $ENV{PATH};
88+my $path = $ENV{PATH};
86−$ENV{PATH}=cwd() . "/" . $idris . ":" . $path;
89+$ENV{PATH} = cwd() . "/" . $idris . ":" . $path;
87−
88−foreach $test (@tests) {
89
90
91+foreach my $test (@tests) {
90 if ($diff == 0 && $show == 0) {
92 if ($diff == 0 && $show == 0) {
91− runtest($test,$update);
93+ runtest($test,$update);
92 }
94 }
93 else {
95 else {
94− chdir($test);
96+ chdir $test;
95−
97+
96− if ($show == 1) {
98+ if ($show == 1) {
97− system("cat output");
99+ system "cat output";
98− }
100+ }
99− if ($diff == 1) {
101+ if ($diff == 1) {
100− print "Differences in $test:\n";
102+ print "Differences in $test:\n";
101− $ok = system("diff output expected");
103+ my $ok = system "diff output expected";
102− if ($ok == 0) {
104+ if ($ok == 0) {
103− print "No differences found.\n";
105+ print "No differences found.\n";
104− }
106+ }
105− }
107+ }
106− chdir("..");
108+ chdir "..";
107 }
109 }
108−
109}
110}
111+
110exit $exitstatus;
112exit $exitstatus;