Completed NoAssertions warning implementation

This commit is contained in:
Phil Nash
2012-08-31 08:10:36 +01:00
parent 55764c8d47
commit a70fbe3c1a
12 changed files with 668 additions and 513 deletions

View File

@@ -149,10 +149,13 @@ namespace Catch {
return m_data.allowThrows;
}
const ConfigData& data() const {
return m_data;
}
ConfigData& data() {
return m_data;
}
private:
ConfigData m_data;

View File

@@ -47,8 +47,10 @@ namespace Catch
virtual void EndTesting( const Totals& totals ) = 0;
virtual void StartGroup( const std::string& groupName ) = 0;
virtual void EndGroup( const std::string& groupName, const Totals& totals ) = 0;
virtual void StartSection( const std::string& sectionName, const std::string& description ) = 0;
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0;
virtual void StartSection( const std::string& sectionName, const std::string& description ) = 0;
virtual void NoAssertionsInSection( const std::string& sectionName ) = 0;
virtual void NoAssertionsInTestCase( const std::string& testName ) = 0;
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0;
virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
virtual void Aborted() = 0;
virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0;

View File

@@ -190,8 +190,16 @@ namespace Catch {
}
virtual void sectionEnded( const std::string& name, const Counts& prevAssertions ) {
Counts assertions = m_totals.assertions - prevAssertions;
if( assertions.total() == 0 &&
( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) &&
!m_runningTest->isBranchSection() ) {
m_reporter->NoAssertionsInSection( name );
m_totals.assertions.failed++;
assertions.failed++;
}
m_runningTest->endSection( name );
m_reporter->EndSection( name, m_totals.assertions - prevAssertions );
m_reporter->EndSection( name, assertions );
}
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {
@@ -246,6 +254,7 @@ namespace Catch {
void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
try {
m_runningTest->reset();
Counts prevAssertions = m_totals.assertions;
if( m_reporter->shouldRedirectStdout() ) {
StreamRedirect coutRedir( std::cout, redirectedCout );
StreamRedirect cerrRedir( std::cerr, redirectedCerr );
@@ -254,6 +263,13 @@ namespace Catch {
else {
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();
}
catch( TestFailureException& ) {

View File

@@ -36,6 +36,17 @@ namespace Catch {
m_runStatus == RanToCompletionWithSections;
}
bool isBranchSection() const {
return m_currentSection &&
m_currentSection->isBranch();
}
bool hasSections() const {
return m_runStatus == RanAtLeastOneSection ||
m_runStatus == RanToCompletionWithSections ||
m_runStatus == EncounteredASection;
}
void reset() {
m_runStatus = NothingRun;
m_changed = false;

View File

@@ -52,6 +52,10 @@ namespace Catch {
return false;
}
bool isBranch() const {
return m_status == Branch;
}
void ranToCompletion() {
if( m_status == Branch && !hasUntestedSections() )
m_status = TestedBranch;