On 20/10/2010 8:45 AM, Austin Hastings wrote:
Mixin templates may only contain declarations - not executable
statements. For this, you want a string mixin. There are some things you
could try.

1. I have some GPL code that does what you're trying to do, in a
different way.

Have a look at
http://github.com/aghast/Leda/blob/master/source/leda/test/unit.d . It
outputs TAP, instead of success/failure messages, but IMO that's a
better solution because there are plenty of TAP harnesses around.

2. You could have a look at "scope classes" in the docs:

http://www.digitalmars.com/d/2.0/class.html#auto (I know, "auto" makes
no sense, but it's in the html source..)

This indicates that a class is intended to be used RAII-style, such that
the destructor is called.

To use this, you'd probably have to catch Assertion failures, or put a
hook in the unit test failure handler (see the core.* doc pages in your
local install, since the net links aren't up on the dmd site).

3. You could use a string mixin.

In order to get the module name added, you could generate the string in
a function. I think there's a std* template that does compile-time
formatting, but naturally googling on the obvious keywords doesn't work.
So you'd so something like:

mixin( function_to_generate_the_scope_statements( MODULE_NAME ) );

at the top of your code.

(Note: mixing( "string" ) is different from mixin-templates, and *can*
have statements and expressions, not just declarations.)


Good luck,

=Austin

> 1. I have some GPL code that does what you're trying to do, in a
> different way.

Thanks Austin; you read my mind. :-)

Kind regards,
Justin

Reply via email to