[Issue 5091] main runs after unittests
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jan 7 17:14:39 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5091
Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrej.mitrovich at gmail.com
--- Comment #6 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-01-07 17:14:36 PST ---
You can override this behavior by defining your own unittest function:
import core.runtime;
import std.stdio;
import std.string;
import std.path;
bool testRunner()
{
foreach (m; ModuleInfo)
{
if (m is null)
continue;
if (auto fp = m.unitTest)
{
try
{
fp();
}
catch (Throwable e)
{
writeln(e);
}
}
}
// stop execution after tests are done
return false;
}
shared static this()
{
Runtime.moduleUnitTester(&testRunner);
}
unittest
{
writeln("in unittest");
assert(1);
}
void main()
{
writeln("not in main");
}
--------------
I've written a similar test system where I can also set these at runtime via
getopt switches:
- specify which modules to run the tests on (--testMods=foo.bar)
- ditto but set modules which should *not* have their tests ran on
(--ignoreMods=foo.bar.doo)
- specify whether to run the unittests, and whether to run main() if the tests
were successful
I might write a DWiki entry later on how to do this if there's any interest.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list