Can we get unitests to not run with program start ?

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 25 22:32:51 PDT 2016


On Wednesday, October 26, 2016 05:24:45 deadalnix via Digitalmars-d wrote:
> Seriously that makes no sense, almost everybody has it own hack
> to have a different main when building for unitests, and we look
> like clown.
>
> We all like to talk about language feature and all, but
> seriously, this kind of thing is what hurts us the most. We kind
> of live with it because we all have our workaround here, but
> really, it looks stupid to anyone that don't the tricks, and
> really, it should looks silly to anyone that knows the trick.
>
> Can I have my unittest build do not complain if there is no main
> and not run main ?

Ideally, the -unittest build would just replace main (whatever it was) or
run something instead of main without actually starting main, and if there
were no main, it wouldn't complain about the lack thereof.

That being said, using -main when unit testing libraries and declaring main
in applications to look something like

version(unittest) void main() {}
else int main(string[] args) {...}

doesn't seem like all that big a deal to me. Not ideal, but not a big deal.

Regardless, I really don't think that it ever makes sense to actually run
main after running the unit tests. So, in that sense, what dmd does with
-unittest is downright weird. I assume that it just seemed like the easiest
way to integrate them though and that that's why it was done that way. And I
wouldn't mind it if it were fixed so that declaring main for unit tests was
not required and that main never actually ran after the unit tests. However,
I bet that if we changed it, _someone_ would complain. Someone always does,
even if the change makes perfect sense and the previous behavior didn't.

- Jonathan M Davis



More information about the Digitalmars-d mailing list