void handleUnfinishedSections() {
     // If sections ended prematurely due to an exception we stored their
     // infos here so we can tear them down outside the unwind process.
     for( std::vector<SectionEndInfo>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
                 itEnd = m_unfinishedSections.rend();
             it != itEnd;
             ++it )
         sectionEnded( *it );
     m_unfinishedSections.clear();
 }
示例#2
0
 void RunContext::handleUnfinishedSections() {
     // If sections ended prematurely due to an exception we stored their
     // infos here so we can tear them down outside the unwind process.
     for (auto it = m_unfinishedSections.rbegin(),
          itEnd = m_unfinishedSections.rend();
          it != itEnd;
          ++it)
         sectionEnded(*it);
     m_unfinishedSections.clear();
 }
示例#3
0
        void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
            TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
            SectionInfo testCaseSection( testCaseInfo.name, testCaseInfo.description, testCaseInfo.lineInfo );
            m_reporter->sectionStarting( testCaseSection );
            Counts prevAssertions = m_totals.assertions;
            double duration = 0;
            try {
                m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
                TestCaseTracker::Guard guard( *m_testCaseTracker );

                Timer timer;
                timer.start();
                if( m_reporter->getPreferences().shouldRedirectStdOut ) {
                    StreamRedirect coutRedir( std::cout, redirectedCout );
                    StreamRedirect cerrRedir( std::cerr, redirectedCerr );
                    m_activeTestCase->invoke();
                }
                else {
                    m_activeTestCase->invoke();
                }
                duration = timer.getElapsedSeconds();
            }
            catch( TestFailureException& ) {
                // This just means the test was aborted due to failure
            }
            catch(...) {
                ResultBuilder exResult( m_lastAssertionInfo.macroName.c_str(),
                                        m_lastAssertionInfo.lineInfo,
                                        m_lastAssertionInfo.capturedExpression.c_str(),
                                        m_lastAssertionInfo.resultDisposition );
                exResult.useActiveException();
            }
            // If sections ended prematurely due to an exception we stored their
            // infos here so we can tear them down outside the unwind process.
            for( std::vector<UnfinishedSections>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
                        itEnd = m_unfinishedSections.rend();
                    it != itEnd;
                    ++it )
                sectionEnded( it->info, it->prevAssertions, it->durationInSeconds );
            m_unfinishedSections.clear();
            m_messages.clear();

            Counts assertions = m_totals.assertions - prevAssertions;
            bool missingAssertions = testForMissingAssertions( assertions );

            if( testCaseInfo.okToFail() ) {
                std::swap( assertions.failedButOk, assertions.failed );
                m_totals.assertions.failed -= assertions.failedButOk;
                m_totals.assertions.failedButOk += assertions.failedButOk;
            }

            SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions );
            m_reporter->sectionEnded( testCaseSectionStats );
        }