diff options
| author | Phil Nash | 2012-08-31 08:10:36 +0100 |
|---|---|---|
| committer | Phil Nash | 2012-08-31 08:10:36 +0100 |
| commit | a70fbe3c1ae16e0129c02e57a2fbd22b8212fe7b (patch) | |
| tree | 6cf70ae2432ff8a67278cbbefa7193f6ce475df9 /include | |
| parent | 55764c8d47dfabb1f4530b1880b87c0b134610d0 (diff) | |
| download | catch3-a70fbe3c1ae16e0129c02e57a2fbd22b8212fe7b.tar.gz | |
Completed NoAssertions warning implementation
Diffstat (limited to 'include')
| -rw-r--r-- | include/catch.hpp | 1 | ||||
| -rw-r--r-- | include/internal/catch_config.hpp | 5 | ||||
| -rw-r--r-- | include/internal/catch_interfaces_reporter.h | 6 | ||||
| -rw-r--r-- | include/internal/catch_runner_impl.hpp | 18 | ||||
| -rw-r--r-- | include/internal/catch_running_test.hpp | 11 | ||||
| -rw-r--r-- | include/internal/catch_section_info.hpp | 4 | ||||
| -rw-r--r-- | include/reporters/catch_reporter_basic.hpp | 17 | ||||
| -rw-r--r-- | include/reporters/catch_reporter_junit.hpp | 5 | ||||
| -rw-r--r-- | include/reporters/catch_reporter_xml.hpp | 2 |
9 files changed, 59 insertions, 10 deletions
diff --git a/include/catch.hpp b/include/catch.hpp index 0507e0f6..c79aab14 100644 --- a/include/catch.hpp +++ b/include/catch.hpp @@ -113,6 +113,7 @@ #define INFO( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Info, false, "INFO" ) #define WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, false, "WARN" ) #define FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, true, "FAIL" ) +#define SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, false, "SUCCEED" ) #define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg ) #define CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CAPTURE" ) diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index c2b989b0..819b6f2b 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -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; diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index 792d6ff3..da3cf79a 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -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; diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index fc438b00..578d26dd 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -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& ) { diff --git a/include/internal/catch_running_test.hpp b/include/internal/catch_running_test.hpp index 25689f68..60fc4f78 100644 --- a/include/internal/catch_running_test.hpp +++ b/include/internal/catch_running_test.hpp @@ -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; diff --git a/include/internal/catch_section_info.hpp b/include/internal/catch_section_info.hpp index 0906c7c0..396372bb 100644 --- a/include/internal/catch_section_info.hpp +++ b/include/internal/catch_section_info.hpp @@ -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; diff --git a/include/reporters/catch_reporter_basic.hpp b/include/reporters/catch_reporter_basic.hpp index 28304d73..6b794ca6 100644 --- a/include/reporters/catch_reporter_basic.hpp +++ b/include/reporters/catch_reporter_basic.hpp @@ -127,12 +127,19 @@ namespace Catch { virtual void StartSection( const std::string& sectionName, const std::string& ) { m_sectionSpans.push_back( SpanInfo( sectionName ) ); } - + + virtual void NoAssertionsInSection( const std::string& sectionName ) { + StartSpansLazily(); + TextColour colour( TextColour::ResultError ); + m_config.stream << "\nNo assertions in section, '" << sectionName << "'\n" << std::endl; + } + virtual void NoAssertionsInTestCase( const std::string& testName ) { + StartSpansLazily(); + TextColour colour( TextColour::ResultError ); + m_config.stream << "\nNo assertions in test case, '" << testName << "'\n" << std::endl; + } + virtual void EndSection( const std::string& sectionName, const Counts& assertions ) { - if( ( m_config.fullConfig.warnings & ConfigData::WarnAbout::NoAssertions ) && assertions.total() == 0 ) { - StartSpansLazily(); - m_config.stream << "** No assertions in section **" << std::endl; - } SpanInfo& sectionSpan = m_sectionSpans.back(); if( sectionSpan.emitted && !sectionSpan.name.empty() ) { diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp index d1633dcb..4e66dddf 100644 --- a/include/reporters/catch_reporter_junit.hpp +++ b/include/reporters/catch_reporter_junit.hpp @@ -88,7 +88,10 @@ namespace Catch { virtual void StartSection( const std::string&, const std::string& ){} - virtual void EndSection( const std::string&, const Counts& ){} + virtual void NoAssertionsInSection( const std::string& ) {} + virtual void NoAssertionsInTestCase( const std::string& ) {} + + virtual void EndSection( const std::string&, const Counts& ) {} virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) { m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getName() ) ); diff --git a/include/reporters/catch_reporter_xml.hpp b/include/reporters/catch_reporter_xml.hpp index 9e6a345e..8329b95d 100644 --- a/include/reporters/catch_reporter_xml.hpp +++ b/include/reporters/catch_reporter_xml.hpp @@ -60,6 +60,8 @@ namespace Catch { .writeAttribute( "name", sectionName ) .writeAttribute( "description", description ); } + virtual void NoAssertionsInSection( const std::string& ) {} + virtual void NoAssertionsInTestCase( const std::string& ) {} virtual void EndSection( const std::string& /*sectionName*/, const Counts& assertions ) { m_xml.scopedElement( "OverallResults" ) |