-
-
Notifications
You must be signed in to change notification settings - Fork 420
Move core.time non-documentation unittests to tests/time #2316
Conversation
Thanks for your pull request, @n8sh! 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 + druntime#2316" |
6484dbf
to
4a2349e
Compare
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.
Why do you think that all of the unittest
blocks need to be moved out of core.time in order to have them not be compiled into the code of folks importing core.time? Moving the tests like this is a serious problem for maintainability, and it should be completely unnecessary. If there is a language-level problem that needs to be fixed here, then we need to fix that, not move all of the tests.
And that goes for druntime and Phobos in general. Putting the tests in a separate place from the code makes it much harder to maintain the tests and keep track of what's being tested. Being able to put the unit tests right after the functions is a key feature of unit tests in D. If we can't do that, we have a serious problem, and it needs to be fixed. AFAIK, outside of templates, the only problem with |
Please explain your concerns.
Aside from the reasons in my first comment, it makes the source code of |
c293f74
to
fef5c91
Compare
Tests like these that run in CI don't need to be repeated in every user's unittest builds.
fef5c91
to
50a1fd3
Compare
I would have though this was obvious and that I stated it clearly enough. The fact that As an example, the
I really don't think that the way that it's been has been a problem. It's the way that druntime and Phobos in general have been, and certainly for me personally, it's worked great. The tests interspersed with the code makes them easy to find, and my experience is that it makes the code far easier to maintain. And it should be trivial to skip past |
It should be trivial to switch back and forth between the implementation file and the unit test file as well in your editor (assuming a convention is followed). Having the unit tests separate works tremendously well in the Ruby world. I have never seen so many projects unit tested and so well covered as Ruby projects. |
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.
Unit tests in D should be near their tested item's implementation.
The stand-alone tests are needed only for cases when a unit test is not applicable for some or other reason.
I've dealt with both, and my experience is that it works far better to have the tests right next to the functions that they're testing. D makes that work really well, and it's what we've generally promoted. If we change it in druntime or Phobos now, we need a really good reason to do so. And if it's because of a problem with the language (e.g. |
I hadn't realized that. That removes nearly all of the reason for this PR. |
Oh, I had misunderstood the PR description.
I thought "user" here means "Phobos contributor" (as in, they should run the Phobos tests on their machine but not the |
We really should look into making it so that The last remaining issue that I'm aware of is when you need a I've been considering writing a DIP on treating |
We might not even want to "fix" this, since if the test actually varies based on the template parameters we want it to run. phobos/6693 has an example of a templated unittest that could catch a real error: @system unittest
{
assert(typeof(this).init.isNull, typeof(this).stringof ~
".isNull does not work correctly because " ~ T.stringof ~
" has an == operator that is non-reflexive and could not be" ~
" determined before runtime to be non-reflexive!");
} |
Really, the ideal solution is having the choice. Sometimes, a test is generic enough that it works to have it compiled in with every instantiation, and you get better test coverage that way, since it ensures that it works correctly (at least with regards to that test) for every type that it's instantiated with. However, most tests can't be generic like that, and so for most tests, it just means that you have exactly the problem that you were worried about for this PR - only worse. The tests end up in the user's code once for every instantiation they use (not just once for having imported the module) - and get run with their unit tests. So, ideally, there would be a way to indicate whether a test was supposed to be instantiated with the template or whether it was just inside the template for convenience (be it for ease of maintenance or so that it can be a ddoc-ed I wrote a DIP for the old DIP process that suggested that if we marked |
Let me interject some things I learned when I was doing some experimentation for a DMD PR that was supposed to remove unittests when those tests were instantiated inside imported modules (that PR was later abandoned, but I wish we had worked through the issues).
The second point means that extra imports get added (ones inside locally instantiated templates), and those extra imports cause more templates to be instantiated, and included, etc. In addition, any unittests inside of those templates are instantiated locally, as if they were written in the importing module (which is really dumb in a way -- you likely are running the same unittests inside every importing module). But module-level unittests are not the problem there, even templates instantiated inside an imported unittest are not semantic'd, so the instantiation doesn't happen, even with the IMO, we should not concentrate at all on removing unittests from modules. We should concentrate on fixing the limitations of DMD that caused the |
Tests like these that run in CI don't need to be repeated in every user's unittest builds. This can be done for other tests too. I am dividing the work among several PRs to make the review easier.