www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17403] New: -main switch doesn't run correctly in unittest

https://issues.dlang.org/show_bug.cgi?id=17403

          Issue ID: 17403
           Summary: -main switch doesn't run correctly in unittest builds
                    when linking separately
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: atila.neves gmail.com

foo.d:

unittest { assert(false); }

$ dmd -main -unittest foo.d
$ ./foo
core.exception.AssertError foo.d(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
core.exception.AssertError foo.d(1): unittest failure

--
May 16