@@ -87,12 +87,15 @@ auto ddocMacroToCode(R)(R text)
87
87
88
88
int main (string [] args)
89
89
{
90
- import std.file , std.getopt , std.path ;
90
+ import std.file , std.getopt ;
91
91
import std.parallelism : parallel;
92
+ import std.path ;
92
93
import std.process : environment;
93
94
import std.typecons : Tuple ;
94
95
95
- auto specDir = __FILE_FULL_PATH__.dirName.dirName.buildPath(" spec" );
96
+ const rootDir = __FILE_FULL_PATH__.dirName.dirName;
97
+ const specDir = rootDir.buildPath(" spec" );
98
+ const stdDir = rootDir.buildPath(" .." , " phobos" , " std" );
96
99
bool hasFailed;
97
100
98
101
config.dmdBinPath = environment.get (" DMD" , " dmd" );
@@ -121,15 +124,27 @@ int main(string[] args)
121
124
SpecType(" $(SPEC_RUNNABLE_EXAMPLE_COMPILE" , CompileConfig.TestMode.compile),
122
125
SpecType(" $(SPEC_RUNNABLE_EXAMPLE_RUN" , CompileConfig.TestMode.run),
123
126
SpecType(" $(SPEC_RUNNABLE_EXAMPLE_FAIL" , CompileConfig.TestMode.fail),
127
+ SpecType(" $(RUNNABLE_EXAMPLE" , CompileConfig.TestMode.run),
124
128
];
125
- foreach (file; specDir.dirEntries(" *.dd" , SpanMode.depth).parallel(1 ))
129
+ auto files = chain(specDir.dirEntries(" *.dd" , SpanMode.depth),
130
+ stdDir.dirEntries(" *.d" , SpanMode.depth));
131
+ foreach (file; files.parallel(1 ))
126
132
{
133
+ // auto-import current module if in phobos
134
+ string modImport = file.name.find(stdDir);
135
+ if (modImport.length)
136
+ {
137
+ modImport = " std" ~ modImport[stdDir.length.. $];
138
+ modImport = modImport.stripExtension();
139
+ modImport = modImport.findSplitBefore(dirSeparator ~ " package" )[0 ];
140
+ modImport = modImport.replace(dirSeparator, " ." );
141
+ }
127
142
auto allTests = specTypes.map! (c => findExamples(file, c.key)
128
- .map! (e => compileAndCheck(e, CompileConfig(c.mode))))
129
- .joiner;
143
+ .map! (e => compileAndCheck(e, CompileConfig(c.mode), modImport )))
144
+ .joiner;
130
145
if (! allTests.empty)
131
146
{
132
- writefln(" %s: %d examples found" , file.baseName , allTests.walkLength);
147
+ writefln(" %s: %d examples found" , file[rootDir.length + 1 .. $] , allTests.walkLength);
133
148
if (allTests.any! (a => a != 0 ))
134
149
hasFailed = true ;
135
150
}
@@ -154,7 +169,7 @@ Params:
154
169
155
170
Returns: the exit code of the compiler invocation.
156
171
*/
157
- auto compileAndCheck (R)(R buffer, CompileConfig config)
172
+ auto compileAndCheck (R)(R buffer, CompileConfig config, string modImport )
158
173
{
159
174
import std.process ;
160
175
import std.uni : isWhite;
@@ -186,7 +201,8 @@ auto compileAndCheck(R)(R buffer, CompileConfig config)
186
201
if (! buffer.find! (a => ! a.isWhite).startsWith(" module" ))
187
202
{
188
203
buffer = " import std.stdio;\n " ~ buffer; // used too often
189
-
204
+ if (modImport.length)
205
+ buffer = " import " ~ modImport ~ " ;" ~ buffer;
190
206
if (! hasMain)
191
207
buffer = " void main() {\n " ~ buffer ~ " \n }" ;
192
208
}
0 commit comments