On 28/11/13 17:40, Dicebot wrote:
I have quickly tested it and looks like asserts are not removed from unittest
blocks in release builds, only from normal code. Which does not seem to be
documented on dlang.org but was probably introduced exactly to prevent existing
tests from breaking in release mode. I have just learned something new :)

Both version(assert) and version(release) are ignored inside unittest blocks. Consider the attached code: running with rdmd -unittest -release results in output:

    I don't respect release mode inside unittest blocks
    Release mode is disabled.

Which is interesting but irritating to say the least, because it means things like testing contracts are more difficult to unittest effectively.

OK, OK, I could do

    version(assert)
    {
        unittest { ... }
    }

... but that makes for an annoying separation out of unittests.
import std.stdio;

void main()
{
    version(release)
    {
        writeln("Release mode is enabled.");
    }
    else
    {
        writeln("Release mode is disabled.");
    }
}

unittest
{

    version(release)
    {
    }
    else
    {
        writeln("I don't respect release mode inside unittest blocks");
    }
}

Reply via email to