Just-run-the-unittests

Sergei Nosov sergei.nosov at gmail.com
Sun Mar 16 01:41:41 PDT 2014


On Sunday, 16 March 2014 at 08:22:04 UTC, safety0ff wrote:
> On Sunday, 16 March 2014 at 07:59:33 UTC, Sergei Nosov wrote:
>> Hi!
>>
>> Suppose I have a small .d script that has a main. Is there any 
>> simple way to just run the unit tests without running main at 
>> all?
>
> Here's the first thing that came to mind:
> If you never want to both unit tests and regular main:
> ---- code begins ----
> import std.stdio;
> version(unittest) void main(){}
> else
> void main() { writeln("Hello world!"); }
>
> unittest { writeln("Hello unit testing world!"); }
> ---- code ends ----
>
> If you sometimes want to have your normal main with unit 
> testing you can replace "version(unittest)" with 
> "version(nopmain)" or some other custom version identifier and 
> compile with -version=nopmain when you want the dummy main.

Thx! That's better, but I think -main switch could be made to 
work like 'add or replace main by stub' instead of just 'add'. I 
don't think it'll hurt anybody, what do you think?


More information about the Digitalmars-d-learn mailing list