Skip to content

Commit

Permalink
Do not parse unittest blocks unless -unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 1, 2015
1 parent c4bcacc commit c32ff34
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
40 changes: 37 additions & 3 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,43 @@ Dsymbols *Parser::parseDeclDefs(int once, Dsymbol **pLastDecl, PrefixAttributes
}

case TOKunittest:
s = parseUnitTest(pAttrs);
if (*pLastDecl)
(*pLastDecl)->ddocUnittest = (UnitTestDeclaration *)s;
if (global.params.useUnitTests || global.params.doDocComments || global.params.doHdrGeneration)
{
s = parseUnitTest(pAttrs);
if (*pLastDecl)
(*pLastDecl)->ddocUnittest = (UnitTestDeclaration *)s;
}
else
{
// Skip over unittest block by counting { }
Loc loc = token.loc;
int braces = 0;
while (1)
{
nextToken();
switch (token.value)
{
case TOKlcurly:
++braces;
continue;

case TOKrcurly:
if (--braces)
continue;
nextToken();
break;

case TOKeof:
/* { */
error(loc, "closing } of unittest not found before end of file");
goto Lerror;

default:
continue;
}
break;
}
}
break;

case TOKnew:
Expand Down
2 changes: 1 addition & 1 deletion test/compilable/testheader1.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EXTRA_SOURCES: extra-files/header1.d
// REQUIRED_ARGS: -o- -H -Hf${RESULTS_DIR}/compilable/header1.di
// REQUIRED_ARGS: -o- -unittest -H -Hf${RESULTS_DIR}/compilable/header1.di
// PERMUTE_ARGS: -d -dw
// POST_SCRIPT: compilable/extra-files/header-postscript.sh header1

Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail14249.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
REQUIRED_ARGS: -unittest
TEST_OUTPUT:
---
fail_compilation/fail14249.d(23): Error: shared static constructor can only be member of module/aggregate/template, not function main
Expand All @@ -17,7 +18,6 @@ fail_compilation/fail14249.d(35): Error: anonymous union can only be a part of a
fail_compilation/fail14249.d(39): Error: mixin fail14249.main.Mix!() error instantiating
---
*/

mixin template Mix()
{
shared static this() {}
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail4375t.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// REQUIRED_ARGS: -w
// REQUIRED_ARGS: -w -unittest
// 4375: Dangling else

unittest { // disallowed
Expand Down

0 comments on commit c32ff34

Please sign in to comment.