Skip to content

Commit 1610498

Browse files
committed
Run one example per test, not one file
For #1194 * Eliminate separate example extraction step * Use the same extract-pod mechanism used by htmlify (gets us the same precompilation for unchanged source) * When a test fails, output the original code snippet (Line number is desired, but isn't part of the Pod object)
1 parent e4c8c21 commit 1610498

File tree

3 files changed

+59
-112
lines changed

3 files changed

+59
-112
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ xt/aspell.pws
2424
highlights/node_modules
2525
**/npm-debug.log
2626
highlights/atom-language-perl6/
27-
examples/

util/extract-examples.p6

Lines changed: 0 additions & 81 deletions
This file was deleted.

xt/examples-compilation.t

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,77 @@
11
use v6;
22
use Test;
3-
use lib 'lib';
4-
use File::Find;
3+
use File::Temp;
54

6-
# Extract examples
7-
chdir $?FILE.IO.dirname.IO.dirname;
8-
my $p1 = shell "$*EXECUTABLE-NAME util/extract-examples.p6 --source-path=./doc/ --prefix=./examples/";
9-
chdir 'examples';
5+
use lib 'lib';
6+
use Pod::Convenience;
107

118
my @files;
129

1310
if @*ARGS {
14-
# don't pass examples/ as part of the path name
1511
@files = @*ARGS;
1612
} else {
17-
@files = find(
18-
dir => '.',
19-
type => 'file',
20-
exclude => /
21-
| 'Language/5to6-nutshell.p6'
22-
| 'Language/5to6-perlfunc.p6'
23-
| 'Language/5to6-perlop.p6'
24-
| 'Language/5to6-perlsyn.p6'
25-
| 'Language/5to6-perlvar.p6'
26-
| 'Language/modules.p6'
27-
| 'Language/nativecall.p6'
28-
| 'Language/packages.p6'
29-
| 'Language/phasers.p6'
30-
| 'Language/rb-nutshell.p6'
31-
| 'Language/tables.p6'
32-
| 'Language/testing.p6'
33-
| 'Language/traps.p6'
13+
for qx<git ls-files doc>.lines -> $file {
14+
next unless $file ~~ / '.pod6' $/;
15+
next if $file ~~ /
16+
| 'doc/Language/5to6-nutshell.pod6'
17+
| 'doc/Language/5to6-perlfunc.pod6'
18+
| 'doc/Language/5to6-perlop.pod6'
19+
| 'doc/Language/5to6-perlsyn.pod6'
20+
| 'doc/Language/5to6-perlvar.pod6'
21+
| 'doc/Language/modules.pod6'
22+
| 'doc/Language/nativecall.pod6'
23+
| 'doc/Language/packages.pod6'
24+
| 'doc/Language/phasers.pod6'
25+
| 'doc/Language/rb-nutshell.pod6'
26+
| 'doc/Language/tables.pod6'
27+
| 'doc/Language/testing.pod6'
28+
| 'doc/Language/traps.pod6'
3429
/,
35-
);
30+
push @files, $file;
31+
}
32+
}
33+
34+
# Extract all the examples from the given files
35+
my @examples;
36+
my $counts = BagHash.new;
37+
for @files -> $file {
38+
for extract-pod($file.IO).contents -> $chunk {
39+
if $chunk ~~ Pod::Block::Code {
40+
next if $chunk.config<skip-test>;
41+
@examples.push: %(
42+
'contents', $chunk.contents.join("\n"),
43+
'file', $file,
44+
'count', $counts{$file}++
45+
);
46+
}
47+
}
3648
}
3749

3850
my $proc;
39-
plan +@files;
51+
plan +@examples;
4052

41-
for @files -> $file {
42-
$proc = run 'perl6', '-c', $file, out => '/dev/null', err => '/dev/null';
53+
for @examples -> $eg {
54+
my ($filename, $filehandle) = tempfile;
55+
56+
# Wrap each snippet in an anonymous class, and add in empty routine bodies if needed
57+
58+
my $code = "class :: \{\n" ~ $eg<contents>.trim.map({
59+
.starts-with('multi') ||
60+
.starts-with('method') ||
61+
.starts-with('proto') ||
62+
.starts-with('only') ||
63+
.starts-with('sub')
64+
}).join("\n") ~ "\n\}";
65+
66+
$filehandle.print: $code;
67+
$filehandle.close;
68+
69+
$proc = run $*EXECUTABLE-NAME, '-c', $filename, out => '/dev/null', err => '/dev/null';
70+
my $msg = "$eg<file> chunk $eg<count> compiles";
4371
if $proc.exitcode == 0 {
44-
pass "$file is compilable";
72+
pass $msg;
4573
} else {
46-
flunk "$file examples check isn't successful";
74+
diag $eg<contents>;
75+
flunk $msg;
4776
}
4877
}

0 commit comments

Comments
 (0)