I have a test suite which includes several tests that take quite a
long time to complete. I would like these to be disabled by default,
but they should run if I specify a certain command line flag. They
would basically behave in exactly the same way as Google Test's
"disabled" test cases. Thus I *could* use the disabled test feature
already provided, but I don't want to because that would mean that I
would effectively lose the functionality of optionally disabling tests
(because every time I disable a broken test, then try to run the test
program with the --gtest_also_run_disabled_tests flag, I will have
to sit through the long tests too). I've adopted the policy of having
all these long tests include the string "LONG_TEST" in their names.
With that, the best solution I've come up with so far is the following
main() function:
---BEGIN CODE---
#include <gtest/gtest.h>
int main(int argc, char *argv[])
{
bool run_long_tests = false; // Read this from argv
if ( ! run_long_tests)
::testing::GTEST_FLAG(filter) = ":-:*LONG_TEST*";
::testing::InitGoogleTest(&argc, argv);
/*
if ( ! run_long_tests)
::testing::GTEST_FLAG(filter) += ":-:*LONG_TEST*";
*/
return RUN_ALL_TESTS();
}
---END CODE---
But that doesn't work if the user sets another filter on the command
line: the user's filter will overwrite the one I set. What I would
like to do is replace the 'if' statement above the call to
InitGoogleTest(...) with the one in the comment immediately after
it. That would solve all my problems, but unfortunately whatever
type ::testing::GTEST_FLAG(filter) is, it doesn't overload the +
and += operators so it seems I can't modify the flags after they're
read by InitGoogleTest(...).
Does anyone have any ideas on how I could get this to work?
Cheers,
Hamish.