Suggestion to avoid registering all the tests:

Added by first last about 3 years ago

I wrote a nice macro for self registering tests:

https://github.com/thigg/cute_improve/blob/master/src/Cute_Helper.hpp

I just wanted to share this with you. Would maybe nice to have this in the next version.

You can just use it via:


TEST(EXAMPLE,SIMPLETEST){
    ASSERT(true);
}

And launch somehwere:

runAllRegisteredTests(argc, argv);


Replies (1)

RE: Suggestion to avoid registering all the tests: - Added by Peter Sommerlad about 3 years ago

I created CUTE and the corresponding Eclipse plug-in to avoid such Macro trickery with static initializers.

They just don't work reliably across compilation units and with multi-threading.

Therefore, CUTE will never have such self-registration macros.

When C++ will have better reflection (it is in the standardization pipeline), I will try to get rid of all macros, so you can write assertions and report failure without relying on FILE and LINE.

And by the way, your code will not work, when included in several compilation units, i.e., a larger test project using several suites.

(1-1/1)