Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/Test/TestMain.cpp
blob: 1492fb7d3b4f2b1138d5090a04e1b9661f865ade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 *  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 )
    {
        const size_t expectedTestCaseCount = 99; // !TBD factor this out
        size_t testCaseCount = runner.getSuccessCount() + runner.getFailureCount();
        std::cout << "All " << testCaseCount << " tests completed successfully" << std::endl;
        if( testCaseCount != expectedTestCaseCount )
        {
            std::cerr   << "- but we were expecting " << expectedTestCaseCount
                        << " test to run. Where some added or removed, or were they not compiled in?" 
                        << std::endl;
            return 1;
        }        
        
    }
    return result;
}