Moved code that detects absence of assertions closer to where end of test case is reported (ready for merging).

Also now considers info macros when warning (i.e. an empty test case with an INFO() will not warn).
This commit is contained in:
Phil Nash 2012-11-21 08:19:23 +00:00
parent db48a6dfda
commit 5d248c98bf
3 changed files with 29 additions and 24 deletions

View File

@ -115,12 +115,22 @@ namespace Catch {
} }
while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() ); while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
Totals deltaTotals = m_totals.delta( prevTotals );
if( deltaTotals.assertions.total() == 0 &&
deltaTotals.assertions.info == 0 &&
( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) ) {
m_totals.assertions.failed++;
deltaTotals = m_totals.delta( prevTotals );
m_reporter->NoAssertionsInTestCase( m_runningTest->getTestCaseInfo().getName() );
}
m_totals.testCases += deltaTotals.testCases;
m_reporter->EndTestCase( testInfo, deltaTotals, redirectedCout, redirectedCerr );
delete m_runningTest; delete m_runningTest;
m_runningTest = NULL; m_runningTest = NULL;
Totals deltaTotals = m_totals.delta( prevTotals );
m_totals.testCases += deltaTotals.testCases;
m_reporter->EndTestCase( testInfo, deltaTotals, redirectedCout, redirectedCerr );
return deltaTotals; return deltaTotals;
} }
@ -158,7 +168,10 @@ namespace Catch {
} }
if( result.getResultType() == ResultWas::Info ) if( result.getResultType() == ResultWas::Info )
{
m_assertionResults.push_back( result ); m_assertionResults.push_back( result );
m_totals.assertions.info++;
}
else else
m_reporter->Result( result ); m_reporter->Result( result );
@ -252,7 +265,6 @@ namespace Catch {
try { try {
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", m_runningTest->getTestCaseInfo().getLineInfo(), "", ResultDisposition::Normal ); m_lastAssertionInfo = AssertionInfo( "TEST_CASE", m_runningTest->getTestCaseInfo().getLineInfo(), "", ResultDisposition::Normal );
m_runningTest->reset(); m_runningTest->reset();
Counts prevAssertions = m_totals.assertions;
if( m_reporter->shouldRedirectStdout() ) { if( m_reporter->shouldRedirectStdout() ) {
StreamRedirect coutRedir( std::cout, redirectedCout ); StreamRedirect coutRedir( std::cout, redirectedCout );
StreamRedirect cerrRedir( std::cerr, redirectedCerr ); StreamRedirect cerrRedir( std::cerr, redirectedCerr );
@ -261,13 +273,6 @@ namespace Catch {
else { else {
m_runningTest->getTestCaseInfo().invoke(); m_runningTest->getTestCaseInfo().invoke();
} }
Counts assertions = m_totals.assertions - prevAssertions;
if( assertions.total() == 0 &&
( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) &&
!m_runningTest->hasSections() ) {
m_totals.assertions.failed++;
m_reporter->NoAssertionsInTestCase( m_runningTest->getTestCaseInfo().getName() );
}
m_runningTest->ranToCompletion(); m_runningTest->ranToCompletion();
} }
catch( TestFailureException& ) { catch( TestFailureException& ) {

View File

@ -13,17 +13,19 @@
namespace Catch { namespace Catch {
struct Counts { struct Counts {
Counts() : passed( 0 ), failed( 0 ) {} Counts() : passed( 0 ), failed( 0 ), info( 0 ) {}
Counts operator - ( const Counts& other ) const { Counts operator - ( const Counts& other ) const {
Counts diff; Counts diff;
diff.passed = passed - other.passed; diff.passed = passed - other.passed;
diff.failed = failed - other.failed; diff.failed = failed - other.failed;
diff.info = info - other.info;
return diff; return diff;
} }
Counts& operator += ( const Counts& other ) { Counts& operator += ( const Counts& other ) {
passed += other.passed; passed += other.passed;
failed += other.failed; failed += other.failed;
info += other.info;
return *this; return *this;
} }
@ -33,6 +35,7 @@ namespace Catch {
std::size_t passed; std::size_t passed;
std::size_t failed; std::size_t failed;
std::size_t info;
}; };
struct Totals { struct Totals {

View File

@ -196,12 +196,12 @@
[Running: ./succeeding/conditions/ptr] [Running: ./succeeding/conditions/ptr]
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:285: p == __null succeeded for: __null == 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:285: p == __null succeeded for: __null == 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:286: p == pNULL succeeded for: __null == __null /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:286: p == pNULL succeeded for: __null == __null
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:291: p != __null succeeded for: 0x7fff54a840d8 != 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:291: p != __null succeeded for: 0x7fff5c6b3078 != 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:294: cp != __null succeeded for: 0x7fff54a840d8 != 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:294: cp != __null succeeded for: 0x7fff5c6b3078 != 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:297: cpc != __null succeeded for: 0x7fff54a840d8 != 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:297: cpc != __null succeeded for: 0x7fff5c6b3078 != 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:299: returnsNull() == __null succeeded for: {null string} == 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:299: returnsNull() == __null succeeded for: {null string} == 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:300: returnsConstNull() == __null succeeded for: {null string} == 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:300: returnsConstNull() == __null succeeded for: {null string} == 0
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:302: __null != p succeeded for: 0 != 0x7fff54a840d8 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/ConditionTests.cpp:302: __null != p succeeded for: 0 != 0x7fff5c6b3078
[Finished: './succeeding/conditions/ptr' All tests passed (8 assertions in 1 test case)] [Finished: './succeeding/conditions/ptr' All tests passed (8 assertions in 1 test case)]
[Running: ./succeeding/conditions/not] [Running: ./succeeding/conditions/not]
@ -475,10 +475,7 @@ No assertions in section, 'the section2'
[Running: ./succeeding/message] [Running: ./succeeding/message]
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/MessageTests.cpp:14: [warning: this is a warning] /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/MessageTests.cpp:14: [warning: this is a warning]
[Finished: './succeeding/message' No tests ran]
No assertions in test case, './succeeding/message'
[Finished: './succeeding/message' 1 test case failed (1 assertion failed)]
[Running: ./failing/message/info/1] [Running: ./failing/message/info/1]
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/MessageTests.cpp:19: [info: this message should be logged] /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/MessageTests.cpp:19: [info: this message should be logged]
@ -1281,7 +1278,7 @@ No assertions in test case, './inprogress/failing/Tricky/compound lhs'
[Finished: './inprogress/failing/Tricky/compound lhs' 1 test case failed (1 assertion failed)] [Finished: './inprogress/failing/Tricky/compound lhs' 1 test case failed (1 assertion failed)]
[Running: ./failing/Tricky/non streamable type] [Running: ./failing/Tricky/non streamable type]
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:95: &o1 == &o2 failed for: 0x7fff54a848b8 == 0x7fff54a848b0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:95: &o1 == &o2 failed for: 0x7fff5c6b3858 == 0x7fff5c6b3850
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:96: o1 == o2 failed for: {?} == {?} /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:96: o1 == o2 failed for: {?} == {?}
[Finished: './failing/Tricky/non streamable type' 1 test case failed (All 2 assertions failed)] [Finished: './failing/Tricky/non streamable type' 1 test case failed (All 2 assertions failed)]
@ -1307,7 +1304,7 @@ No assertions in test case, './inprogress/failing/Tricky/compound lhs'
[Finished: './succeeding/enum/bits' All tests passed (1 assertion in 1 test case)] [Finished: './succeeding/enum/bits' All tests passed (1 assertion in 1 test case)]
[Running: ./succeeding/boolean member] [Running: ./succeeding/boolean member]
/Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:239: obj.prop != __null succeeded for: 0x7fff54a848b0 != 0 /Users/Phil/Dev/OSS/Catch/projects/XCode4/CatchSelfTest/CatchSelfTest/../../../SelfTest/TrickyTests.cpp:239: obj.prop != __null succeeded for: 0x7fff5c6b3850 != 0
[Finished: './succeeding/boolean member' All tests passed (1 assertion in 1 test case)] [Finished: './succeeding/boolean member' All tests passed (1 assertion in 1 test case)]
[Running: ./succeeding/unimplemented static bool] [Running: ./succeeding/unimplemented static bool]
@ -1354,8 +1351,8 @@ No assertions in test case, './inprogress/failing/Tricky/compound lhs'
[End of section: 'This stuff exists' 1 assertion passed] [End of section: 'This stuff exists' 1 assertion passed]
[Finished: 'scenario name' All tests passed (1 assertion in 1 test case)] [Finished: 'scenario name' All tests passed (1 assertion in 1 test case)]
[End of group: '~dummy'. 45 of 97 test cases failed (103 of 613 assertions failed)] [End of group: '~dummy'. 44 of 97 test cases failed (102 of 612 assertions failed)]
[Testing completed. 45 of 97 test cases failed (103 of 613 assertions failed)] [Testing completed. 44 of 97 test cases failed (102 of 612 assertions failed)]