runAllTests() runs nothing because tests are stripped away

In our plugin we use Xcode’s DEAD_CODE_STRIPPING=YES option, partly because some library that we use requires that (otherwise we get linker errors), however when trying to also use UnitTestRunner::runAllTests, the flag causes the tests to be stripped away and consequently not run…

Does anyone else have this situation? Any good solutions to it?

My current work-around is to have UnitTest* t_myTest = &myTest; in the test module with a matching extern in my main module and using UnitTestRunner().runTests ({ t_myTest }); instead of runAllTests. But it’s not as nice as just runAllTests

How are you structuring your unit tests? Our CI runs the UnitTestRunner project in release builds with DEAD_CODE_STRIPPING=YES and the tests aren’t being stripped away.

How are you structuring your unit tests?

This is what I tried:

  • Add a .cpp file to my project and in it create a class which inherits from UnitTest with the runTest method and all, and declare one global object of this class.
  • In the standalone plugin use the JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP=1 option
  • In the custom app check the command line arguments, where the test argument triggers UnitTestRunner().runAllTests()

Adding externs so that the main references the symbols of the test objects did make the tests run.

Our CI runs the UnitTestRunner project in release builds with DEAD_CODE_STRIPPING=YES and the tests aren’t being stripped away.

Could you verify that if you add a false assertion in a test it does fail in your mac build?

Adding an assert (false); in any of the JUCE module unit tests gets caught in a release build on macOS, is this what you mean?

Yes this is what I meant.

I guess perhaps it acts different because it’s only one target and the tests aren’t in a shared code library like for plugins, where from what I see here do get stripped away.