diff options
| author | Phil Nash | 2010-11-12 19:32:13 +0000 |
|---|---|---|
| committer | Phil Nash | 2010-11-12 19:32:13 +0000 |
| commit | d8aa843c7d5244b90761c52eb61dc3838df1b4f1 (patch) | |
| tree | cebd225a0d8bbf0a4b5bdfd92abef70663ace42c /Test/TestMain.cpp | |
| parent | 7e8cfa714f2fdf577497ed65f7c631523ed26cfa (diff) | |
| download | catch3-d8aa843c7d5244b90761c52eb61dc3838df1b4f1.tar.gz | |
Added Visual Studio project and fixed up some warnings showing in VS
Diffstat (limited to 'Test/TestMain.cpp')
| -rw-r--r-- | Test/TestMain.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Test/TestMain.cpp b/Test/TestMain.cpp new file mode 100644 index 00000000..98f85160 --- /dev/null +++ b/Test/TestMain.cpp @@ -0,0 +1,65 @@ +/* + * main.cpp + * Catch - Test + * + * Created by Phil on 22/10/2010. + * Copyright 2010 Two Blue Cubes Ltd + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ + +#include "../catch.hpp" +#include "../catch_runner.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[]) +{ + using namespace Catch; + + bool showAllResults = false; + if( argc > 1 && ( std::string( argv[1] ) == "-s" || std::string( argv[1] ) == "--success" ) ) + showAllResults = true; + + ReporterConfig reporterConfig( ReporterConfig::Include::SuccessfulResults ); + BasicReporter reporter (reporterConfig ); + Runner runner; + runner.setReporter( &reporter ); + + std::ostringstream ossSucceeding; + reporterConfig.setStreamBuf( ossSucceeding.rdbuf() ); + runner.runMatching( "succeeding/*" ); + std::string succeedingResults = ossSucceeding.str(); + + std::ostringstream ossFailing; + reporterConfig.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; + } + 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; + } + else if( showAllResults ) + { + std::cout << failingResults << "\n\n"; + } + + if( result == 0 ) + { + std::cout << "All " << runner.getSuccessCount() + runner.getFailureCount() << " tests completed successfully" << std::endl; + } + return result; +} |