dub
dub copied to clipboard
dub test with betterC
Bug Description
dub test doesn't work when betterC is in buildOptions
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.
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
I just stumbled on this.
Why is there even a custom test runner? Why is dub_test_root also compiled with -betterc?
I would also like dub test to work in betterC.
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.
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.
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.
seems like this is still an issue
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