Skip to content

Commit 418bf18

Browse files
authored
[tools/dspec_tester] When example fails, show error with filename (#4207)
Wrap example code in "---" RUNNABLE_EXAMPLE_FAIL tests [tools/dspec_tester] When example fails, show error with filename Without this it's sometimes hard to quickly see which file failed.
1 parent a14dfb1 commit 418bf18

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tools/dspec_tester.d

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,17 @@ int main(string[] args)
141141
modImport = modImport.replace(dirSeparator, ".");
142142
}
143143
const text = file.readText;
144-
// Find all examples in the specification
144+
// Lazy range of matching examples code contents
145145
alias findExamples = (ddocKey) => text
146146
.findDdocMacro(ddocKey)
147147
.map!ddocMacroToCode;
148148
auto allTests = specTypes.map!(c => findExamples(c.key)
149-
.map!(e => compileAndCheck(e, CompileConfig(c.mode), modImport)))
149+
.map!((e) {
150+
auto code = compileAndCheck(e, CompileConfig(c.mode), modImport);
151+
if (code)
152+
writefln("%s: Error testing above example", file[rootDir.length+1..$]);
153+
return code;
154+
}))
150155
.joiner;
151156
if (!allTests.empty)
152157
{
@@ -221,7 +226,10 @@ auto compileAndCheck(R)(R buffer, CompileConfig config, string modImport)
221226
{
222227
if (ret == 0)
223228
{
224-
stderr.writefln("Compilation should have failed for:\n%s", buffer);
229+
stderr.writeln("Compilation should have failed for:");
230+
stderr.writeln("---");
231+
stderr.writeln(buffer);
232+
stderr.writeln("---");
225233
ret = 1;
226234
}
227235
else

0 commit comments

Comments
 (0)