Totals runTest( TestCase const& testCase ) { Totals prevTotals = m_totals; std::string redirectedCout; std::string redirectedCerr; TestCaseInfo testInfo = testCase.getTestCaseInfo(); m_reporter->testCaseStarting( testInfo ); m_activeTestCase = &testCase; m_testCaseTracker = TestCaseTracker( testInfo.name ); do { do { runCurrentTest( redirectedCout, redirectedCerr ); } while( !m_testCaseTracker->isCompleted() && !aborting() ); } while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() ); Totals deltaTotals = m_totals.delta( prevTotals ); m_totals.testCases += deltaTotals.testCases; m_reporter->testCaseEnded( TestCaseStats( testInfo, deltaTotals, redirectedCout, redirectedCerr, aborting() ) ); m_activeTestCase = NULL; m_testCaseTracker.reset(); return deltaTotals; }
void runTest( const TestCaseInfo& testInfo ) { Totals prevTotals = m_totals; std::string redirectedCout; std::string redirectedCerr; m_reporter->StartTestCase( testInfo ); m_runningTest = new RunningTest( &testInfo ); do { do { // m_reporter->StartGroup( "test case run" ); m_currentResult.setLineInfo( m_runningTest->getTestCaseInfo().getLineInfo() ); runCurrentTest( redirectedCout, redirectedCerr ); // m_reporter->EndGroup( "test case run", m_totals.delta( prevTotals ) ); } while( m_runningTest->hasUntestedSections() && !aborting() ); } while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() ); delete m_runningTest; m_runningTest = NULL; Totals deltaTotals = m_totals.delta( prevTotals ); m_totals.testCases += deltaTotals.testCases; m_reporter->EndTestCase( testInfo, deltaTotals, redirectedCout, redirectedCerr ); }
virtual ~RunContext() { m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) ); m_context.setRunner( m_prevRunner ); m_context.setConfig( NULL ); m_context.setResultCapture( m_prevResultCapture ); m_context.setConfig( m_prevConfig ); }
Totals runTest( TestCase const& testCase ) { Totals prevTotals = m_totals; std::string redirectedCout; std::string redirectedCerr; TestCaseInfo testInfo = testCase.getTestCaseInfo(); m_reporter->testCaseStarting( testInfo ); m_activeTestCase = &testCase; do { ITracker& rootTracker = m_trackerContext.startRun(); assert( rootTracker.isSectionTracker() ); static_cast<SectionTracker&>( rootTracker ).addInitialFilters( m_config->getSectionsToRun() ); do { m_trackerContext.startCycle(); m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( testInfo.name, testInfo.lineInfo ) ); runCurrentTest( redirectedCout, redirectedCerr ); } while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() ); } // !TBD: deprecated - this will be replaced by indexed trackers while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() ); Totals deltaTotals = m_totals.delta( prevTotals ); if( testInfo.expectedToFail() && deltaTotals.testCases.passed > 0 ) { deltaTotals.assertions.failed++; deltaTotals.testCases.passed--; deltaTotals.testCases.failed++; } m_totals.testCases += deltaTotals.testCases; m_reporter->testCaseEnded( TestCaseStats( testInfo, deltaTotals, redirectedCout, redirectedCerr, aborting() ) ); m_activeTestCase = CATCH_NULL; m_testCaseTracker = CATCH_NULL; return deltaTotals; }
virtual void runAll( bool runHiddenTests = false ) { const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests(); for( std::size_t i=0; i < allTests.size(); ++i ) { if( runHiddenTests || !allTests[i].isHidden() ) { if( aborting() ) { m_reporter->Aborted(); break; } runTest( allTests[i] ); } } }
Totals RunContext::runTest(TestCase const& testCase) { Totals prevTotals = m_totals; std::string redirectedCout; std::string redirectedCerr; auto const& testInfo = testCase.getTestCaseInfo(); m_reporter->testCaseStarting(testInfo); m_activeTestCase = &testCase; ITracker& rootTracker = m_trackerContext.startRun(); assert(rootTracker.isSectionTracker()); static_cast<SectionTracker&>(rootTracker).addInitialFilters(m_config->getSectionsToRun()); do { m_trackerContext.startCycle(); m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo)); runCurrentTest(redirectedCout, redirectedCerr); } while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting()); Totals deltaTotals = m_totals.delta(prevTotals); if (testInfo.expectedToFail() && deltaTotals.testCases.passed > 0) { deltaTotals.assertions.failed++; deltaTotals.testCases.passed--; deltaTotals.testCases.failed++; } m_totals.testCases += deltaTotals.testCases; m_reporter->testCaseEnded(TestCaseStats(testInfo, deltaTotals, redirectedCout, redirectedCerr, aborting())); m_activeTestCase = nullptr; m_testCaseTracker = nullptr; return deltaTotals; }
ResultAction::Value actOnCurrentResult( AssertionResult const& result ) { m_lastResult = result; assertionEnded( m_lastResult ); ResultAction::Value action = ResultAction::None; if( !m_lastResult.isOk() ) { action = ResultAction::Failed; if( shouldDebugBreak() ) action = (ResultAction::Value)( action | ResultAction::Debug ); if( aborting() ) action = (ResultAction::Value)( action | ResultAction::Abort ); } return action; }
virtual std::size_t runMatching( const std::string& rawTestSpec ) { TestSpec testSpec( rawTestSpec ); const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests(); std::size_t testsRun = 0; for( std::size_t i=0; i < allTests.size(); ++i ) { if( testSpec.matches( allTests[i].getName() ) ) { if( aborting() ) { m_reporter->Aborted(); break; } runTest( allTests[i] ); testsRun++; } } return testsRun; }
ResultAction::Value actOnCurrentResult() { testEnded( m_currentResult ); m_lastResult = m_currentResult; m_currentResult = ResultInfoBuilder(); ResultAction::Value action = ResultAction::None; if( !m_lastResult.ok() ) { action = ResultAction::Failed; if( shouldDebugBreak() ) action = (ResultAction::Value)( action | ResultAction::Debug ); if( aborting() ) action = (ResultAction::Value)( action | ResultAction::Abort ); } return action; }
void RunContext::populateReaction( AssertionReaction& reaction ) { reaction.shouldDebugBreak = m_config->shouldDebugBreak(); reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal); }
void RunContext::testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount) { m_reporter->testGroupEnded(TestGroupStats(GroupInfo(testSpec, groupIndex, groupsCount), totals, aborting())); }
int recover(){ //Read from the transaction.txt to get the total number of transactions performed FILE *fr; int transacionId = 0; if(access( "transaction.txt", F_OK ) != -1){ fr = fopen("transaction.txt","r"); fscanf(fr, "%d", &transacionId); fclose(fr); } //Scan through the log from end and get the list of losers. //Assuming only one transaction can be performed with an actionId. If there are no outcome records then that actionId is a loser. int losers[transacionId]; int completeds[transacionId]; FILE* f; long sz; f = fopen("log.txt", "rb"); sz = fsize(f); int loserIndex = 0; if (sz > 0) { char buf[256]; fseek(f, sz, SEEK_SET); char outcomeRecord[50] = ""; strcat(outcomeRecord,"Type = Outcome\n"); int completedsIndex = 0 ; char prevScannedLine[256]; char committed[50] = ""; strcat(committed,"Status = Committed"); char aborted[50] = ""; strcat(aborted,"Status = Aborted"); while (fgetsr(buf, sizeof(buf), f) != NULL){ if(strcmp(buf,outcomeRecord) == 0){ //If the transaction Id has outcome then it is a winner. //There is no concept of end transaction in this implementation //Then previous line will contain ACTION_ID = actionIdNumber //So int k = 11; char actionId[256]; int j =0; for(k=11;prevScannedLine[k]!='\n';k++){ actionId[j] = prevScannedLine[k]; j++; } actionId[j] = '\0'; int completedTransactionId = atoi(actionId); completeds[completedsIndex] = completedTransactionId; completedsIndex++; } if(strcmp(buf,"TYPE = CHANGE\n") == 0){ // Check if the action Id is completed by logging an outcome record. // If it has outcome record it will be in completeds array. else add this actionId to losers list char actionId[256]; int j=0; int k=0; //Checking if the actionId is in completeds //First get the actionId from previous line for(k=11;prevScannedLine[k]!='\n';k++){ actionId[j] = prevScannedLine[k]; j++; } actionId[j] = '\0'; int transactionIdOfChange = atoi(actionId); int transactionCompleted = 0; int w =0; for(w=0;completeds[w]!=0;w++){ if(transactionIdOfChange == completeds[w]){ transactionCompleted = 1; } } if(transactionCompleted == 0){ losers[loserIndex] = transactionIdOfChange; loserIndex++; } //If transactionIdOfChange means that there is no outcome record so add it to losers. } strcpy(prevScannedLine,buf); } } fclose(f); //Aborting the pending transactions int i=0; for(i=0;i<loserIndex;i++){ aborting(losers[i]); } return 0; }
virtual ~RunContext() { m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) ); }