RejectedSoftware Forums

Sign up

vibe.d project and testing

I am working on a vibe.d project, and I was adding some unittests.

I'm allowing vibe.d to define its own main function for the project.

When running dub test, I get the error: only one main allowed
dmd failed with exit code 1.

How do I fix dub test so it doesn't create its own main function? Shouldn't this be the default config for vibe.d programs?

Re: vibe.d project and testing

On Thu, 14 Jul 2016 21:45:03 GMT, Steven Schveighoffer wrote:

I am working on a vibe.d project, and I was adding some unittests.

I'm allowing vibe.d to define its own main function for the project.

When running dub test, I get the error: only one main allowed
dmd failed with exit code 1.

How do I fix dub test so it doesn't create its own main function? Shouldn't this be the default config for vibe.d programs?

I have the same issue. The workaround is to move versions "VibeDefaultMain" to an application configuration:

configuration "application" {
  targetType "executable"
  versions "VibeDefaultMain"
}

For more information see this discussion: https://github.com/rejectedsoftware/vibe.d/pull/1417

Re: vibe.d project and testing

On Fri, 15 Jul 2016 09:27:11 GMT, Jacob Carlborg wrote:

I have the same issue. The workaround is to move versions "VibeDefaultMain" to an application configuration:

configuration "application" {
  targetType "executable"
  versions "VibeDefaultMain"
}

OK, that kind of worked. But now it says there is an error because I didn't define mainSourceFile. It seems to run the tests now at least.

Thanks.

-Steve

Re: vibe.d project and testing

On Wed, 20 Jul 2016 23:35:14 GMT, Steven Schveighoffer wrote:

OK, that kind of worked. But now it says there is an error because I didn't define mainSourceFile. It seems to run the tests now at least.

Yeah, I noticed that as well. Not sure if that was present before Dub 1.0.0.

There's some strange things going on here. If I remove targetType "executable" I get back the error with a duplicated main function. But if I look at how Dub actually compiles the code, in both cases (with and without targetType) it will compile vibe-d/source/vibe/appmain.d with the version VibeDefaultMain specified.

Looking a bit more closely on the command Dub is executing, if targetType "executable" is specified it will not generate the standard main function it usually does for unit tests. Instead the vibe.d default main function will be used. When I run the unit tests, after they finished, I see that the vibe.d application is started just before the application exits:

Listening for requests on http://0.0.0.0:3000/
Please open http://0.0.0.0:3000/ in your browser.

@Sönke, this behavior is not good.

/Jacob Carlborg

Re: vibe.d project and testing

On Thu, 14 Jul 2016 21:45:03 GMT, Steven Schveighoffer wrote:

I am working on a vibe.d project, and I was adding some unittests.

I'm allowing vibe.d to define its own main function for the project.

When running dub test, I get the error: only one main allowed
dmd failed with exit code 1.

How do I fix dub test so it doesn't create its own main function? Shouldn't this be the default config for vibe.d programs?

I had the same problem but in combination with unit-threaded. With some combination of suggested config I can get it to run, but then unit-threaded's runner freezes.

I decided to ditch unit-threaded in the project, and rely on plain unittests. Sadly, now dub decides to run the program after unittests are complete.

This is unworkable.

What is vibe.d doing that causes all these problems?

I reckon unit-threaded's approach of running the unittests in separate threads goes against vibe.d. But surely, it must be possible.