Skip to content

Make Phobos module examples runnable#5517

Merged
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:runnable-examples
Jul 10, 2017
Merged

Make Phobos module examples runnable#5517
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:runnable-examples

Conversation

@wilzbach
Copy link
Contributor

@wilzbach wilzbach commented Jun 27, 2017

With the new RUNNABLE_EXAMPLE Ddoc macro, in theory we just need to slap it around documented examples that can be run online.
Of course, the requires a valid main method, 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 new RUNNABLE_EXAMPLE Ddoc macro will happen in another PR.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jun 27, 2017

Thanks for your pull request, @wilzbach!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@wilzbach wilzbach added the Review:WIP Work In Progress - not ready for review or pulling label Jun 27, 2017
@wilzbach wilzbach force-pushed the runnable-examples branch 2 times, most recently from 0e055f3 to 9538559 Compare June 28, 2017 01:49
@wilzbach
Copy link
Contributor Author

wilzbach commented Jun 28, 2017

@meh DPaste seems really restrictive and it's time it gets overhauled or replaced:

  • std.concurrency -> segfaults (works fine with the DTour)
  • std.csv -> permission errors (works fine with the DTour)
  • std.zip -> permission errors (works fine with the DTour)

TODO

I removed all tricky bits from this PR.
Stage 2 should include at least this:

  • std.base64
  • std.demangle
  • std.getopt
  • std.regex (third example has assertion failures)
  • std.uni
  • std.zip
  • std.zlib

@wilzbach wilzbach removed the Review:WIP Work In Progress - not ready for review or pulling label Jun 28, 2017
@wilzbach wilzbach force-pushed the runnable-examples branch 2 times, most recently from 1284439 to b80ae0d Compare June 28, 2017 01:52
@wilzbach
Copy link
Contributor Author

@CyberShadow
Copy link
Member

Seems like currently it breaks the DDox module examples.

@PetarKirov
Copy link
Member

PetarKirov commented Jul 1, 2017

I would prefer making those examples into (possibly module-level) documented unittests, where possible.

@wilzbach
Copy link
Contributor Author

wilzbach commented Jul 1, 2017

I would prefer making those examples into (possibly module-level) documented unittests, where possible.

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 unittests. However, I think I managed to do this for a few modules and left the other ones for the future when I (or someone else) has time to look at the Ddox errors.

// Using writeln is very helpful for runnable unittest examples
version(unittest)
{
void writeln(T...)(T t){}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these four lines as tuple is nearly equally important as its big brother Tuple

@wilzbach wilzbach force-pushed the runnable-examples branch from dca2a7a to 9590194 Compare July 1, 2017 22:09
@wilzbach wilzbach force-pushed the runnable-examples branch from 9590194 to 10d0522 Compare July 2, 2017 01:03
@wilzbach wilzbach added Severity:Documentation Review:Trivial typos, formatting, comments labels Jul 6, 2017
@dlang-bot dlang-bot merged commit 681c743 into dlang:master Jul 10, 2017
@wilzbach wilzbach deleted the runnable-examples branch December 11, 2017 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants