linkrope / dunit

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

Issues to get dunit running within a dub project #11

Closed andre2007 closed 6 years ago

andre2007 commented 6 years ago

I created a dub project using "dub init dtest2" and specified the dependency to "d-unit".

dub.json looks like this:

{
    "name": "dtest2",
    "dependencies": {
        "d-unit": "~>0.8.1"
    }
}

It is quite hard for a beginner maybe much to hard to get the unittest running using command "dub test".

I have a app.d file with this content:

version (unittest)
{
    import dunit;
    mixin Main;
}
else
{
    void main()
    {
        import std.stdio;
        writeln("Edit source/app.d to start your project.");
    }
}

and a test1.d file with this content:

import dunit;
class Test
{
    mixin UnitTest;
    @Test void myTest() { assertEquals("foo", "bar"); }
}

The result of running "dub test" is: All unit tests have been run successfully. By removing the "mixin Main" in app.d and adding it to test1.d

// app.d
version (unittest){}
else
{
    void main()
    {
        import std.stdio;
        writeln("Edit source/app.d to start your project.");
    }
}
// test1.d
import dunit;

version (unittest)
{
    import dunit;
    mixin Main;
}

class Test
{
    mixin UnitTest;

    @Test
    void myTest() { assertEquals("foo", "bar"); }
}

there is now an error returned while running dub test:

....\AppData\Roaming\dub\packages\d-unit-0.8.1\d-unit\src\dunit\framework.d(47,9): Error: only one main/WinMain/DllMain allowed. Previously found main at ....\AppData\Local\Temp\dub_test_root-68e76de3-85a8-4cc2-baba-ce3d55b37483.d(9,12) dmd failed with exit code 1.

My gut feeling is, dub is causing this issue because the application is detected as "library" anf therefore a default test runner is generated...

Maybe you can add a dub example which shows the correct way or you can enhance the readme. For an unexperienced developer there is a high level of frustration until d-unit is working correctly within dub. (To get it working I had to add a debug and unittest configuration with specifying targetType and setting the mainSourceFile..., but I am not sure whether this is the correct way or it is a workaround for a dub bug)