some of my code throws using
if (failure) throw std::runtime_error("a bad thing happened: ...");
I use Google Test and TeamCity to automatically run my tests. It works on Windows, so I use the -gtest_catch_exceptions option to report that the test was unsuccessful if an unexpected exception occurred. However, Google Test just fails when testing with a message like
Exception thrown with code 0xe06d7363 in the test body. in (null) line -1
which is not very useful. I would rather have a message like
Exception thrown: "a bad thing happened: ..."
I have a custom TestListener that implements a method
OnTestPartResult( const ::testing::TestPartResult& test_part_result)
but it looks like there is no reference to the exception that was detected in Google Test. Is there any other way to report an exception from std :: cout or somewhere else?
Please note that I cannot use
try { return RUN_ALL_TESTS(); } catch (std::exception& e) { std::cout << "EXCEPTION: " << e.what(); return -1; } catch (...) { return -1; }
without -gtest_catch_exceptions, because the test execution is then "canceled" in the first exception.
I would also not like to change the throwing code.
Thanks for any ideas!
source share