Skip to content

Commit 017530c

Browse files
committed
Make one subtest per file in xt/examples-compilation.t
Refactor xt/examples-compilation.t to give each tested POD file its own subtest. This restores a rough test plan and refs #2798 without giving up memory usage improvements for #2764.
1 parent 14c6081 commit 017530c

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed

xt/examples-compilation.t

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,52 +33,16 @@ Perl 6 level one.
3333
3434
=end SYNOPSIS
3535

36-
my @files = Test-Files.pods;
36+
plan +my @files = Test-Files.pods;
3737

38-
sub walk($arg) {
39-
given $arg {
40-
when Pod::FormattingCode { walk $arg.contents }
41-
when Str { $arg }
42-
when Array { $arg.map({walk $_}).join }
43-
}
44-
}
45-
46-
# Extract all the examples from the given files
4738
for @files -> $file {
48-
my $counts = 0;
49-
my @chunks = extract-pod($file.IO).contents;
50-
while @chunks {
51-
my $chunk = @chunks.pop;
52-
if $chunk ~~ Pod::Block::Code {
53-
if $chunk.config<lang> && $chunk.config<lang> ne 'perl6' {
54-
next; # Only testing Perl 6 snippets.
55-
}
56-
my $todo = False;
57-
if $chunk.config<skip-test> {
58-
%*ENV<P6_DOC_TEST_FUDGE> ?? ($todo = True) !! next;
59-
}
60-
check-chunk( %(
61-
'contents', $chunk.contents.map({walk $_}).join,
62-
'file', $file,
63-
'count', ++$counts,
64-
'todo', $todo,
65-
'ok-test', $chunk.config<ok-test> // "",
66-
'preamble', $chunk.config<preamble> // "",
67-
'method', $chunk.config<method> // "",
68-
'solo', $chunk.config<solo> // "",
69-
) );
70-
} else {
71-
if $chunk.^can('contents') {
72-
@chunks.push(|$chunk.contents)
73-
}
74-
}
39+
subtest $file => {
40+
plan +my @examples = code-blocks($file);
41+
test-example $_ for @examples;
7542
}
7643
}
7744

78-
done-testing;
79-
80-
sub check-chunk( $eg ) {
81-
45+
sub test-example ($eg) {
8246
# #1355 - don't like .WHAT in examples
8347
if ! $eg<ok-test>.contains('WHAT') && $eg<contents>.contains('.WHAT') {
8448
flunk "$eg<file> chunk starting with «" ~ starts-with($eg<contents>) ~ '» uses .WHAT: try .^name instead';
@@ -97,7 +61,8 @@ sub check-chunk( $eg ) {
9761
if $eg<solo> {
9862
$code = $eg<preamble> ~ ";\n" if $eg<preamble>;
9963
$code ~= $eg<contents>;
100-
} else {
64+
}
65+
else {
10166
$code = 'no worries; ';
10267
$code ~= "if False \{\nclass :: \{\n";
10368
$code ~= $eg<preamble> ~ ";\n";
@@ -136,7 +101,8 @@ sub check-chunk( $eg ) {
136101
$proc.stdout.tap: {;};
137102
$proc.stderr.tap: {;};
138103
$has-error = ! await $proc.start;
139-
} else {
104+
}
105+
else {
140106
temp $*OUT = open :w, $*SPEC.devnull;
141107
temp $*ERR = open :w, $*SPEC.devnull;
142108
use nqp;
@@ -153,11 +119,52 @@ sub check-chunk( $eg ) {
153119
diag $eg<contents>;
154120
diag $has-error;
155121
flunk $msg;
156-
} else {
122+
}
123+
else {
157124
pass $msg;
158125
}
159126
}
160127

161-
sub starts-with( Str $chunk ) {
128+
sub code-blocks (IO() $file) {
129+
my $count;
130+
my @chunks = extract-pod($file).contents;
131+
gather while @chunks {
132+
my $chunk = @chunks.pop;
133+
if $chunk ~~ Pod::Block::Code {
134+
# Only testing Perl 6 snippets.
135+
next unless $chunk.config<lang>:v eq '' | 'perl6';
136+
137+
my $todo = False;
138+
if $chunk.config<skip-test> {
139+
%*ENV<P6_DOC_TEST_FUDGE> ?? ($todo = True) !! next;
140+
}
141+
take %(
142+
'contents', $chunk.contents.map({walk $_}).join,
143+
'file', $file,
144+
'count', ++$count,
145+
'todo', $todo,
146+
'ok-test', $chunk.config<ok-test> // "",
147+
'preamble', $chunk.config<preamble> // "",
148+
'method', $chunk.config<method> // "",
149+
'solo', $chunk.config<solo> // "",
150+
);
151+
}
152+
else {
153+
if $chunk.^can('contents') {
154+
@chunks.push(|$chunk.contents)
155+
}
156+
}
157+
}
158+
}
159+
160+
sub walk ($arg) {
161+
given $arg {
162+
when Pod::FormattingCode { walk $arg.contents }
163+
when Str { $arg }
164+
when Array { $arg.map({walk $_}).join }
165+
}
166+
}
167+
168+
sub starts-with (Str $chunk) {
162169
($chunk.lines)[0].substr(0,10).trim
163170
}

0 commit comments

Comments
 (0)