On 10/17/2014 9:10 AM, Jacob Carlborg wrote:
On 2014-10-17 10:26, Atila Neves wrote:

Is cleaning up in a unittest build a problem? I'd say no, if it the
tests fail it doesn't make much sense to clean up unless it affects the
reporting of tests failing.

I have used files in some of my unit tests. I would certainly like those to be
properly closed if a tests failed (for whatever reason). Now, some of you will
argue that one shouldn't use files in unit tests. But that would only work in a
ideal and perfect world, which we don't live in.

This should be fairly straightforward to deal with:

1. Write functions to input/output from/to ranges instead of files. Then, have the unittests "mock up" input to drive them that does not come from files. I've used this technique very successfully in Warp.

2. If (1) cannot be done, then write the unittests like:

  {
    openfile();
    scope (exit) closefile();
    scope (failure) assert(0);
    ... use enforce() instead of assert() ...
  }

3. In a script that compiles/runs the unittests, have the script delete any extraneous generated files.

Reply via email to