nomad-software / dunit

Advanced unit testing toolkit for the D programming language
MIT License
62 stars 20 forks source link

dunit.toolkit.assert* functions not @nogc #15

Open PetarKirov opened 8 years ago

PetarKirov commented 8 years ago

I'm writing a library which needs to have @safe @nogc pure nothrow API. To ensure this, I annotate my unittests with those attributes, however this currently means that I can't use dunit.toolkit in those unittests.

PetarKirov commented 8 years ago

One possible way to do this may be to pre-allocate an array of records for each unittest. Inside the assert* functions the code will then fill the corresponding record for the current unittest. After the test runner finishes it will iterate through the elements of the array and perform string formating as needed.

A different strategy is to use ref-counted objects, but that seems even more involved for the scope of this project, considering that currently phobos provides little support for this style of memory management.

A third option is to use fibers or ranges to separate the code that needs to allocate memory from code that just checks the assert* functions parameters.

PetarKirov commented 8 years ago

To clarify about my idea to use fibers - instead of throwing DUnitAssertError, you can fiber.yield() directly to the code that is supposed to catch the exception