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.

Reply via email to