Skip to content

Commit

Permalink
Merge pull request #2544 from AndrejMitrovic/Fix10992
Browse files Browse the repository at this point in the history
Issue 10992 - Missing unittests when using getUnittests trait
  • Loading branch information
9rnsr committed Sep 30, 2013
2 parents 163d36b + 331b5b0 commit efe4275
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/doc.c
Expand Up @@ -546,7 +546,7 @@ void emitUnittestComment(Scope *sc, Dsymbol *s, size_t ofs)
{
OutBuffer *buf = sc->docbuf;

for (UnitTestDeclaration *utd = s->unittest; utd; utd = utd->unittest)
for (UnitTestDeclaration *utd = s->ddocUnittest; utd; utd = utd->ddocUnittest)
{
if (utd->protection == PROTprivate || !utd->comment || !utd->fbody)
continue;
Expand Down Expand Up @@ -607,7 +607,7 @@ void Dsymbol::emitDitto(Scope *sc)
sc->lastoffset += b.offset;

Dsymbol *s = this;
if (!s->unittest && parent)
if (!s->ddocUnittest && parent)
s = parent->isTemplateDeclaration();
if (s)
emitUnittestComment(sc, s, strlen(ddoc_decl_dd_e));
Expand Down Expand Up @@ -1370,7 +1370,7 @@ void DocComment::parseSections(utf8_t *comment)
void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
{
//printf("DocComment::writeSections()\n");
if (sections.dim || s->unittest)
if (sections.dim || s->ddocUnittest)
{
buf->writestring("$(DDOC_SECTIONS \n");
for (size_t i = 0; i < sections.dim; i++)
Expand All @@ -1391,7 +1391,7 @@ void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
buf->writestring(")\n");
}
}
if (s->unittest)
if (s->ddocUnittest)
emitUnittestComment(sc, s, 0);
buf->writestring(")\n");
}
Expand Down
4 changes: 2 additions & 2 deletions src/dsymbol.c
Expand Up @@ -52,7 +52,7 @@ Dsymbol::Dsymbol()
this->errors = false;
this->depmsg = NULL;
this->userAttributes = NULL;
this->unittest = NULL;
this->ddocUnittest = NULL;
}

Dsymbol::Dsymbol(Identifier *ident)
Expand All @@ -69,7 +69,7 @@ Dsymbol::Dsymbol(Identifier *ident)
this->errors = false;
this->depmsg = NULL;
this->userAttributes = NULL;
this->unittest = NULL;
this->ddocUnittest = NULL;
}

bool Dsymbol::equals(RootObject *o)
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol.h
Expand Up @@ -128,7 +128,7 @@ class Dsymbol : public RootObject
PASS semanticRun;
char *depmsg; // customized deprecation message
Expressions *userAttributes; // user defined attributes from UserAttributeDeclaration
UnitTestDeclaration *unittest; // !=NULL means there's a unittest associated with this symbol
UnitTestDeclaration *ddocUnittest; // !=NULL means there's a ddoc unittest associated with this symbol (only use this with ddoc)

Dsymbol();
Dsymbol(Identifier *);
Expand Down
2 changes: 1 addition & 1 deletion src/parse.c
Expand Up @@ -276,7 +276,7 @@ Dsymbols *Parser::parseDeclDefs(int once, Dsymbol **pLastDecl)

case TOKunittest:
s = parseUnitTest();
if (*pLastDecl) (*pLastDecl)->unittest = (UnitTestDeclaration *)s;
if (*pLastDecl) (*pLastDecl)->ddocUnittest = (UnitTestDeclaration *)s;
break;

case TOKnew:
Expand Down
11 changes: 6 additions & 5 deletions src/traits.c
Expand Up @@ -91,13 +91,12 @@ static int fptraits(void *param, Dsymbol *s)
* unitTests array of DsymbolExp's of the collected unit test functions
* uniqueUnitTests updated with symbols from unitTests[ ]
*/
static void collectUnitTests (Dsymbols *symbols, AA *uniqueUnitTests, Expressions *unitTests)
static void collectUnitTests(Dsymbols *symbols, AA *uniqueUnitTests, Expressions *unitTests)
{
for (size_t i = 0; i < symbols->dim; i++)
{
Dsymbol *symbol = (*symbols)[i];
UnitTestDeclaration *unitTest = symbol->unittest ? symbol->unittest : symbol->isUnitTestDeclaration();

UnitTestDeclaration *unitTest = symbol->isUnitTestDeclaration();
if (unitTest)
{
if (!_aaGetRvalue(uniqueUnitTests, unitTest))
Expand All @@ -110,13 +109,15 @@ static void collectUnitTests (Dsymbols *symbols, AA *uniqueUnitTests, Expression
*value = true;
}
}

else
{
AttribDeclaration *attrDecl = symbol->isAttribDeclaration();

if (attrDecl)
collectUnitTests(attrDecl->decl, uniqueUnitTests, unitTests);
{
Dsymbols *decl = attrDecl->include(NULL, NULL);
collectUnitTests(decl, uniqueUnitTests, unitTests);
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/compilable/test10992.d
@@ -0,0 +1,11 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -unittest

unittest { }
unittest { }
unittest { }

void main()
{
static assert(__traits(getUnitTests, mixin(__MODULE__)).length == 3);
}
16 changes: 16 additions & 0 deletions test/compilable/test10992b.d
@@ -0,0 +1,16 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -unittest

version(none)
{}
else
{
unittest { }
unittest { }
unittest { }
}

void main()
{
static assert(__traits(getUnitTests, mixin(__MODULE__)).length == 3);
}

0 comments on commit efe4275

Please sign in to comment.