linkrope / dunit

xUnit Testing Framework for D
Boost Software License 1.0
37 stars 9 forks source link

Errors using mixin Main #30

Closed vladimmi closed 3 years ago

vladimmi commented 3 years ago

I have simple test with mixin Main; in the end like suggested:

module test;

import dunit.ng;

class Test {
    mixin UnitTest;

    @Test
    void assertSuccess() {
        assertEquals(1, 1);
    }

    @Test
    void assertFailure() {
        assertEquals(1, 2);
    }
}

mixin Main;

dub test fails with:

C:\Users\vladi\AppData\Local\Temp\dub_test_root_c931562a_8985_4af8_b4db_eada183d4cd7.d(12,12): Error: only one `main`, `WinMain`, or `DllMain` allowed. Previously found `main` at C:\Users\vladi\AppData\Local\dub\packages\d-unit-0.9.3\d-unit\src\dunit\framework.d(47,9)
C:\Users\vladi\AppData\Local\Temp\dub_test_root_c931562a_8985_4af8_b4db_eada183d4cd7.d(12,12): Warning: skipping definition of function `D main` due to previous definition for the same mangled name: _Dmain
C:\tools\ldc\bin\..\import\core\internal\entrypoint.d(29,17): Warning: skipping definition of function `dub_test_root._d_cmain!().wmain` due to previous definition for the same mangled name: wmain
ldc2 failed with exit code 1.
vladimmi commented 3 years ago

Same with dmd:

C:\Users\vladi\AppData\Local\dub\packages\d-unit-0.9.3\d-unit\src\dunit\framework.d(47,9): Error: only one `main`, `WinMain`, or `DllMain` allowed. Previously found `main` at C:\Users\vladi\AppData\Local\Temp\dub_test_root_60265411_8788_438b_aa30_8ddaaf0d5231.d(12,12)
dmd failed with exit code 1.
vladimmi commented 3 years ago

It seems the issue is in dub test which (I suspect) generates its own main() too. Custom configuration seems to fix it.

andre2007 commented 3 years ago

Exactly, see example here:

https://github.com/andre2007/coding-puzzles/blob/425a10e95848520cb95b033633213c40ad29b11e/dub.json#L16