toHash => pure, nothrow, const, @safe

Alex Rønne Petersen xtzgzorex at gmail.com
Mon Mar 12 11:41:39 PDT 2012


On 12-03-2012 19:04, H. S. Teoh wrote:
> On Mon, Mar 12, 2012 at 01:55:33PM -0400, Jonathan M Davis wrote:
> [...]
>> So, no, I don't think that @ctfe would really work. And while I agree
>> that the situation isn't exactly ideal, I don't really see a way
>> around it. Unit tests _do_ catch it for you though. The only thing
>> that they can't catch is whether the template is going to be pure,
>> nothrow, @safe, and/or CTFEable with _your_ arguments to it, but as
>> long as it's pure, nothrow, @safe, and/or CTFEable with _a_ set of
>> arguments, it will generally be the fault of the arguments when such a
>> function fails to be pure, nothrow, @safe, and/or CTFEable as
>> expected. If the unit tests don't hit all of the possible static
>> if-else blocks and all of the possible code paths for CTFE, it could
>> still be a problem, but that just means that the unit tests aren't
>> thorough enough, and more thorough unit tests will fix the problem, as
>> tedious as it may be to do that.
> [...]
>
> Tangential note: writing unit tests may be tedious, but D's inline
> unittest syntax has alleviated a large part of that tedium. So much so
> that I find myself writing as much code in unittests as real code.
> Which is a good thing, because in the past I'd always been too lazy to
> write any unittests at all.
>
>
> T
>

I stopped writing inline unit tests in larger code bases. If I do that, 
I have to maintain a separate build configuration just for test 
execution, which is not practical. Furthermore, I want to test my code 
in debug and release mode, which... goes against having a test 
configuration.

So, I've ended up moving all unit tests to a separate executable that 
links in all my libraries and runs their tests in debug/release mode. 
Works much better.

I don't feel that unittest in D was really thought through properly for 
large projects targeting actual end users...

-- 
- Alex


More information about the Digitalmars-d mailing list