diff options
| author | Phil Nash | 2011-01-14 08:38:46 +0000 |
|---|---|---|
| committer | Phil Nash | 2011-01-14 08:38:46 +0000 |
| commit | f36d7773437830ff8178d0491166a29b62b156ea (patch) | |
| tree | fa5fb6f36ff9dc0c37f909fa3efd1565ce570866 /Test/TestMain.cpp | |
| parent | f063c2ae2aec4fcbef9d105ada97eb5f9eb7b21d (diff) | |
| download | catch3-f36d7773437830ff8178d0491166a29b62b156ea.tar.gz | |
Replaced dodgy self-test code with slightly less dodgy self test meta test cases
Diffstat (limited to 'Test/TestMain.cpp')
| -rw-r--r-- | Test/TestMain.cpp | 89 |
1 files changed, 41 insertions, 48 deletions
diff --git a/Test/TestMain.cpp b/Test/TestMain.cpp index 53782bca..7ca6ce6b 100644 --- a/Test/TestMain.cpp +++ b/Test/TestMain.cpp @@ -10,67 +10,60 @@ * */ -#include "../catch.hpp" -#include "../catch_runner.hpp" +#include "../internal/catch_self_test.hpp" +#include "../catch_default_main.hpp" -// This code runs the meta tests and verifies that the failing ones failed and the successful ones succeeded -int main (int argc, char * const argv[]) +TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results" ) { using namespace Catch; - bool showAllResults = false; - if( argc > 1 && ( std::string( argv[1] ) == "-s" || std::string( argv[1] ) == "--success" ) ) - showAllResults = true; - - std::ostringstream ossSucceeding; - std::ostringstream ossFailing; - - Config config; - config.setReporter( "Basic" ); - config.setIncludeWhat( Config::Include::SuccessfulResults ); - Runner runner( config ); - - config.setStreamBuf( ossSucceeding.rdbuf() ); - runner.runMatching( "succeeding/*" ); - std::string succeedingResults = ossSucceeding.str(); - - config.setStreamBuf( ossFailing.rdbuf() ); - runner.runMatching( "failing/*" ); - std::string failingResults = ossFailing.str(); - - int result = 0; - if( succeedingResults.find( "failed" ) != std::string::npos ) { - std::cerr << "Some tests that should have succeeded failed:\n\n" << succeedingResults; - result = 1; + EmbeddedRunner runner; + runner.runMatching( "succeeding/*" ); + CHECK( runner.getReporter().getSucceeded() == 53 ); + CHECK( runner.getReporter().getFailed() == 0 ); } - else if( showAllResults ) { - std::cout << succeedingResults << "\n\n"; - } - if( failingResults.find( "succeeded" ) != std::string::npos ) - { - std::cerr << "Some tests that should have failed succeeded:\n\n" << failingResults; - result = 1; + EmbeddedRunner runner; + runner.runMatching( "failing/*" ); + + CHECK( runner.getReporter().getSucceeded() == 0 ); + CHECK( runner.getReporter().getFailed() == 53 ); } - else if( showAllResults ) +} + +TEST_CASE( "selftest/succeeding", "Runs all Catch self tests that should succeed and checks their results" ) +{ + using namespace Catch; + + // Run a nested Runner - we scope it here so it restores our runner + // at the end of scope { - std::cout << failingResults << "\n\n"; + SelfTestConfig config; + { + Runner runner( config ); + runner.runMatching( "succeeding/*" ); + } + + CHECK( config.getReporter().getSucceeded() == 53 ); + CHECK( config.getReporter().getFailed() == 0 ); } +} - if( result == 0 ) +TEST_CASE( "selftest/failing", "Runs all Catch self tests that should fail and checks their results" ) +{ + using namespace Catch; + + // Run a nested Runner - we scope it here so it restores our runner + // at the end of scope { - const size_t expectedTestCaseCount = 106; // !TBD factor this out - size_t testCaseCount = runner.getSuccessCount() + runner.getFailureCount(); - std::cout << "All " << testCaseCount << " test(s) completed successfully" << std::endl; - if( testCaseCount != expectedTestCaseCount ) + SelfTestConfig config; { - std::cerr << "- but we were expecting " << expectedTestCaseCount - << " test to run. Were some added or removed, or were they not compiled in?" - << std::endl; - return 1; - } + Runner runner( config ); + runner.runMatching( "failing/*" ); + } + CHECK( config.getReporter().getSucceeded() == 0 ); + CHECK( config.getReporter().getFailed() == 53 ); } - return result; } |