www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Awesome: asserts turn into writeln for ddoc'd unit tests

reply Steven Schveighoffer <schveiguy yahoo.com> writes:
This is something I didn't realize happened (I remember discussing it a 
while back). Awesome work whoever did it, and works great!

To recap, for anyone like me who is clueless, for documented unit tests:

///
unittest
{
    int x = 5;
    assert(x == 5);
}

turns into this in ddoc:

int x = 5;
writeln(x); // 5

Very cool :)

A question: is this for all libraries, or is it a special case for 
dlang.org?

-Steve
Sep 17
parent reply Seb <seb wilzba.ch> writes:
On Sunday, 17 September 2017 at 18:30:51 UTC, Steven 
Schveighoffer wrote:
 This is something I didn't realize happened (I remember 
 discussing it a while back). Awesome work whoever did it, and 
 works great!
Yeah we even had a short post about it: https://github.com/dlang/dlang.org/blob/master/assert_writeln_magic.d
 Very cool :)
Thanks!!
 A question: is this for all libraries, or is it a special case 
 for dlang.org?
It's done with libdparse and only for dlang.org. The code is actually really simple in case you are interested: https://github.com/dlang/dlang.org/blob/master/assert_writeln_magic.d
Sep 17
parent reply Jonathan Marler <johnnymarler gmail.com> writes:
On Sunday, 17 September 2017 at 21:36:51 UTC, Seb wrote:
 On Sunday, 17 September 2017 at 18:30:51 UTC, Steven 
 Schveighoffer wrote:
 This is something I didn't realize happened (I remember 
 discussing it a while back). Awesome work whoever did it, and 
 works great!
Yeah we even had a short post about it: https://github.com/dlang/dlang.org/blob/master/assert_writeln_magic.d
 Very cool :)
Thanks!!
 A question: is this for all libraries, or is it a special case 
 for dlang.org?
It's done with libdparse and only for dlang.org. The code is actually really simple in case you are interested: https://github.com/dlang/dlang.org/blob/master/assert_writeln_magic.d
I'm having a hard time seeing the benefits of this feature, could you share some examples or mention some reasons how this transformation is helpful? Not trying to attack the feature, just curious. Thanks.
Sep 17
parent Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Monday, 18 September 2017 at 02:40:00 UTC, Jonathan Marler 
wrote:
 I'm having a hard time seeing the benefits of this feature, 
 could you share some examples or mention some reasons how this 
 transformation is helpful? Not trying to attack the feature, 
 just curious. Thanks.
When running the unittests/examples on dlang.org, or when copying them and pasting in a text file and running them locally, the code will almost always execute with no output or other side effects. Generally, this isn't very useful or interesting when you're trying to learn about or experiment with the symbol being documented - it's more interesting to print the calculated results. The transformation converts the expected results (whatever the assert statement checks for equality) into a comment, so you can still see what the expected output was.
Sep 17