comparison t/harness6 @ 0:c341f82e7ad7 default tip

Rakudo branch in cr.ie.u-ryukyu.ac.jp
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 26 Dec 2019 16:50:27 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c341f82e7ad7
1 #!/usr/bin/env perl6
2
3 # note: Due to a limitation in argument parsing options that should be passed
4 # through to fudgeall have to come after all other options
5
6 # We keep TAP module in a non-core repo, so here we either clone
7 # it or just pull in any changes into the directory with the module
8 # that we then load:
9
10 use lib <t/packages/tap-harness6/lib>;
11 constant $tap-dir = 't/packages/tap-harness6'.IO;
12 constant $tap-repo = 'https://github.com/perl6/tap-harness6';
13 if $tap-dir.d {
14 say 'Updating TAP::Harness checkout...';
15 run :cwd($tap-dir), <git pull>;
16 }
17 else {
18 say 'TAP::Harness checkout not found; going to clone...';
19 run <git clone>, $tap-repo, $tap-dir.absolute;
20 }
21 require ::('TAP');
22
23 constant FULL_ROAST_TEST_LIST_FILE = 't/spectest.data';
24 constant ROAST_VERSION_FILE = 't/spec/VERSION';
25
26 my $vm = $*VM.name;
27
28 sub MAIN(
29 Str :$tests-from-file is copy = Str,
30 Bool :$fudge = False,
31 Int :$verbosity = (%*ENV<TEST_VERBOSE> // 0).Int,
32 Int :$jobs = (%*ENV<TEST_JOBS> // 1).Int,
33 Bool :$quick = False,
34 Bool :$stress = False,
35 Bool :$randomize = False,
36 Bool :$no-mix-slow = $*DISTRO.is-win || $jobs == 1,
37 Str :$perlpath = ~$*EXECUTABLE,
38 Str :$perl5path = 'perl',
39 *@files,
40 ) {
41 my @slow;
42 with $tests-from-file {
43 $tests-from-file .= &convert-to-versioned-file;
44 my $inline-perl5-is-installed = run(
45 $perlpath, '-e', 'exit 1 if (try require Inline::Perl5) === Nil'
46 ).exitcode == 0;
47
48 unless $inline-perl5-is-installed {
49 say 'Inline::Perl5 not installed: not running Perl 5 integration tests';
50 say 'You can install Inline::Perl5 into the build directory with';
51 say '';
52 say " zef --install-to=inst#{$*PROGRAM.parent}/../gen/build_rakudo_home/site install Inline::Perl5";
53 say '';
54 }
55
56 my %traits = :perl5($inline-perl5-is-installed),
57 :long(!$quick), :$stress, :slow,
58 :jvm($vm eq 'jvm'), :moar($vm eq 'moar'),
59 :conc(?($vm eq any("jvm","moar")));
60 my $recode-path = $*SPEC !~~ IO::Spec::Unix;
61 for $tests-from-file.IO.lines {
62 next if / ^ \s* '#' / or not m/ \S /;
63 my ($fn, $fudgespec) = .trim.split(/ \s+ '#' \s* /);
64 my @specs = $fudgespec ?? $fudgespec.words !! ();
65 next if not all(%traits{@specs});
66
67 $fn ~~ s{ ^ <!before "t/spec/"> } = "t/spec/";
68 $fn = $*SPEC.catdir($fn.split('/')) if $recode-path;
69 if $fn.IO ~~ :r {
70 if not $no-mix-slow and any(@specs) eq 'slow' {
71 push @slow, $fn;
72 }
73 else {
74 push @files, $fn;
75 }
76 } else {
77 warn "Missing test file: $fn\n";
78 }
79 }
80 }
81
82 my @tfiles = $randomize ?? @files.flatmap(&all-in).pick(*) !! @files.flatmap(&all-in).sort;
83
84 if (@slow) {
85 @slow.=flatmap(&all-in);
86 @tfiles = (roundrobin @slow, batch(@tfiles / @slow, @tfiles)).flat;
87 }
88
89 if $fudge {
90 @tfiles = batch(200, @tfiles).flatmap(&fudge);
91 }
92
93 my $harness = ::('TAP::Harness').new(
94 :handlers[get-handler($vm, :$perlpath)],
95 :ignore-exit,
96 # :trap,
97 :$jobs,
98 :$verbosity,
99 :err('ignore'),
100 );
101 await $harness.run(@tfiles).waiter;
102
103 sub batch(Int(Real) $size, @files) {
104 gather {
105 while @files {
106 my @batch = @files.splice: 0, $size;
107 take @batch;
108 }
109 }
110 }
111
112 multi all-in(Str $start) {
113 all-in($start.IO);
114 }
115 multi all-in(IO::Path $start) {
116 return ~$start unless $start.d;
117
118 return gather {
119 listdir($start);
120 }
121
122 sub listdir(IO::Path $start) {
123 state $test = none($*SPEC.updir, $*SPEC.curdir, '.git');
124 for $start.dir(:$test) -> $file {
125 if $file.d {
126 listdir($file);
127 }
128 elsif $file ~~ / \. t $ / {
129 take ~$file;
130 }
131 }
132 }
133 }
134
135 sub fudge(@files) {
136 my $cmd = run($perl5path, 't/spec/fudgeall', '--keep-exit-code', "rakudo.$vm", |@files, :out);
137 $cmd.out.slurp-rest.split(' ').map(*.chomp);
138 }
139
140 # multi sub get-handler('jvm') {
141 # unlink 'TESTTOKEN';
142 # state $server = run ".".IO.child("perl6-eval-server"), <-bind-stdin -cookie TESTTOKEN -app perl6.jar>, :in;
143 # sleep 1;
144 # ::('TAP::Harness::SourceHandler::Exec').new($perl5path, './eval-client.pl', 'TESTTOKEN', 'run');
145 # }
146 multi sub get-handler(Any, :$perlpath) {
147 ::('TAP::Harness::SourceHandler::Perl6').new(:incdirs['lib'], :path($perlpath));
148 }
149 }
150
151 sub note-in-box { note "{'#' x 76}\n\n$^text\n\n{'#' x 76}\n" }
152 sub convert-to-versioned-file ($file) {
153 return $file unless $file eq FULL_ROAST_TEST_LIST_FILE;
154
155 my $ver = .lines.grep({!/\s* '#'/ and .trim.chars}).head.trim
156 with ROAST_VERSION_FILE.IO.open
157 orelse note-in-box "Failed to open roast VERSION file in "
158 ~ "{ROAST_VERSION_FILE}: " ~ .exception.message
159 ~ "\nDefaulting to test files from $file"
160 and return $file;
161
162 # Make a new test file name using the version of the roast. The master
163 # branch would have version something like `6.d-proposals`; in such
164 # a case, we'll use the default test file list
165 my $new-file = $file ~ (".$ver" unless $ver.lc.contains: 'propos');
166 if $new-file.IO.r {
167 say "Testing Roast version $ver using test file list from $new-file";
168 return $new-file;
169 }
170
171 note-in-box "Test list file `$new-file` for Roast version $ver does not exist\n"
172 ~ "or isn't readable. Defaulting to $file";
173 return $file;
174 }
175
176 sub USAGE { say "\n" ~ (require ::('Pod::To::Text')).render($=pod[0]) ~ "\n" }
177
178 =begin pod
179
180 =head1 NAME
181
182 t/harness - run the harness tests for Rakudo.
183
184 =head1 SYNOPSIS
185
186 t/harness [options] [files]
187
188 Options:
189
190 --help - display the help message.
191 --tests-from-file=[filename] - get the tests from the filename.
192 --fudge - apply backend specific fixups to various files
193 --verbosity=[level] - set the verbosity level.
194 --jobs - number of jobs. Defaults to TEST_JOBS env var if specified, or 1
195 --quick - do not run tests marked as long-running
196 --stress - run tests marked as stress tests
197 --randomize randomize the order in which test-files are processed.
198 --no-mixslow - don't spread tests marked "slow" equally over the run (on non-Win)
199 --perlpath - path to perl6 (defaults to $*EXECUTABLE)
200 --perl5path - path to Perl executable for various helper utilities (defaults to 'perl')
201
202 =end pod