convert docstring examples to unittests#4042
Conversation
e2a9a50 to
456c3e5
Compare
456c3e5 to
f2780f1
Compare
It does work on local machine & the autotester - that's exactly what I was looking for :)
I would go ahead once I get the okay from an official member - pinging randomly @andralex, @JackStouffer, @schveiguy, @burner |
Personally, I think that it would be a bit cleaner to put the unittest block after the imports, but I'm not sure that it matters much. As for turning ddoc examples into ddoc-ed unittest blocks. You really don't need permission for that. It's slowly been being done over time. It's just that it's most frequently happening either a PR happens to touch some code that didn't use a ddoc-ed unittest block. Just keep in mind that there are examples that won't work as ddoc-ed unit tests. std.net.curl is a great example of this because of the network stuff that it's doing, and a bunch of the examples in std.datetime shouldn't be converted either, because the functions in question are member functions on templated types, and it's problematic to put unittest blocks inside of templates. Also, in some rare cases, the documentation purposefully has an example in the middle of it, in which case, turning the example into a ddoc-ed unittest block would mess up the documentation. So, don't just automatically convert an example to a ddoc-ed unit test without thinking about it. I expect that that majority of examples that aren't ddoc-ed unittest blocks should be. So, there should be plenty for you to do on that front, but not every example should be converted. So, feel free to create some PRs which turn examples into ddoc-ed unittest blocks where appropriate, but please make sure that the PRs are of a manageable size - e.g. there's no need to try and fix every example in one PR. If you do it in smaller chunks, it'll be easier to review and verify the changes. |
f2780f1 to
a9c1eb9
Compare
a9c1eb9 to
d81030a
Compare
Understood - I regard this PR as completed now. As a side remark: I moved also the unittests for SList #4039, DList #4040 and RBTree #4041 to the top ;-) |
As a further incentive, PRs that affect less files are less likely to encounter merge conflicts. |
|
I even found a case where the docstring isn't displayed: See: http://dlang.org/phobos/std_experimental_allocator_building_blocks_stats_collector.html |
|
LGTM |
|
Auto-merge toggled on |
convert docstring examples to unittests
Inspired by #4039 I propose to go through all old modules and replace the examples in docstring with checked unittests.
The advantage is quite clear - it is possible to verify that the documentation is correct and up-to-date.
A quick regex yielded that there a 55 files affected:
I used this command - in case you want to reproduce it:
Questions
I would be happy to start with this task and go through the modules - maybe I can even automate it.
So there are only two questions
If there is a global module example (like in this PR for uuid), currently the best thing is to add the unittest below the class and add the magic
\\\. However this means that the example will be added to the class and not the module. How about using\\\\for module unittest examples?Compare http://dlang.org/phobos/std_uuid.html and the generated documentation for this PR.
How "okay" are you with this proposal?
It's a bit of work and it would feel like wasted time if this ends up non-merged.
I would split the PR in multiple parts, so that it's easier to review ;-)
PS/off-topic: Is anyone taking bets how many docstring examples don't work anymore?