RejectedSoftware Forums

Sign up

Dub and tested not creating results.json

Hello,

I just started using tested with dub and I've noticed that I don't see the "results.json" file being created when I do a "dub test". Is this the correct behavior because my expectation, from the documentation, is that it would automatically create this when I call "dub test" as well as execute the tests. Or am I missing something?

Re: Dub and tested not creating results.json

On Tue, 15 Apr 2014 18:24:30 GMT, Casey wrote:

Hello,

I just started using tested with dub and I've noticed that I don't see the "results.json" file being created when I do a "dub test". Is this the correct behavior because my expectation, from the documentation, is that it would automatically create this when I call "dub test" as well as execute the tests. Or am I missing something?

The default main file that DUB generates if "tested" is present looks like this:

import std.stdio;
import core.runtime;

void main() { writeln("All unit tests have been run successfully."); }
shared static this() {
	version (Have_tested) {
		import tested;
		import core.runtime;
		import std.exception;
		Runtime.moduleUnitTester = () => true;
		enforce(runUnitTests!allModules(new ConsoleTestResultWriter), "Unit tests failed.");
	}
}

So it runs the tests with a console result writer only. To generate the JSON file, a JsonTestResultWriter would have to be instantiated instead. To achieve that, you could either use dub test --main-file=../path/to/your/custom/main.d or by creating a "test" configuration in the project's dub.json that either specifies a different main file, or uses the same main file, but version (unittest) is used to replace the normal main function with the test runner.

Re: Dub and tested not creating results.json

O.K. The documentation confused me a bit. Thanks.

Re: Dub and tested not creating results.json

I'm still getting an issue where it tells me I can't have more than one main when I run "dub test". Can you tell me what I'm doing wrong? Here's the test main class that I created:

module test;

version (unittest)
{
    import tested;
    import std.exception;

    shared static this()
    {
        // disable built-in unit test runner
        import core.runtime;
        Runtime.moduleUnitTester = () => true;
    }

}

void main()
{
    version(unittest)
    {
        enforce(runUnitTests!test(new
                JsonTestResultWriter("results.json")), "Unit tests failed.");
    }
}

And here's my dub.json:

{
    "name": "test",
    "description": "A simple vibe.d server application.",
    "copyright": "Copyright © 2014, dev",
    "authors": ["dev"],
    "dependencies": {
        "vibe-d": ">=0.7.18",
        "tested": ">=0.9.3"
},
    "configurations": [
        {
            "name": "test",
            "mainSourceFile": "source/test.d"
        }
    ]
}

dub version 0.9.21.

Re: Dub and tested not creating results.json

Am 16.04.2014 15:46, schrieb Casey:

I'm still getting an issue where it tells me I can't have more than one main when I run "dub test". Can you tell me what I'm doing wrong? Here's the test main class that I created:

 module test;

 version (unittest)
 {
     import tested;
     import std.exception;

     shared static this()
     {
         // disable built-in unit test runner
         import core.runtime;
         Runtime.moduleUnitTester = () => true;
     }

 }

 void main()
 {
     version(unittest)
     {
         enforce(runUnitTests!test(new
                 JsonTestResultWriter("results.json")), "Unit tests failed.");
     }
 }

And here's my dub.json:

 {
     "name": "test",
     "description": "A simple vibe.d server application.",
     "copyright": "Copyright © 2014, dev",
     "authors": ["dev"],
     "dependencies": {
         "vibe-d": ">=0.7.18",
         "tested": ">=0.9.3"
},
     "configurations": [
         {
             "name": "test",
             "mainSourceFile": "source/test.d"
         }
     ]
 }

dub version 0.9.21.

Try inserting "excludedSourceFiles": ["source/app.d"] (or whichever
file matches your usual main module) into the "test" configuration - I
think it still picks up that one.

Re: Dub and tested not creating results.json

Try inserting "excludedSourceFiles": ["source/app.d"] (or whichever
file matches your usual main module) into the "test" configuration - I
think it still picks up that one.

Nope. Still having the issue. Even tried adding "versions": ["VibeCustomMain"] to try to prevent a main from being generated.

Re: Dub and tested not creating results.json

Am 16.04.2014 16:23, schrieb Casey:

Try inserting "excludedSourceFiles": ["source/app.d"] (or whichever
file matches your usual main module) into the "test" configuration - I
think it still picks up that one.

Nope. Still having the issue. Even tried adding "versions": ["VibeCustomMain"] to try to prevent a main from being generated.

Seems like something has broken this. I tried to reproduce it locally
and it definitely behaves strange. I'll prepare a fix in the next days.

Re: Dub and tested not creating results.json

On Thu, 17 Apr 2014 09:24:53 +0200, Sönke Ludwig wrote:

Am 16.04.2014 16:23, schrieb Casey:

Try inserting "excludedSourceFiles": ["source/app.d"] (or whichever
file matches your usual main module) into the "test" configuration - I
think it still picks up that one.

Nope. Still having the issue. Even tried adding "versions": ["VibeCustomMain"] to try to prevent a main from being generated.

Seems like something has broken this. I tried to reproduce it locally
and it definitely behaves strange. I'll prepare a fix in the next days.

Cool, thanks.