Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/include/dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ struct Param
d_bool tracegc; // instrument calls to 'new'
d_bool vcg_ast; // write-out codegen-ast
d_bool useUnitTests; // generate unittest code
d_bool useUnitTestsRootOnly; // generate unittest code for root modules only
d_bool useInline; // inline expand functions
d_bool release; // build release version
d_bool preservePaths; // true means don't strip path from source file
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dmd/cli.d
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,11 @@ dmd -cov -unittest myprog.d
`Compile in $(LINK2 spec/unittest.html, unittest) code, turns on asserts, and sets the
$(D unittest) $(LINK2 spec/version.html#PredefinedVersions, version identifier)`,
),
Option("unittest-roots",
"compile in unit tests for root modules only",
`Compile in $(LINK2 spec/unittest.html, unittest) code, turns on asserts, and sets the
$(D unittest) $(LINK2 spec/version.html#PredefinedVersions, version identifier) only for root modules whose sources files are explicitly passed as arguments to compiler`,
),
Option("v",
"verbose",
`Enable verbose output for each compiler pass`,
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ extern (C++) final class Module : Package
}
else
{
const bool doUnittests = global.params.parsingUnittestsRequired();
const bool doUnittests = global.params.parsingUnittestsRequired(this.isRoot);
scope p = new Parser!AST(this, buf, cast(bool) docfile, global.errorSink, &global.compileEnv, doUnittests);
p.nextToken();
p.parseModuleDeclaration();
Expand Down
14 changes: 11 additions & 3 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -3804,8 +3804,9 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
const len = buf.length;
buf.writeByte(0);
const str = buf.extractSlice()[0 .. len];
const bool doUnittests = global.params.parsingUnittestsRequired();
scope p = new Parser!ASTCodegen(sc._module, str, false, global.errorSink, &global.compileEnv, doUnittests);
auto mod = sc._module;
const bool doUnittests = global.params.parsingUnittestsRequired(mod.isRoot);
scope p = new Parser!ASTCodegen(mod, str, false, global.errorSink, &global.compileEnv, doUnittests);
adjustLocForMixin(str, cd.loc, *p.baseLoc, global.params.mixinOut);
p.linnum = p.baseLoc.startLine;
p.nextToken();
Expand Down Expand Up @@ -4769,7 +4770,14 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
return;
}

if (global.params.useUnitTests)
auto use = global.params.useUnitTests;
if (use && global.params.useUnitTestsRootOnly)
{
auto m = sc._module;
if (m && !m.isRoot())
use = false;
}
if (use)
{
if (!utd.type)
utd.type = new TypeFunction(ParameterList(), Type.tvoid, LINK.d, utd.storage_class);
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -5880,7 +5880,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
{
arguments.push(makeTemplateItem(Id.InterpolatedExpression, str));
const parseErrors = global.errors;
const bool doUnittests = global.params.parsingUnittestsRequired();
const bool doUnittests = global.params.parsingUnittestsRequired(sc._module.isRoot);
auto exprSl = SourceLoc(e.interpolatedSet.locs[idx]);
scope p = new Parser!ASTCodegen(sc._module, str, false, global.errorSink, &global.compileEnv, doUnittests);
p.baseLoc.startLine = exprSl.line;
Expand Down Expand Up @@ -9394,7 +9394,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
const errors = global.errors;
const len = buf.length;
const str = buf.extractChars()[0 .. len];
const bool doUnittests = global.params.parsingUnittestsRequired();
const bool doUnittests = global.params.parsingUnittestsRequired(sc._module.isRoot);
scope p = new Parser!ASTCodegen(sc._module, str, false, global.errorSink, &global.compileEnv, doUnittests);
adjustLocForMixin(str, exp.loc, *p.baseLoc, global.params.mixinOut);
p.linnum = p.baseLoc.startLine;
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ extern (C++) struct Param
bool tracegc; // instrument calls to 'new'
bool vcg_ast; // write-out codegen-ast
bool useUnitTests; // generate unittest code
bool useUnitTestsRootOnly; // generate unittest code for root modules only
Comment thread
nordlow marked this conversation as resolved.
bool useInline = false; // inline expand functions
bool release; // build release version
bool preservePaths; // true means don't strip path from source file
Expand Down Expand Up @@ -274,9 +275,9 @@ extern (C++) struct Param
const(char)* timeTraceFile; /// File path of output file

///
bool parsingUnittestsRequired() @safe
bool parsingUnittestsRequired(bool isRoot) @safe
Comment thread
nordlow marked this conversation as resolved.
{
return useUnitTests || ddoc.doOutput || dihdr.doOutput;
return (useUnitTests && (!useUnitTestsRootOnly || isRoot)) || ddoc.doOutput || dihdr.doOutput;
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/iasm/dmdaarch64.d
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Statement inlineAsmAArch64Semantic(InlineAsmStatement s, Scope* sc)
}
}

const bool doUnittests = global.params.parsingUnittestsRequired();
const bool doUnittests = global.params.parsingUnittestsRequired(sc._module.isRoot);
scope p = new Parser!ASTCodegen(sc._module, "", false, global.errorSink, &global.compileEnv, doUnittests);

/* Set list of tokens that will be the input to the parser, and starting line number to use.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/iasm/gcc.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import dmd.typesem;
public Statement gccAsmSemantic(GccAsmStatement s, Scope* sc)
{
//printf("GccAsmStatement.semantic()\n");
const bool doUnittests = global.params.parsingUnittestsRequired();
const bool doUnittests = global.params.parsingUnittestsRequired(sc._module.isRoot);
scope p = (sc && sc.inCfile)
? new CParser!ASTCodegen(sc._module, "", false, global.errorSink, target.c, null, &global.compileEnv)
: new Parser!ASTCodegen(sc._module, "", false, global.errorSink, &global.compileEnv, doUnittests);
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,11 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, out Param
}
else if (arg == "-unittest")
params.useUnitTests = true;
else if (arg == "-unittest-roots")
{
params.useUnitTests = true;
params.useUnitTestsRootOnly = true;
}
else if (p[1] == 'I') // https://dlang.org/dmd.html#switch-I
{
params.imppath.push(ImportPathInfo(p + 2 + (p[2] == '=')));
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/statementsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -5001,7 +5001,7 @@ private Statements* flatten(Statement statement, Scope* sc)
const len = buf.length;
buf.writeByte(0);
const str = buf.extractSlice()[0 .. len];
const bool doUnittests = global.params.parsingUnittestsRequired();
const bool doUnittests = global.params.parsingUnittestsRequired(sc._module.isRoot);
scope p = new Parser!ASTCodegen(sc._module, str, false, global.errorSink, &global.compileEnv, doUnittests);
adjustLocForMixin(str, cs.loc, *p.baseLoc, global.params.mixinOut);
p.linnum = p.baseLoc.startLine;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -9660,7 +9660,7 @@ RootObject compileTypeMixin(TypeMixin tm, Loc loc, Scope* sc)
const len = buf.length;
buf.writeByte(0);
const str = buf.extractSlice()[0 .. len];
const bool doUnittests = global.params.parsingUnittestsRequired();
const bool doUnittests = global.params.parsingUnittestsRequired(sc._module.isRoot);
scope p = new Parser!ASTCodegen(sc._module, str, false, global.errorSink, &global.compileEnv, doUnittests);
adjustLocForMixin(str, loc, *p.baseLoc, global.params.mixinOut);
p.linnum = p.baseLoc.startLine;
Expand Down
Loading