-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Support parsing only specific unittests (e.g. @betterc-test) #357
Conversation
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + tools#357" |
@ZombineDev or @JinShil - you seem to be two most interested in having |
|
||
@("foo") @betterc unittest | ||
{ | ||
assert(4 == 4); |
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.
Given that this has a @betterc
attribute, shoudn't the body be something like this?
version(D_BetterC)
{
assert(4 == 4);
}
else
{
assert(0);
}
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.
No. The idea here is just to selectively filter out unittests. Such rewrites would just complicate the job of this extraction tool and mess up the line matching.
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.
But I don't see the test proving that the extraction tool only extracts those test with the correct attribute, as all tests in this file succeed. Though, I also don't understand the purpose of the .ext file either.
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.
Ah, now I get it. Ok it's good!
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.
For the record: the .ext
files are the result of applying the extraction script on this file.
@@ -0,0 +1,44 @@ | |||
module attributes; | |||
|
|||
enum betterc; |
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 think the name should be betterC
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.
This is just a test to check whether the attribute filter works. It could be any attribute. See the -a betterc
line in posix.mak
I'm not yet convinced that this is the right approach, but I'm not convinced it's not either. For example, perhaps what we should be doing instead is running the unittests twice (once with -betterC and once without), and then segregating the betterC-supported code from the betterC-unsupported code with Also, I think this should be added to druntime first before adding it to Phobos. I have my doubts that much of anything in Phobos even works in betterC given how limiting it is. |
Also, I don't clearly understand what this PR is implementing. Are you saying that |
Well, we have been using this tests_extractor for almost two years now at Phobos, but we haven't managed to use it for druntime (see e.g. dlang/druntime#2087), so I think it's easier to start with Phobos.
I think that's because what you want for druntime is a bit different to what I want to have for Phobos ;-)
I agree, this probably won't scale well.
You would be suprised, but much of std.algorithm and std.range does work in
Yes, this a generic approach to it.
Yes, this just implements the extraction. The decision which attribute name it should be is somewhat arbitrary and I opened a NG thread for this: https://forum.dlang.org/post/irovmywdhafdromajrwc@forum.dlang.org |
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.
Other than version
ing code (which has its own problems), I can't think of a better way.
Gah! I'm not 100% on this yet. I need to give it more thought. Sorry!
BTW I thought a bit more about this and instead of performing dirty hacks in the Phobos Makefile, I think it's better if we directly transform the Of course, on the long run it would be great if dmd could do this out of the box, but for now I think the best place to do the AST rewrites is here in the transformer as we already have access to the AST and can just emit function declarations instead of I added this as another commit. |
I finally got around making the respective PR for Phobos: dlang/phobos#6645 I hope this helps to clear up the plans I have for this PR and how it's supposed to be integrated with Phobos and later-on Druntime. |
I'm most likely missing something, but the compiler already transforms unit test blocks to functions. |
Yep, but we miss See also: |
What about |
116545c
to
36ca53a
Compare
Okay, extern(C) void main()
{
static foreach(u; __traits(getUnitTests, __traits(parent, main)))
u();
} In theory this could also be added during the build process, but as this will be required often, I think the tests_extractor is a good place for this. |
Also as running unittests in |
"ignore", "Comma-separated list of files to exclude (partial matching is supported)", &ignoredFilesStr); | ||
"ignore", "Comma-separated list of files to exclude (partial matching is supported)", &ignoredFilesStr, | ||
"attributes|a", "Comma-separated list of UDAs that the unittest should have", &attributesStr, | ||
"betterC", "Add custom extern(C) main method for running D's unittests", &visitorConfig.betterCOutput, |
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.
Maybe it's better to rename this to --main
as it's now more analogous to the -main
switch of DMD?
So can we move forward with this? I would love to give this a try at Phobos. |
I'm still more in favor of There are also issues with -betterC's janky design and implementation. The fact that it imports everything at compile-time, but then pulls the rung out at link time causes issues, as features are available at CTFE that aren't available at runtime. And since there is no -betterC is fragmenting the D language, but it's necessary given the poor design decisions of the past. I hope in the long run -betterC just turns out to be a transition feature to a more scalable language. I'm also concerned about the shoehorning here, trying to make Phobos and betterC work together when both were designed without each other in mind. I really think we need to consider moving Phobos modules to DUB, and force it to compete in the broader ecosystem. Without "blessed" implementations, it opens the flood gates for competing implementations that can then take things like -betterC into consideration from the beginning. That is out of scope of what's being proposed here, but we need to keep the future in mind as we make decisions. I see the practicality of the solution in this PR, though I warn that when we get in the habit of using the more expedient option, we just create technical debt for the future. That being said, given the available options, I can't think of a more practical solution. Since I have a completely different vision for where we should be going, I will recuse myself from reviewing this PR. |
I think we have different directions in mind. I just want to prevent
Agreed.
It doesn't look like it at the moment, because we still haven't found good
We had such a discussion 1 1/2 years ago and we weren't able to convince Andrei that splitting up Phobos is a good idea. However, I agree that Phobos is in deep need of a "do-over".
I agree in general, but I don't think that adding a few
Yep, me neither. I'm not sure whether I have already mentioned this, but I did talk with Andrei about this last week very briefly and he's in favour of adding |
Yes, that's probably the core of the disagreement here. I think we should tell users to "use Phobos in -betterC at your own risk". The fact that some things work in -betterC seems more accidental than by design.
Thanks for that link; I'd forgotten all about it. It's probably going to take several motivated individuals working outside of the D Language Foundation to make it happen. I'm slowly working towards it, but I doubt I'll get there on my own.
Yeah, I know, but I do have a few ideas. Right now I'm just trying to get a few basic features of arrays working in -betterC, and it's not easy. |
BTW he's not the only one who wants to see So can we please move forward with this? Anyone around for a quick merge?
Well, the long-term plan is that we can say for certain functions (or even modules) that they will work in
I actually also want to see this happen and as I'm a bit involved with the DLF, I might be able to push from the inside a bit ;-)
Another idea is that |
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 agree with @JinShil on most points, but in this particular case, I believe that incremental progress towards making phobos functions more and more independent is very much worth pursuing.
Plus I really like how general is the attribute extraction - we can easily reuse it for other purposes, besides @betterc
.
The only thing that I would prefer is if we could find a clean way to define test runners externally not hard code them in the test_extractor itself, but this could improved in the future.
(I guess no point in waiting for Jenkins anymore ;) ) |
This adds support for parsing only a subset of specifically annotated unittests from Phobos.
A potential example:
The only downside of this approach is that we would have to define such a dummy symbol somewhere, so maybe the string approach is better:
Anyhow, this can be decided on the PR for Phobos as the attribute support is generic enough to support both use cases.