diff --git a/src/doc.c b/src/doc.c index e0bf153cf1ad..8af895d8ff09 100644 --- a/src/doc.c +++ b/src/doc.c @@ -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; @@ -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)); @@ -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++) @@ -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"); } diff --git a/src/dsymbol.c b/src/dsymbol.c index 96dda5f87f55..0899212941db 100644 --- a/src/dsymbol.c +++ b/src/dsymbol.c @@ -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) @@ -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) diff --git a/src/dsymbol.h b/src/dsymbol.h index 32237e368b55..32d95c0e6006 100644 --- a/src/dsymbol.h +++ b/src/dsymbol.h @@ -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 *); diff --git a/src/parse.c b/src/parse.c index 38daef9a6ad7..71c15b0f0427 100644 --- a/src/parse.c +++ b/src/parse.c @@ -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: diff --git a/src/traits.c b/src/traits.c index 663f672991e9..7fc0d25d3506 100644 --- a/src/traits.c +++ b/src/traits.c @@ -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)) @@ -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); + } } } } diff --git a/test/compilable/test10992.d b/test/compilable/test10992.d new file mode 100644 index 000000000000..8462939ed796 --- /dev/null +++ b/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); +} diff --git a/test/compilable/test10992b.d b/test/compilable/test10992b.d new file mode 100644 index 000000000000..67c7d41d71c7 --- /dev/null +++ b/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); +}