From 3dbd06ae89b33022e362a35de74d34c76f998e86 Mon Sep 17 00:00:00 2001 From: Andrej Mitrovic Date: Mon, 9 Sep 2013 22:36:58 +0200 Subject: [PATCH 1/2] Rename "unittest" to "ddocUnittest" since it should only be used with ddoc. --- src/doc.c | 10 +++++----- src/dsymbol.c | 4 ++-- src/dsymbol.h | 2 +- src/parse.c | 2 +- src/traits.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/doc.c b/src/doc.c index 590c53ee6dac..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"); } @@ -1524,7 +1524,7 @@ void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf) { arg->type->toCBuffer(buf, arg->ident, &hgs); } - else + else { if (isTemplateParameter(s, namestart, namelen)) { 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 5b70580d5b00..98de00a7d59e 100644 --- a/src/dsymbol.h +++ b/src/dsymbol.h @@ -127,7 +127,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 3ac8450d11ba..4608f4cc178a 100644 --- a/src/parse.c +++ b/src/parse.c @@ -274,7 +274,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 fe99581d44ce..32ddc6f4c9d4 100644 --- a/src/traits.c +++ b/src/traits.c @@ -96,7 +96,7 @@ static void collectUnitTests (Dsymbols *symbols, AA *uniqueUnitTests, Expression for (size_t i = 0; i < symbols->dim; i++) { Dsymbol *symbol = (*symbols)[i]; - UnitTestDeclaration *unitTest = symbol->unittest ? symbol->unittest : symbol->isUnitTestDeclaration(); + UnitTestDeclaration *unitTest = symbol->ddocUnittest ? symbol->ddocUnittest : symbol->isUnitTestDeclaration(); if (unitTest) { @@ -762,7 +762,7 @@ Expression *TraitsExp::semantic(Scope *sc) { FuncDeclaration *f; ISDSYMBOL((f = s->isFuncDeclaration()) != NULL && f->isOverride()) - } + } else if(ident == Id::getVirtualIndex) { if (dim != 1) From 331b5b0cb33433cbba391dd418ae36e8b454c4e6 Mon Sep 17 00:00:00 2001 From: Andrej Mitrovic Date: Mon, 9 Sep 2013 22:41:26 +0200 Subject: [PATCH 2/2] Fixes Issue 10992 - Missing unittests when using getUnittests trait. --- src/traits.c | 11 ++++++----- test/compilable/test10992.d | 11 +++++++++++ test/compilable/test10992b.d | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 test/compilable/test10992.d create mode 100644 test/compilable/test10992b.d diff --git a/src/traits.c b/src/traits.c index 32ddc6f4c9d4..9ea627b5af7e 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->ddocUnittest ? symbol->ddocUnittest : 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); +}