[swift-evolution] Solving the issue of unit-testing precondition with the Standard Library?

Dmitri Gribenko gribozavr at gmail.com
Sun Mar 13 18:14:06 CDT 2016

On Sun, Mar 13, 2016 at 3:32 PM, Brent Royal-Gordon via
swift-evolution <swift-evolution at swift.org> wrote:
> It might be possible to run whole tests, rather than individual assertions, by fork/exec-ing our harness

This is exactly what is being proposed.

> with a command-line flag indicating the test to run, but we would need a way to mark the tests which ought to be treated this way. (Or we could run every test in a sub-process, but that seems like it would introduce significant overhead.)

I think we should measure first and then make conclusions.  By the
way, I highly recommend everyone to take a look at StdlibUnittest,
where this approach is already implemented and works well for testing
preconditions in the standard library.  StdlibUnittest just keeps a
worker process running, asking it to run tests one by one until it
crashes, and then starts a new one.

> With the assistance of the compiler, we might be able to have precondition() and friends throw C++ exceptions in builds with testability enabled,

That would immediately lead to undefined behavior, not just leaks.  If
the code does not expect to continue, then the optimizer will make all
sorts of assumptions about that, and we don't want to inflict
debugging that mess onto our users.


(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/

More information about the swift-evolution mailing list