-
-
Notifications
You must be signed in to change notification settings - Fork 671
Fix issue 16995 - __traits(getUnitTests) works with separate compilation #6727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3156,16 +3156,6 @@ extern (C++) final class InvariantDeclaration : FuncDeclaration | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /*********************************************************** | ||||||||||||||||||||||||||||
| * Generate unique unittest function Id so we can have multiple | ||||||||||||||||||||||||||||
| * instances per module. | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| private Identifier unitTestId(Loc loc) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| OutBuffer buf; | ||||||||||||||||||||||||||||
| buf.printf("__unittestL%u_", loc.linnum); | ||||||||||||||||||||||||||||
| return Identifier.generateId(buf.peekString()); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /*********************************************************** | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
|
|
@@ -3178,7 +3168,10 @@ extern (C++) final class UnitTestDeclaration : FuncDeclaration | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| extern (D) this(Loc loc, Loc endloc, StorageClass stc, char* codedoc) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| super(loc, endloc, unitTestId(loc), stc, null); | ||||||||||||||||||||||||||||
| // Id.empty can cause certain things to fail, so we create a | ||||||||||||||||||||||||||||
| // temporary one here that serves for most purposes with | ||||||||||||||||||||||||||||
| // createIdentifier. There is no scope to pass so we pass null. | ||||||||||||||||||||||||||||
| super(loc, endloc, createIdentifier(loc, null), stc, null); | ||||||||||||||||||||||||||||
| this.codedoc = codedoc; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -3189,6 +3182,35 @@ extern (C++) final class UnitTestDeclaration : FuncDeclaration | |||||||||||||||||||||||||||
| return FuncDeclaration.syntaxCopy(utd); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| Sets the "real" identifier, replacing the one created in the contructor. | ||||||||||||||||||||||||||||
| The reason for this is that the "real" identifier can only be generated | ||||||||||||||||||||||||||||
| properly in the semantic pass. See: | ||||||||||||||||||||||||||||
| https://issues.dlang.org/show_bug.cgi?id=16995 | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| final void setIdentifier() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| ident = createIdentifier(loc, _scope); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /*********************************************************** | ||||||||||||||||||||||||||||
| * Generate unique unittest function Id so we can have multiple | ||||||||||||||||||||||||||||
| * instances per module. | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
| private static Identifier createIdentifier(Loc loc, Scope* sc) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| OutBuffer buf; | ||||||||||||||||||||||||||||
| auto index = sc ? sc._module.unitTestCounter++ : 0; | ||||||||||||||||||||||||||||
| buf.printf("__unittest_%s_%u_%d", loc.filename, loc.linnum, index); | ||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a difference without a distinction between %u and %d - just use %u for both, or better yet %s for all (assuming they're all unsigned as they should).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wait I thought it's writef... |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // replace characters that demangle can't handle | ||||||||||||||||||||||||||||
| auto str = buf.peekString; | ||||||||||||||||||||||||||||
| for(int i = 0; str[i] != 0; ++i) | ||||||||||||||||||||||||||||
| if(str[i] == '/' || str[i] == '\\' || str[i] == '.') str[i] = '_'; | ||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More efficient as:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or even:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here's one of those places where
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oopsie-daisy!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is not strong enough and various testsuite tests fail if compiling to assembly (such as what gdc does). This logic should match what is done for Lines 3033 to 3045 in 32830de
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For instance, unittests compiled that are inside the directory |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return Identifier.idPool(buf.peekSlice()); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| override AggregateDeclaration isThis() | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| unittest {} unittest {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // EXTRA_SOURCES: imports/module_with_tests.d | ||
| // REQUIRED_ARGS: -unittest | ||
| // COMPILE_SEPARATELY | ||
|
|
||
|
|
||
| import imports.module_with_tests; | ||
|
|
||
| void main() { | ||
| import module_with_tests; | ||
| foreach(ut; __traits(getUnitTests, module_with_tests)) { | ||
| ut(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes me uneasy to start with one identifier, and finish with another. What fails with an empty identifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't like having to do it either, my first attempt was to use
Id.empty, but when I did that the unit tests failed. I can't remember which ones or why now, but they do.