-
-
Notifications
You must be signed in to change notification settings - Fork 747
Remove version(unittest) imports to avoid extra imports in user code. #6451
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
Conversation
|
Thanks for your pull request, @schveiguy! 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 + phobos#6451" |
| } | ||
| } | ||
|
|
||
| version(unittest) |
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.
Since in-function structs depend on the order defined, these have to be defined at module-level. Did not work if I put it inside the unittest itself.
But these structs are super-simple, and have no external dependencies.
| } | ||
| } | ||
|
|
||
| @system unittest |
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.
Not a fan of unittests being inside version(unittest), that's why the indentation changed.
| "\uFFFD","\uFFFD","\uFFFD","\uFFFD","\uFFFD","\uFFFD","\uFFFD","\uFFFD", | ||
| ]; | ||
|
|
||
| // HELPER FUNCTIONS |
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.
Note, these were copied as-is to this unittest. I'm not in love with the implementation, but wanted to keep the PR simple.
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 movaroo wasn't quite needed because it doesn't import anything. But fine by me.
|
ping @marler8997 |
|
Haven't reviewed in detail but changes look fine at the surface level. |
|
Since this decision is going to affect a fair amount of code in ALL of phobos. Would like to get an opinion from @andralex whether this is the direction we want to go in. From what I can see, what were'e doing is taking all the unittests that have shared code and merging them into one "super unittest". Then we move the shared code that use to be inside Besides the forward reference problem, the other problem I see is that this forces all the unittests using shared code to be in the same block. This may be less than ideal if a unittest is for a specific function and now it has to be moved away from the function it is testing. This also won't work if it is a "documentation" unittest. |
To clarify, this is only happening inside std.concurrency. And really, the "super unittest" consists of 2 very similar small adjacent unittests, which were trivial to put together.
This is regarding the structs in std.conv? No, those were already in a
The qualifier is that There is no requirement for all unittests to be in the same block, nor is that required really anywhere, even in the std.concurrency example. I could have potentially left those two functions out (and moved the imports inside them), but merging the only 2 unittests that utilize the functions seemed simpler, and not a drastic change. Just noticed, the std.concurrency unittest imports std.stdio, but doesn't actually use it. Will remove. |
008b557 to
6a324db
Compare
|
A further note: I would like to remove as many |
I'm just trying to summarize our strategy for this. Do we have other strategies for solving the "shared unittest code" problem, or are we planning on using this strategy throughout? I know that we may not know what's needed until more modules are looked at, but I want to make sure the strategy you've used here is what we want.
Right. I was just saying that you "would have put them" inside the unittest block (following the strategy I outlined) but couldn't in this case because of the forward reference issues, so you left them in the
Right, I'm just saying that if there is "shared code" between unittests, this seems to be the strategy you've chosen. Since the code inside the |
andralex
left a comment
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.
yah imports in version(unittest) are at least with the current semantics a latent source of bugs
| "\uFFFD","\uFFFD","\uFFFD","\uFFFD","\uFFFD","\uFFFD","\uFFFD","\uFFFD", | ||
| ]; | ||
|
|
||
| // HELPER FUNCTIONS |
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 movaroo wasn't quite needed because it doesn't import anything. But fine by me.
That sounds a bit extreme, unittest fixtures are a common idiom. Let's not take this too far, thanks. |
|
sry wrong button |
I plan on moving all code that I can inside unittests. A goal of mine is to eliminate as many instances of For example, if a There are other possibilities as we have discussed elsewhere -- i.e. making everything templates so they aren't actually semantic'd until used from a unittest.
I've looked at them all, and there are a few crappy cases. I'm saving them for last, these are the easy ones 😉 I'm fine with shared code in To that end, what may be the best solution is to put such shared items inside std.internal, and import those inside the unittests. But I don't know that we need to go that far (yet). This exercise is a basic cleanup of the easy things. |
|
Nice verb..."semantic'd" :) I think we need to treat What we currently use them for is to define shared code between unittests within a module. I expect there to be cases in phobos where there is alot of shared usage of a common set of code. We could use your strategy to create a "super unittest" to solve this problem but that does have some disadvantages (moving tests around/forward reference problems). I'm just trying to see if theres a better way to solve this, but I guess we'll see when we get to those problem modules. |
I like the idea. Just unittest/support in general (for current and other modules). |
|
IMO, if there is common code shared between unittests, said common code should be factored out into its own module (e.g.,
|
Yes this is another strategy that would work. Thanks for the idea. @schveiguy Maybe this is the solution we could use for the more "problemantic" modules? |
|
I'm curious if you could mention any problems you know of with |
|
Yep, I like the idea (see my comment, "what may be the best solution is to put such shared items inside std.internal" ), but it may be overkill for simple things. There may not be a hard set of rules we can come up with that fixes all situations, and I'm not sure we are ready to define it yet in any case. |
|
Using |
|
Thanks for the explanation @quickfur . That's basically what I figured. Though I hadn't thought of the confusing ddoc case. |
Another batch, see #6450 for details.