dmd -unittest works poorly with executables

Steven Schveighoffer schveiguy at gmail.com
Sun Dec 9 20:56:53 UTC 2018


On 12/8/18 3:16 PM, Andrew Pennebaker wrote:
> I think it's lame to have to use magical code like `version(unittest) {} 
> else` to guard our main functions, when we run unit tests. Could D go 
> ahead and do the right thing, automatically shadowing our main functions 
> when the unit tests are run?

This is in process of deprecation, but I dropped the ball on making sure 
the deprecation happened in a timely manner (also I see the ddoc doesn't 
show the list very well...)

See this in the description of core.runtime.runModuleUnitTests: 
https://dlang.org/phobos/core_runtime.html#.runModuleUnitTests

"If the switch --DRT-testmode is passed to the executable, it can have 
one of 3 values:
1. "run-main": even if unit tests are run (and all pass), main is still 
run. This is currently the default.
2. "test-or-main": any unit tests present will cause the program to 
summarize the results and exit regardless of the result. This will be 
the default in 2.080.
3. "test-only", the runtime will always summarize and never run main, 
even if no tests are present."

Will do a PR to switch the default.

-Steve


More information about the Digitalmars-d-learn mailing list