On Thu, 14 Apr 2011 12:48:26 -0400, Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:

On 4/14/11 9:03 AM, Steven Schveighoffer wrote:
Sometimes, I worry that my unit tests or asserts aren't running. Every
once in a while, I have to change one to fail to make sure that code is
compiling (this is especially true when I'm doing version statements or
templates). It would be nice if there was a -assertprint mode which
showed asserts actually running (only for the module compiled with that
switch, of course).

Could this be achieved within the language?

I think you need to do it at the compiler level to make it useful. For example, an assert like:

assert(container.length == 5);

To print this out properly, I'd want to see that the assert passed, but also what the test was. I think there is already some work being commissioned (if not already in progress) on dissecting the expression into string form in the compiler.

I don't know how you would do this in a DRY fashion without compiler help. You can't use a mixin string because mixins are compiled in the context where you mix them in.

I outlined a possible solution in a response to Daniel that I believe:

1. allows one to 'see' an example working that just uses asserts
2. allows one to run specific unit tests to make sure they are working (via names)
3. does not require any changes to any asserts in existance.

I think this would be an awesome feature. One of the cool things about the new way phobos runs unit tests (one module at a time) is that if a particular test fails, I can just build/run it over and over again until it passes. This is huge since to run the full phobos unit tests can take a while.

To just be able to select on the command line how to run unit tests (I think overtaking the command line args for unittest-enabled code is reasonable) would be a great tool for debugging code via unittests and assert printouts.

It also gives us a smooth transition into using ddoc examples as unit tests.

-Steve

Reply via email to