Skip to content

Commit c992eca

Browse files
assert_writeln_magic: Report filename on error (instead of magic.d) (#3227)
* assert_writeln_magic: Report filename on error (instead of `magic.d`) Pass the current file path to libdparse s.t. error messages point to the actual file instead of `magic.d`. * preprocessor: Ensure that error messages are not interleaved Using a single call ensures that parallel builds won't mess up the output
1 parent d3e26a2 commit c992eca

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

ddoc/source/assert_writeln_magic.d

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private:
178178
Out fl;
179179
}
180180

181-
void parseString(Visitor)(ubyte[] sourceCode, Visitor visitor)
181+
void parseString(Visitor)(const string filepath, ubyte[] sourceCode, Visitor visitor)
182182
{
183183
import dparse.lexer;
184184
import dparse.parser : parseModule, ParserConfig;
@@ -189,28 +189,28 @@ void parseString(Visitor)(ubyte[] sourceCode, Visitor visitor)
189189
const(Token)[] tokens = getTokensForParser(sourceCode, config, &cache).array;
190190

191191
RollbackAllocator rba;
192-
auto m = parseModule(ParserConfig(tokens, "magic.d", &rba));
192+
auto m = parseModule(ParserConfig(tokens, filepath, &rba));
193193
visitor.visit(m);
194194
}
195195

196-
private auto assertWritelnModuleImpl(string fileText)
196+
private auto assertWritelnModuleImpl(const string filepath, string fileText)
197197
{
198198
import std.string : representation;
199199
auto fl = FileLines(fileText);
200200
scope visitor = new TestVisitor!(typeof(fl))(fl);
201201
// libdparse doesn't allow to work on immutable source code
202-
parseString(cast(ubyte[]) fileText.representation, visitor);
202+
parseString(filepath, cast(ubyte[]) fileText.representation, visitor);
203203
return fl;
204204
}
205205

206-
auto assertWritelnModule(string fileText)
206+
auto assertWritelnModule(const string filepath, string fileText)
207207
{
208-
return assertWritelnModuleImpl(fileText).buildLines;
208+
return assertWritelnModuleImpl(filepath, fileText).buildLines;
209209
}
210-
auto assertWritelnBlock(string fileText)
210+
auto assertWritelnBlock(const string filepath, string fileText)
211211
{
212212
auto source = "unittest{\n" ~ fileText ~ "}\n";
213-
auto fl = assertWritelnModuleImpl(source);
213+
auto fl = assertWritelnModuleImpl(filepath, source);
214214
auto app = appender!string;
215215
foreach (line; fl.lines[1 .. $ - 2])
216216
{
@@ -275,7 +275,7 @@ version(unittest)
275275
import std.string : representation;
276276
auto mock = FileLinesMock(sourceCode.split("\n"));
277277
scope visitor = new TestVisitor!(typeof(mock))(mock);
278-
parseString(sourceCode.representation.dup, visitor);
278+
parseString("unittest.d", sourceCode.representation.dup, visitor);
279279
return mock;
280280
}
281281
}

ddoc/source/preprocessor.d

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ All unknown options are passed to the compiler.
6666

6767
// Phobos index.d should have been named index.dd
6868
if (inputFile.endsWith(".d") && !inputFile.endsWith("index.d"))
69-
text = assertWritelnModule(text);
69+
text = assertWritelnModule(inputFile, text);
7070

7171
string[string] macros;
7272
macros["SRC_FILENAME"] = "%s\n".format(inputFile.buildNormalizedPath);
@@ -114,10 +114,13 @@ auto compile(R)(R buffer, string[] arguments, string inputFile, string[string] m
114114
auto ret = execute(args);
115115
if (ret.status != 0)
116116
{
117-
stderr.writeln("File content:");
118-
stderr.writeln(buffer);
119-
stderr.writeln("----------------------------------------");
120-
stderr.writeln(ret.output);
117+
stderr.writeln(
118+
"\n------------- File content -------------\n",
119+
buffer,
120+
"\n------------ Compiler output -----------\n",
121+
ret.output,
122+
"\n----------------------------------------\n",
123+
);
121124
}
122125
return ret.status;
123126
}

dpl-docs/source/ddox_main.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int cmdFilterDocs(string[] args)
129129
writefln("Warning: Cannot add documented unit test %s to %s, which is not documented.", name, last_decl["name"].opt!string);
130130
} else {
131131
import assert_writeln_magic;
132-
auto rewrittenSource = assertWritelnBlock(source);
132+
auto rewrittenSource = assertWritelnBlock(mod["file"].get!string(), source);
133133
last_decl["comment"] ~= format("Example:\n%s$(DDOX_UNITTEST_HEADER %s)\n---\n%s\n---\n$(DDOX_UNITTEST_FOOTER %s)\n", comment.strip, name, rewrittenSource, name);
134134
}
135135
} catch (Exception e) {

0 commit comments

Comments
 (0)