Bug 2630 – ddoc should be able to document unittests

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-01-28T11:19:00Z
Last change time
2013-02-13T06:23:30Z
Keywords
ddoc, pull
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2009-01-28T11:19:17Z
I have a hard time coming with examples for phobos' documentation and keeping them in sync with the library and its unittests. A great way to avoid all that and also motivate people to write both better documentation and better unittests would be to enable ddoc's outputting of select unittests. For example: /// This is function foo. It does nothing. void foo() {} /// The following example calls foo twice. unittest { foo(); foo(); } For the input above, ddoc should generate the regular ddoc fare for foo, and then print the content of the unittest code nicely formatted and highlighted, preceded by the header. Now both the unittest and the documentation are in place and the documentation example always compiles and runs!
Comment #1 by wbaxter — 2009-01-28T17:34:32Z
Sounds a lot like doctests that are becoming popular in Python. http://en.wikipedia.org/wiki/Doctest There the roles are reversed from what you are talking about. Some examples in the doc are made to run as unit tests, instead of making some unittests into doc. I think your version sounds simpler to get working in D, but the other way seems ultimately more useful to me. It allows you to interleave the examples with the documentation of the function more naturally.
Comment #2 by tomeksowi — 2010-10-13T11:44:48Z
Implementing ddoc'ed unittests entails that each unittest must have an owner (the preceding declaration) to put it in the right HTML tag. That would also solve the unittest name problem (bug 2749) with 'owner.stringof'.
Comment #3 by andrej.mitrovich — 2012-10-30T22:42:22Z
(In reply to comment #2) > Implementing ddoc'ed unittests entails that each unittest must have an owner > (the preceding declaration) to put it in the right HTML tag. That would also > solve the unittest name problem (bug 2749) with 'owner.stringof'. A simple workaround is to look for the next element in the members list to see if it's a unittest declaration. If it is, and it's commented and not private, we can insert a "----%s----" code block in the previous element. This would be done until a non-unittest block is found, or until a private/non-commented one is found. It's a ~20-line change to implement.
Comment #4 by andrej.mitrovich — 2012-12-01T13:32:56Z
(In reply to comment #3) > A simple workaround is to look for the next element in the members list to see > if it's a unittest declaration. If it is, and it's commented and not private, > we can insert a "----%s----" code block in the previous element. This would be > done until a non-unittest block is found, or until a private/non-commented one > is found. > > It's a ~20-line change to implement. That was a hacky solution, I have a better one coming soon.
Comment #5 by andrej.mitrovich — 2012-12-01T13:38:31Z
Comment #6 by github-bugzilla — 2013-02-07T13:15:39Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/78f2f612334326929d48b01dac68aef21a6f2d52 Fixes Issue 2630 - Support documenting unittest code as code samples. https://github.com/D-Programming-Language/dmd/commit/b94129918bfb929db2c0e2a8728c8ccfcd1d6590 Merge pull request #1342 from AndrejMitrovic/Fix2630 [enh] Issue 2630 - Support documenting unittest code as code samples.
Comment #7 by andrej.mitrovich — 2013-02-07T13:25:17Z
Fixed for D2.
Comment #8 by verylonglogin.reg — 2013-02-13T06:23:30Z
If it is "RESOLVED FIXED", it is a D2 issue.