Should unittests run as logical part of compilation?

Simen Kjærås simen.kjaras at gmail.com
Sun Jan 26 17:40:29 PST 2014


On 2014-01-25 23:06, Jakob Ovrum wrote:
> On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:
>> In particular, this view of unittests declares our current stance on
>> running unittests ("run unittests just before main()") as meaningless.
>> Indeed that has bothered me for quite a while - unittests are part of
>> the build/acceptance, not part of every run. To wit, this is a growing
>> idiom in D programs:
>>
>> version(unittest) void main() {}
>> else void main()
>> {
>>     ...
>> }
>
> This idiom is probably mostly obsolete now that we have the -main flag.
> An IDE can build with -unittest -main -run and exclude the source file
> that normally defines `main`.

Except that would exclude any unit tests in the module that defines main.

Of course, if you want to be evil, you could even write unit tests for main:

int main() {
     return 3;
} unittest {
     assert(main() == 3);
}

--
   Simen


More information about the Digitalmars-d mailing list