Can we get unitests to not run with program start ?

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 17 23:51:35 PST 2016


On Wednesday, 26 October 2016 at 21:57:59 UTC, Basile B. wrote:
> It looks fairly simple to do in dmd, like this (with breakage 
> in case the user-defined main() did something useful):
>
> 1. deactivate the main functionDeclaration un funcs.d
>
> ....
> final bool isMain()
> {
>    return ident == Id.main && linkage != LINKc && !isMember() 
> && !isNested()
>     && !global.params.useUnitTests;
> }
> ...
>
> 2. forces -main in params.d:
>
> ...
> else if (strcmp(p + 1, "unittest") == 0)
> {
>     global.params.useUnitTests = true;
>     global.params.addMain = true;
> }
> ...
>
> I see no reason to discuss much about this. People that are pro 
> should just agree on how this should be done and someone makes 
> a PR.
>
> Maybe the little issue would be with LDMD2 and GDMD. Since 
> these programs are just bridges they cannot do point 1, and 
> LDC2 and GDC would have to follow this behavior.

I tried that and it doesn't work. addMain actualy just inject a 
main function as a mixin in the module. Yes this is a string, it 
is parsed and all.

The problem is that this function that is injected is then not 
wired in as main, because isMain returns false.

Any tips appreciated.


More information about the Digitalmars-d mailing list