简体   繁体   中英

Turning off unittest execution of third-party code

I'm trying to understand how the '-unittest' dmd switch can be used to select which files have their unittests executed.

I have a file, "ad", containing a unittest block. File "ad" imports from a third-party module (requiring the file "b1.d" and in turn "b2.d") which contain their own unittest blocks.

I don't want to run the tests in the third-party code: I just want to run the tests in ad

If I compile the third-party code first

dmd -c b1.d b2.d

then try to link it with my code with the unittests copied in

dmd -unittest a.d b1.o b2.o

then I get an error saying that the module in b1.d which ad is trying to import is in a file that cannot be read.

Can anyone show me how to accomplish this?

Thanks!

What you want to do is not possible because ad has imported b1.d and b2.d . It means that those modules must be passed to the compiler.

If you want to link some *.o files it's more complex: you have to write an interface (*.di file for them just like for a *.so ) thus it's not a good idea to use this mechanism to bypass the unittests. (although this could work it's a bit heavy).

A more straightforward way to arbitrary select some unittests is to use the trait getUnitTests . It's really more the way to go.

You are almost there. Just use separate compilation and linking steps, ie

dmd -c -unittest a.d

and then:

dmd a.o b1.o b2.o

That's it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM