Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dub test with betterC #1636

Closed
yshui opened this issue Jan 4, 2019 · 9 comments
Closed

dub test with betterC #1636

yshui opened this issue Jan 4, 2019 · 9 comments

Comments

@yshui
Copy link

yshui commented Jan 4, 2019

Bug Description

dub test doesn't work when betterC is in buildOptions

@wilzbach
Copy link
Member

wilzbach commented Jan 4, 2019

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.

@yshui
Copy link
Author

yshui commented Jan 4, 2019

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

@dkorpel
Copy link
Contributor

dkorpel commented Aug 1, 2019

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

@kayomn
Copy link

kayomn commented May 29, 2020

I would also like dub test to work in betterC.

@dbankov-vmware
Copy link
Contributor

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-vmware added a commit to dbankov-vmware/dub that referenced this issue Dec 2, 2020
This change modifies dub.d so to emit different code to execute
unittests if 'betterC' option is used. The difference is that the code
emitted for 'betterC' uses 'printf' instead of 'writeln'.

This change also includes a simple test which verifies that 'dub test'
works with 'betterC'.
dbankov-vmware added a commit to dbankov-vmware/dub that referenced this issue Dec 2, 2020
This change modifies dub.d so to emit different code to execute
unittests if 'betterC' option is used. The difference is that the code
emitted for 'betterC' uses 'printf' instead of 'writeln'.

This change also includes a simple test which verifies that 'dub test'
works with 'betterC'.
dbankov-vmware added a commit to dbankov-vmware/dub that referenced this issue Dec 2, 2020
This change modifies dub.d to emit different code to execute
unittests if 'betterC' option is used. The difference is that the code
emitted for 'betterC' uses 'printf' instead of 'writeln'.

This change also includes a simple test which verifies that 'dub test'
works with 'betterC'.
@dbankov-vmware
Copy link
Contributor

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.

@kayomn
Copy link

kayomn commented Dec 3, 2020

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.

@WebFreak001
Copy link
Member

seems like this is still an issue

@rikkimax
Copy link
Contributor

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.

string[] import_modules;

etcimon pushed a commit to etcimon/dub that referenced this issue Feb 8, 2023
WebFreak001 added a commit to etcimon/dub that referenced this issue Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants