-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathprove6
executable file
·236 lines (194 loc) · 6.42 KB
/
prove6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env perl
# This is a test harness for pugs and v6-alpha
# XXX TODO: add support for the --js option
use strict;
use warnings;
use Getopt::Long;
use Test::Harness;
use File::Spec;
use Cwd;
my $top = getcwd;
while (not -f "$top/util/prove6") {
die "Not inside pugs directory\n" unless $top;
$top =~ s!(.*)/(.*)!!;
}
my ($pugs, $pir, $perl5, $help, $inc);
my $blib = 0;
my $lib = 0;
my $recurse = 0;
my @ext = ();
my @includes = ();
my @switches = ();
my $update_yml = 0;
# Allow cuddling the paths with the -I
@ARGV = map { /^(-I)(.+)/ ? ($1,$2) : $_ } @ARGV;
my $pugs_exec = ($^O =~ /(?:MSWin32|mingw|msys|cygwin)/) ? 'pugs' : './pugs';
# Stick any default switches at the beginning, so they can be overridden
# by the command line switches.
#unshift @ARGV, split( " ", $ENV{PROVE_SWITCHES} ) if defined $ENV{PROVE_SWITCHES};
Getopt::Long::Configure( "no_ignore_case" );
Getopt::Long::Configure( "bundling" );
GetOptions(
haskell => \$pugs,
pugs => \$pugs,
pir => \$pir,
parrot => \$pir,
perl5 => \$perl5,
perl => \$perl5,
'v6-alpha' => \$perl5,
help => \$help,
'I=s' => \$inc,
'b|blib' => \$blib,
'l|lib' => \$lib,
'v|verbose' => \$Test::Harness::verbose,
'r|recurse' => \$recurse,
'ext=s@' => \@ext,
'update-yml' => \$update_yml,
) or exit 1;
$ENV{TEST_VERBOSE} = 1 if $Test::Harness::verbose;
if ($help) {
print <<'_EOC_';
prove6 - Pugs Test Suit Harness
Usage:
prove6 --pugs t/some-dir/*.t
prove6 --perl5 t/*/*.t
prove6 --pir t/some-dir/some-test.t
Options:
--pugs Harness with the Haskell Pugs (default on)
--haskell ditto
--pir Harness with Pugs' PIR backend
--parrot ditto
--perl5 Harness with v6.pm (the Perl 5 implementation)
--perl ditto
--v6-alpha ditto
-I <path> Prepends <path> to PERL6LIB.
-b, --blib Adds blib/lib to the path for your tests, a la "use blib".
-l, --lib Add lib to the path for your tests.
-v, --verbose Display standard output of test scripts while running them.
-r, --recurse Recursively descend into directories.
--ext=x Extensions (defaults to .t)
--update-yml Refresh Test.pm.yml and Prelude.pm.yml
_EOC_
exit(0);
}
# Build up extensions regex
@ext = map { split /,/ } @ext;
s/^\.// foreach @ext;
@ext = ("t") unless @ext;
my $ext_regex = join( "|", map { quotemeta } @ext );
$ext_regex = qr/\.($ext_regex)$/;
my $sum = do { no warnings; $pugs + $perl5 + $pir };
if ($sum > 1) { die "error: you can't specify multiple implementations/backends.\n"; }
if ($sum == 0) { $pugs = 1 } # default to pugs
my $impl = "pugs";
# $impl = "smop" if $smop;
# etc.
my @tfiles = sort map { -d $_ ? all_in($_) : $_ } map glob, @ARGV;
@tfiles = split ' ', `$^X $top/t/spec/fudgeall $impl @tfiles`;
$ENV{PERL6LIB} ||= 'blib6/lib';
my $sep = ($^O eq 'MSWin32')? ';' : ':';
#warn $sep;
#warn $inc;
if ($inc) { $ENV{PERL6LIB} = $inc . $sep . $ENV{PERL6LIB}; }
# Handle blib includes
if ( $blib ) {
my @blibdirs = blibdirs();
if ( @blibdirs ) {
unshift @includes, @blibdirs;
} else {
warn "No blib directories found.\n";
}
}
# Handle lib includes
if ( $lib ) {
unshift @includes, "lib";
}
# refresh Test.pm.yml and Prelude.pm.yml.
if ($update_yml) {
warn "$pugs_exec -CParse-YAML ext/Test/lib/Test.pm > blib6/lib/Test.pm.yml\n";
system("$pugs_exec -CParse-YAML ext/Test/lib/Test.pm > blib6/lib/Test.pm.yml");
system("$^X $top/util/gen_prelude.pl -v -i src/perl6/Prelude.pm -p pugs " .
"--output blib6/lib/Prelude.pm.yml");
}
# Build up TH switches
push( @switches, map { /\s/ && !/^".*"$/ ? qq["-I$_"] : "-I$_" } @includes );
$Test::Harness::Switches = join( " ", @switches );
print "# \$Test::Harness::Switches: $Test::Harness::Switches\n" if $Test::Harness::debug;
if ($perl5) {
warn " info: Harness with v6.pm.\n";
#warn " warning: make sure you have run 'make install'.\n";
$ENV{PERL5LIB} = "blib6/pugs/perl5/lib${sep}blib6/pugs/perl5/arch";
} elsif ($pugs) {
warn " info: Harness with pugs (Haskell backend).\n";
# Something like this seems better, but didn't work
# use ExtUtils::MM;
# my $mm = ExtUtils::MM->new();
# $mm->maybe_command('pugs')
if (!$ENV{HARNESS_PERL} && `$pugs_exec --version` =~ m/perl/i) {
$ENV{HARNESS_PERL} = $pugs_exec;
}
elsif ($ENV{HARNESS_PERL}) {
# Nothing to do, respect the current setting
}
# Guess that it's in the local directory
elsif (-x './pugs') {
$ENV{HARNESS_PERL} = $pugs_exec;
}
else {
die "unable to find pugs binary to test with";
}
} elsif ($pir) {
warn " info: Harness with pugs (PIR packend).\n";
$ENV{PERL5LIB} = 'blib/lib${sep}blib/arch';
$ENV{HARNESS_PERL_SWITCHES} = '-B PIR';
$ENV{HARNESS_PERL} = 'blib/script/pugs';
}
runtests(@tfiles);
# Stolen directly from 'prove'
sub all_in {
my $start = shift;
my @hits = ();
local *DH;
if ( opendir( DH, $start ) ) {
my @files = sort readdir DH;
closedir DH;
for my $file ( @files ) {
next if $file eq File::Spec->updir || $file eq File::Spec->curdir;
next if $file eq ".svn";
next if $file eq "CVS";
my $currfile = File::Spec->catfile( $start, $file );
if ( -d $currfile ) {
push( @hits, all_in( $currfile ) ) if $recurse;
} else {
push( @hits, $currfile ) if $currfile =~ $ext_regex;
}
}
} else {
warn "$start: $!\n";
}
return @hits;
}
# Stolen directly from 'prove', which stole from blib.pm
sub blibdirs {
my $dir = File::Spec->curdir;
if ($^O eq 'VMS') {
($dir = VMS::Filespec::unixify($dir)) =~ s-/\z--;
}
my $archdir = "arch";
if ( $^O eq "MacOS" ) {
# Double up the MP::A so that it's not used only once.
$archdir = $MacPerl::Architecture = $MacPerl::Architecture;
}
my $i = 5;
while ($i--) {
my $blib = File::Spec->catdir( $dir, "blib" );
my $blib_lib = File::Spec->catdir( $blib, "lib" );
my $blib_arch = File::Spec->catdir( $blib, $archdir );
if ( -d $blib && -d $blib_arch && -d $blib_lib ) {
return ($blib_arch,$blib_lib);
}
$dir = File::Spec->catdir($dir, File::Spec->updir);
}
warn "$0: Cannot find blib\n";
return;
}