virtual void registerTest( const TestCaseInfo& testInfo ) {
            if( testInfo.getName() == "" ) {
                std::ostringstream oss;
                oss << testInfo.getName() << "unnamed/" << ++m_unnamedCount;
                return registerTest( TestCaseInfo( testInfo, oss.str() ) );
            }

            if( m_functions.find( testInfo ) == m_functions.end() ) {
                m_functions.insert( testInfo );
                m_functionsInOrder.push_back( testInfo );
                if( !testInfo.isHidden() )
                    m_nonHiddenFunctions.push_back( testInfo );
            }
            else {
                const TestCaseInfo& prev = *m_functions.find( testInfo );
                std::cerr   << "error: TEST_CASE( \"" << testInfo.getName() << "\" ) already defined.\n"
                            << "\tFirst seen at " << SourceLineInfo( prev.getLineInfo() ) << "\n"
                            << "\tRedefined at " << SourceLineInfo( testInfo.getLineInfo() ) << std::endl;
                exit(1);
            }
        }
        virtual void registerTest( TestCase const& testCase ) {
            std::string name = testCase.getTestCaseInfo().name;
            if( name == "" ) {
                std::ostringstream oss;
                oss << "Anonymous test case " << ++m_unnamedCount;
                return registerTest( testCase.withName( oss.str() ) );
            }

            if( m_functions.find( testCase ) == m_functions.end() ) {
                m_functions.insert( testCase );
                m_functionsInOrder.push_back( testCase );
                if( !testCase.isHidden() )
                    m_nonHiddenFunctions.push_back( testCase );
            }
            else {
                TestCase const& prev = *m_functions.find( testCase );
                std::cerr   << "error: TEST_CASE( \"" << name << "\" ) already defined.\n"
                            << "\tFirst seen at " << SourceLineInfo( prev.getTestCaseInfo().lineInfo ) << "\n"
                            << "\tRedefined at " << SourceLineInfo( testCase.getTestCaseInfo().lineInfo ) << std::endl;
                exit(1);
            }
        }
Example #3
0
        virtual bool sectionStarted
        (
            const std::string& name, 
            const std::string& description,
            const std::string& filename,
            std::size_t line,
            std::size_t& successes,
            std::size_t& failures 
        )
        {
            std::ostringstream oss;
            oss << name << "@" << SourceLineInfo( filename, line );

            if( !m_runningTest->addSection( oss.str() ) )
                return false;

            m_currentResult.setFileAndLine( filename, line );
            m_reporter->StartSection( name, description );
            successes = m_successes;
            failures = m_failures;
            
            return true;
        }
Example #4
0
 virtual void Result( const ResultInfo& resultInfo ) {
     if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
         return;
     
     StartSpansLazily();
     
     if( !resultInfo.getFilename().empty() ) {
         TextColour colour( TextColour::FileName );
         m_config.stream() << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
     }
     
     if( resultInfo.hasExpression() ) {
         TextColour colour( TextColour::OriginalExpression );
         m_config.stream() << resultInfo.getExpression();
         if( resultInfo.ok() ) {
             TextColour successColour( TextColour::Success );
             m_config.stream() << " succeeded";
         }
         else {
             TextColour errorColour( TextColour::Error );
             m_config.stream() << " failed";
         }
     }
     switch( resultInfo.getResultType() ) {
         case ResultWas::ThrewException:
         {
             TextColour colour( TextColour::Error );
             if( resultInfo.hasExpression() )
                 m_config.stream() << " with unexpected";
             else
                 m_config.stream() << "Unexpected";
             m_config.stream() << " exception with message: '" << resultInfo.getMessage() << "'";
         }
             break;
         case ResultWas::DidntThrowException:
         {
             TextColour colour( TextColour::Error );
             if( resultInfo.hasExpression() )
                 m_config.stream() << " because no exception was thrown where one was expected";
             else
                 m_config.stream() << "No exception thrown where one was expected";
         }
             break;
         case ResultWas::Info:
             streamVariableLengthText( "info", resultInfo.getMessage() );
             break;
         case ResultWas::Warning:
             m_config.stream() << "warning:\n'" << resultInfo.getMessage() << "'";
             break;
         case ResultWas::ExplicitFailure:
         {
             TextColour colour( TextColour::Error );
             m_config.stream() << "failed with message: '" << resultInfo.getMessage() << "'";
         }
             break;
         case ResultWas::Unknown: // These cases are here to prevent compiler warnings
         case ResultWas::Ok:
         case ResultWas::FailureBit:
         case ResultWas::ExpressionFailed:
         case ResultWas::Exception:
         default:
             if( !resultInfo.hasExpression() ) {
                 if( resultInfo.ok() ) {
                     TextColour colour( TextColour::Success );
                     m_config.stream() << " succeeded";
                 }
                 else {
                     TextColour colour( TextColour::Error );
                     m_config.stream() << " failed";
                 }
             }
             break;
     }
     
     if( resultInfo.hasExpandedExpression() ) {
         m_config.stream() << " for: ";
         TextColour colour( TextColour::ReconstructedExpression );
         m_config.stream() << resultInfo.getExpandedExpression();
     }
     m_config.stream() << std::endl;        
 }