mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-04 05:59:32 +01:00 
			
		
		
		
	[#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.
This commit is contained in:
		@@ -60,13 +60,15 @@ namespace Catch {
 | 
				
			|||||||
            it != itEnd;
 | 
					            it != itEnd;
 | 
				
			||||||
            ++it ) {
 | 
					            ++it ) {
 | 
				
			||||||
            std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
 | 
					            std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
 | 
				
			||||||
            if( !prev.second ){
 | 
					            if( !prev.second ) {
 | 
				
			||||||
                Catch::cerr()
 | 
					                std::ostringstream ss;
 | 
				
			||||||
                << Colour( Colour::Red )
 | 
					
 | 
				
			||||||
 | 
					                ss  << Colour( Colour::Red )
 | 
				
			||||||
                    << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n"
 | 
					                    << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n"
 | 
				
			||||||
                    << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n"
 | 
					                    << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n"
 | 
				
			||||||
                    << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl;
 | 
					                    << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl;
 | 
				
			||||||
                exit(1);
 | 
					
 | 
				
			||||||
 | 
					                throw std::runtime_error(ss.str());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user