on bf4e535 help sign in
Idris-dev/test/runtest.pl
159 lines 3.8 kB history raw
1#!/usr/bin/env perl
3use strict;
4use Cwd;
5use Cwd 'abs_path';
6use Env;
8my $exitstatus = 0;
9my @idrOpts = ();
11sub sandbox_path {
12 my ($test_dir,) = @_;
13 my $sandbox = abs_path("$test_dir/../../.cabal-sandbox/bin");
15 if ( -d $sandbox ) {
16 return "PATH=\"$sandbox:$PATH\"";
17 } else {
18 return "";
19 }
22sub runtest {
23 my ($test, $update) = @_;
25 my $sandbox = sandbox_path($test);
27 chdir($test);
29 print "Running $test...\n";
30 my $got = `$sandbox ./run @idrOpts`;
31 my $exp = `cat expected`;
33 # Allow for variant expected output for tests by overriding expected
34 # when there is an expected.<os> file in the test.
35 # This should be the exception but there are sometimes valid reasons
36 # for os-dependent output.
37 # The endings are msys for windows, darwin for osx and linux for linux
38 if ( -e "expected.$^O") {
39 $exp = `cat expected.$^O`;
40 }
41 open my $out, '>', 'output';
42 print $out $got;
43 close $out;
45 # $ok = system("diff output expected &> /dev/null");
46 # Mangle newlines in $got and $exp
47 $got =~ s/\r\n/\n/g;
48 $exp =~ s/\r\n/\n/g;
50 # Normalize paths in $got and $exp, so the expected outcomes don't
51 # change between platforms
52 while($got =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms) {
53 $got = "$1$2/$3:$4:$5";
54 }
55 while($exp =~ /(^|.*?\n)(.*?)\\(.*?):(\d+):(.*)/ms) {
56 $exp = "$1$2/$3:$4:$5";
57 }
59 if ($got eq $exp) {
60 print "Ran $test...success\n";
61 }
62 else {
63 if ($update == 0) {
64 $exitstatus = 1;
65 print "Ran $test...FAILURE\n";
66 system "diff output expected";
67 } else {
68 system("cp output expected");
69 print "Ran $test...UPDATED\n";
70 }
71 }
72 chdir "..";
75my ( @without, @args, @tests, @opts );
77if ($#ARGV>=0) {
78 my $test = shift @ARGV;
79 if ($test eq "all") {
80 opendir my $dir, ".";
81 my @list = readdir $dir;
82 foreach my $file (@list) {
83 if ($file =~ /[0-9][0-9][0-9]$/) {
84 push @tests, $file;
85 }
86 }
87 @tests = sort @tests;
89 } elsif ($test eq "without") {
90 @args = @ARGV;
91 foreach my $file (@args) {
92 last if ($file =~ /--/);
93 push @without, shift @ARGV;
94 }
96 opendir my $dir, ".";
97 my @list = readdir $dir;
98 foreach my $file (@list) {
99 if ($file =~ /[0-9][0-9][0-9]$/) {
100 if (!(grep ($_ eq $file, @without))) {
101 push @tests, $file;
102 }
103 else {
104 print "Omitting $file\n";
105 }
106 }
107 }
108 @tests = sort @tests;
109 }
110 else {
111 if ($test =~ /[0-9][0-9][0-9]$/) {
112 push @tests, $test;
113 }
114 }
115 @opts = @ARGV;
117else {
118 print "Give a test name, or 'all' to run all.\n";
119 exit;
122my $update = 0;
123my $diff = 0;
124my $show = 0;
125my $usejava = 0;
127while (my $opt = shift @opts) {
128 if ($opt eq "-u") { $update = 1; }
129 elsif ($opt eq "-d") { $diff = 1; }
130 elsif ($opt eq "-s") { $show = 1; }
131 else { push(@idrOpts, $opt); }
134my $idris = $ENV{IDRIS};
135my $path = $ENV{PATH};
136$ENV{PATH} = cwd() . "/" . $idris . ":" . $path;
138foreach my $test (@tests) {
139 if ($diff == 0 && $show == 0) {
140 runtest($test,$update);
141 }
142 else {
143 chdir $test;
145 if ($show == 1) {
146 system "cat output";
147 }
148 if ($diff == 1) {
149 print "Differences in $test:\n";
150 my $ok = system "diff output expected";
151 if ($ok == 0) {
152 print "No differences found.\n";
153 }
154 }
155 chdir "..";
156 }
159exit $exitstatus;