Why can't we put import in functions.

Henning Hasemann hhasemann at web.de
Tue Oct 16 08:46:03 PDT 2007


I came to (nearly) entirely drop unittests and instead make "module
tests" where I compile each module into a binary and run it.

It goes like this:

module foo;
import bar;

// Class defitions etc...

version(module_test_foo) {
  import test_dep;
  void main() {
    // test code
  }
}

I know it isnt particular prettier either, especially as you have to be
careful about reusing your object files and have a lot of extra
compiling to do for the tests. But on the other hand the modules
included can "see" which module is beeing tested and file some special
cases for it to test or whatever.

I also use an additional -version=module_test which in some places is
needed (in my code) to skip some initialization functions that
otherwisely might "bite" with the main.

Also note that this is for library code where there would be no main()
at all, so it wouldnt be testable without having an extra main.

Henning

-- 
GPG Public Key:
http://gpg-keyserver.de/pks/lookup?op=get&search=0xDDD6D36D41911851



More information about the Digitalmars-d mailing list