dub icon indicating copy to clipboard operation
dub copied to clipboard

dub test with betterC

Open yshui opened this issue 6 years ago • 8 comments
trafficstars

Bug Description

dub test doesn't work when betterC is in buildOptions

yshui avatar Jan 04 '19 16:01 yshui

That's kind of expected as betterC doesn't allow to run unittests as they depend on druntime. Can't you do sth. like this:

configuration "default" {
	buildOptions "betterC"
}
configuration "unittest" {
}

This way unittest's won't be run with -betterC.

wilzbach avatar Jan 04 '19 16:01 wilzbach

unittests does work in betterC: https://dlang.org/spec/betterc.html#unittests

dub should be able to generate a different dub_test_root for betterC builds

yshui avatar Jan 04 '19 16:01 yshui

I just stumbled on this. Why is there even a custom test runner? Why is dub_test_root also compiled with -betterc?

dkorpel avatar Aug 01 '19 14:08 dkorpel

I would also like dub test to work in betterC.

kayomn avatar May 29 '20 20:05 kayomn

As far as I can tell one reason 'dub test' not to work with 'betterC' option is that some code which dub emits to execute the unit tests uses 'writeln' which seems to be unsupported in 'betterC'. I'll post a PR with a fix for this problem and we'll see how it goes.

dbankov-broadcom avatar Dec 02 '20 22:12 dbankov-broadcom

Just realised that fixing the 'writeln' issue won't resolve this problem because tests are executed in module's shared static constructor which will not be executed in betterC. I'll try to come up with a complete fix and will post it once I'm ready.

dbankov-broadcom avatar Dec 03 '20 00:12 dbankov-broadcom

Could generate a main that calls the unit tests using compile-time introspection

int main(string[] args) {
  foreach (unitTest; __traits(getUnitTests, thismodule)) {
     unitTest();
  }

  return remappedMain(args);
}

int remappedMain(string[] args) {
  // Dub test builder would treat the program's regular main as this when built using test mode.
}

The only difficulty I can see with this solution is collecting the names of every module that needs to be tested, as well as generating the entry point.

kayomn avatar Dec 03 '20 00:12 kayomn

seems like this is still an issue

WebFreak001 avatar Oct 13 '21 12:10 WebFreak001

The only difficulty I can see with this solution is collecting the names of every module that needs to be tested, as well as generating the entry point.

We already have this implemented in the generated test module: dub_test_root.

https://github.com/dlang/dub/blob/82d7a907d9822c2ed88993edba0120b439b43646/source/dub/project.d#L292

rikkimax avatar Dec 15 '22 17:12 rikkimax