Make Phobos module examples runnable#5517
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. |
0e055f3 to
9538559
Compare
|
@meh DPaste seems really restrictive and it's time it gets overhauled or replaced:
TODOI removed all tricky bits from this PR.
|
1284439 to
b80ae0d
Compare
|
Examples of how this will look are on DAutoTest, e.g. http://dtest.dlang.io/artifact/website-d47df2c302b4a710bf285a86fc8e3417827dd7b8-0867404c3823f79c76cd98ee9f462b20/web/phobos-prerelease/std_csv.html |
|
Seems like currently it breaks the DDox module examples. |
|
I would prefer making those examples into (possibly module-level) documented unittests, where possible. |
b80ae0d to
c17218a
Compare
c17218a to
dca2a7a
Compare
Same here - as you might remember I have pushed for this in the past already: #4042, #4044, #4045, #4066, ... In these cases, the examples use stdout and create files, so it's a bit tricky to make to convert them to |
| // Using writeln is very helpful for runnable unittest examples | ||
| version(unittest) | ||
| { | ||
| void writeln(T...)(T t){} |
There was a problem hiding this comment.
I am not a huge fan of this workaround, but this allows us to use writeln in the unittest below and thus convert the documented example to a unittest without loosing out on features. Better ideas are, of course, welcome.
| // tuples can also be constructed on instantiation | ||
| assert(tuple(2, 3, 4)[1] == 3); | ||
| // construction on instantiation works with names too | ||
| assert(tuple!("x", "y", "z")(2, 3, 4).y == 3); |
There was a problem hiding this comment.
I added these four lines as tuple is nearly equally important as its big brother Tuple
dca2a7a to
9590194
Compare
9590194 to
10d0522
Compare
With the newRUNNABLE_EXAMPLEDdoc macro, in theory we just need to slap it around documented examples that can be run online.Of course, the requires a valid
mainmethod, imports etc. and examples without output are quite boring to the reader.This is a test to see whether more work is required or it "just works".edit: this now just converts documented examples into real
unittestss, testing the newRUNNABLE_EXAMPLEDdoc macro will happen in another PR.