@@ -10,6 +10,7 @@ use v6;
10
10
}
11
11
12
12
use Test ;
13
+ use File::Temp;
13
14
14
15
use lib ' lib' ;
15
16
use Pod ::Convenience;
@@ -46,6 +47,7 @@ sub walk($arg) {
46
47
47
48
# Extract all the examples from the given files
48
49
my @ examples ;
50
+
49
51
my $ counts = BagHash . new ;
50
52
for @ files -> $ file {
51
53
for extract-pod($ file . IO ). contents -> $ chunk {
@@ -65,6 +67,7 @@ for @files -> $file {
65
67
' ok-test' , $ chunk . config<ok-test > // " " ,
66
68
' preamble' , $ chunk . config<preamble > // " " ,
67
69
' method' , $ chunk . config<method > // " " ,
70
+ ' solo' , $ chunk . config<solo > // " " ,
68
71
);
69
72
}
70
73
}
@@ -90,37 +93,52 @@ for @examples -> $eg {
90
93
# Further wrap in an anonymous class (so bare method works)
91
94
# Add in empty routine bodies if needed
92
95
93
- my $ code = ' no worries; ' ;
94
- $ code ~ = " if False \{\n class :: \{\n " ;
95
- $ code ~ = $ eg <preamble > ~ " ;\n " ;
96
-
97
- for $ eg <contents >. lines -> $ line {
98
- $ code ~ = $ line ;
99
- if $ line . trim . starts-with (any (<multi method proto only sub >)) && ! $ line . trim . ends-with (any (' }' ,' ,' )) && $ eg <method > eq " " {
100
- $ code ~ = " \{ }" ;
101
- }
102
- if $ eg <method > eq " " || $ eg <method > eq " False" {
103
- $ code ~ = " \n " ;
96
+ my $ code ;
97
+ if $ eg <solo > {
98
+ $ code = $ eg <contents >;
99
+ } else {
100
+ $ code = ' no worries; ' ;
101
+ $ code ~ = " if False \{\n class :: \{\n " ;
102
+ $ code ~ = $ eg <preamble > ~ " ;\n " ;
103
+
104
+ for $ eg <contents >. lines -> $ line {
105
+ $ code ~ = $ line ;
106
+ if $ line . trim . starts-with (any (<multi method proto only sub >)) && ! $ line . trim . ends-with (any (' }' ,' ,' )) && $ eg <method > eq " " {
107
+ $ code ~ = " \{ }" ;
108
+ }
109
+ if $ eg <method > eq " " || $ eg <method > eq " False" {
110
+ $ code ~ = " \n " ;
111
+ }
104
112
}
113
+ $ code ~ = " \{ }\n " if $ eg <method > eq " True" ;
114
+ $ code ~ = " \n }}" ;
105
115
}
106
- $ code ~ = " \{ }\n " if $ eg <method > eq " True" ;
107
- $ code ~ = " \n }}" ;
108
116
109
117
my $ msg = " $ eg <file> chunk $ eg <count> starts with “" ~ starts-with ($ eg <contents >) ~ " ” compiles" ;
110
118
111
- my $ status ;
119
+ my $ has-error ;
112
120
{
113
- temp $ * OUT = open : w, $ * SPEC . devnull;
114
- temp $ * ERR = open : w, $ * SPEC . devnull;
115
- try EVAL $ code ;
116
- $ status = $! ;
117
- close $ * OUT ;
118
- close $ * ERR ;
121
+ # Does the test require its own file?
122
+ if $ eg <solo > {
123
+ my ($ tmp_fname , $ tmp_io ) = tempfile;
124
+ $ tmp_io . spurt : $ code , : close;
125
+ my $ proc = Proc ::Async. new ($ * EXECUTABLE , ' -c' , $ tmp_fname );
126
+ $ proc . stdout. tap : {;};
127
+ $ proc . stderr. tap : {;};
128
+ $ has-error = ! await $ proc . start;
129
+ } else {
130
+ temp $ * OUT = open : w, $ * SPEC . devnull;
131
+ temp $ * ERR = open : w, $ * SPEC . devnull;
132
+ try EVAL $ code ;
133
+ $ has-error = $! ;
134
+ close $ * OUT ;
135
+ close $ * ERR ;
136
+ }
119
137
}
120
138
todo (1 ) if $ eg <todo >;
121
- if $ status {
139
+ if $ has-error {
122
140
diag $ eg <contents >;
123
- diag $ status ;
141
+ diag $ has-error ;
124
142
flunk $ msg ;
125
143
} else {
126
144
pass $ msg ;
0 commit comments