From c4c8843cae9ddfd45e5f6e0c3d0cca7a5d68eff3 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 1 Apr 2016 11:54:23 -0500 Subject: [PATCH] [#608] Don't use exit() on duplicate test descriptions Instead of `exit(1)`, it now throws `std::runtime_error` with the details of the failure. This exception is handled in `run()` at a higher level where the log is printed to cerr and the test gracefully exits. --- .../internal/catch_test_case_registry_impl.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/include/internal/catch_test_case_registry_impl.hpp b/include/internal/catch_test_case_registry_impl.hpp index acd619b4..6d0e4bbd 100644 --- a/include/internal/catch_test_case_registry_impl.hpp +++ b/include/internal/catch_test_case_registry_impl.hpp @@ -59,13 +59,15 @@ namespace Catch { it != itEnd; ++it ) { std::pair::const_iterator, bool> prev = seenFunctions.insert( *it ); - if( !prev.second ){ - Catch::cerr() - << Colour( Colour::Red ) - << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n" - << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" - << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl; - exit(1); + if( !prev.second ) { + std::ostringstream ss; + + ss << Colour( Colour::Red ) + << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n" + << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" + << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl; + + throw std::runtime_error(ss.str()); } } }