@@ -33,52 +33,16 @@ Perl 6 level one.
33
33
34
34
= end SYNOPSIS
35
35
36
- my @ files = Test-Files. pods;
36
+ plan + my @ files = Test-Files. pods;
37
37
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
47
38
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 ;
75
42
}
76
43
}
77
44
78
- done-testing ;
79
-
80
- sub check-chunk ( $ eg ) {
81
-
45
+ sub test-example ($ eg ) {
82
46
# #1355 - don't like .WHAT in examples
83
47
if ! $ eg <ok-test >. contains (' WHAT' ) && $ eg <contents >. contains (' .WHAT' ) {
84
48
flunk " $ eg <file> chunk starting with «" ~ starts-with ($ eg <contents >) ~ ' » uses .WHAT: try .^name instead' ;
@@ -97,7 +61,8 @@ sub check-chunk( $eg ) {
97
61
if $ eg <solo > {
98
62
$ code = $ eg <preamble > ~ " ;\n " if $ eg <preamble >;
99
63
$ code ~ = $ eg <contents >;
100
- } else {
64
+ }
65
+ else {
101
66
$ code = ' no worries; ' ;
102
67
$ code ~ = " if False \{\n class :: \{\n " ;
103
68
$ code ~ = $ eg <preamble > ~ " ;\n " ;
@@ -136,7 +101,8 @@ sub check-chunk( $eg ) {
136
101
$ proc . stdout. tap : {;};
137
102
$ proc . stderr. tap : {;};
138
103
$ has-error = ! await $ proc . start;
139
- } else {
104
+ }
105
+ else {
140
106
temp $ * OUT = open : w, $ * SPEC . devnull;
141
107
temp $ * ERR = open : w, $ * SPEC . devnull;
142
108
use nqp ;
@@ -153,11 +119,52 @@ sub check-chunk( $eg ) {
153
119
diag $ eg <contents >;
154
120
diag $ has-error ;
155
121
flunk $ msg ;
156
- } else {
122
+ }
123
+ else {
157
124
pass $ msg ;
158
125
}
159
126
}
160
127
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 ) {
162
169
($ chunk . lines )[0 ]. substr (0 ,10 ). trim
163
170
}
0 commit comments