Review: A new stab at a potential std.unittests

Jonathan M Davis jmdavisProg at gmx.com
Sat Nov 20 17:34:00 PST 2010


On Saturday 20 November 2010 16:23:32 Jonathan M Davis wrote:
> The lazy solution sounds pretty good actually. Can anyone think of any real
> downsides to that? So, it would look something like
> 
> assertExcThrown(E : Throwable, T)(lazy T, string file = __FILE__, size_t
> line = __LINE__);

Wait. No. I didn't think that one through enough. It doesn't work. You You don't 
actually get a delegate out of lazy, and what you need for assertExcThrown!() is 
a delegate. It would be great to be able to implicitly create a delegate like 
that, but lazy does it underneath the hood, so to speak, and when the function 
call is made, you still get the result of the function call, and by that point, 
it's too late, since to get the result of the function call, you obviously need 
to have called it. So, the question remains whether it would be better to pass a 
string which gets mixed in or a delegate which gets called.

I think that the delegate solution is uglier to use, but that's debatable. It's 
less efficient at runtime, but it would be faster to compile and would result in 
less code bloat (though how much code bloat matters for unit tests is debatable, 
since they shouldn't end up in released binaries). I'm really not sure which is 
better. I like the mixin solution, but the delegate solution has its advantages 
as well.

Anyone else have an opinion on whether (and why) the string mixin approach or 
the delegate approach is better?

- Jonathan M Davis


More information about the Digitalmars-d mailing list