Bug 17403 – -main switch doesn't run correctly in unittest builds when linking separately

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-05-16T17:43:00Z
Last change time
2017-05-17T04:02:02Z
Assigned to
nobody
Creator
atila.neves

Comments

Comment #0 by atila.neves — 2017-05-16T17:43:42Z
foo.d: unittest { assert(false); } $ dmd -main -unittest foo.d $ ./foo [email protected](1): unittest failure # fails as expected $ dmd -offoo.o -c -main -unittest foo.d $ dmd foo.o $ ./foo # no error $ If I change foo.d to include a main function manually: unittest { assert(false); } void main() { import core.runtime: Runtime; Runtime.moduleUnitTester; } Then the 2nd example above fails as expected. $ dmd -offoo.o -c -unittest foo.d $ dmd foo.o $ ./foo [email protected](1): unittest failure
Comment #1 by dlang-bugzilla — 2017-05-16T22:51:05Z
I think the invocation is incorrect - you need to specify -main when linking, not compiling: $ dmd -c -unittest foo.d $ dmd -main foo.o $ ./foo [email protected](1): unittest failure
Comment #2 by atila.neves — 2017-05-17T04:01:45Z
That's... not what I expected. Thanks for the clarification.