From 55764c8d47dfabb1f4530b1880b87c0b134610d0 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 28 Aug 2012 08:20:18 +0100 Subject: [PATCH] Added warnings - first one: no assertions --- include/catch_runner.hpp | 2 +- include/internal/catch_commandline.hpp | 32 ++++++++++++++++++-- include/internal/catch_config.hpp | 14 +++++++-- include/internal/catch_context.h | 3 +- include/internal/catch_interfaces_reporter.h | 10 ++++-- include/internal/catch_interfaces_testcase.h | 2 ++ include/internal/catch_test_spec.h | 3 ++ include/reporters/catch_reporter_basic.hpp | 5 +++ 8 files changed, 59 insertions(+), 12 deletions(-) diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index a927e022..5fec833c 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -102,7 +102,7 @@ namespace Catch { ? "basic" : m_config.reporter; - ReporterConfig reporterConfig( m_config.name, m_configWrapper.stream(), m_config.includeWhichResults == Include::SuccessfulResults ); + ReporterConfig reporterConfig( m_config.name, m_configWrapper.stream(), m_config.includeWhichResults == Include::SuccessfulResults, m_config ); m_reporter = getRegistryHub().getReporterRegistry().create( reporterName, reporterConfig ); if( !m_reporter ) { diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp index 31ca3748..17a3ea74 100644 --- a/include/internal/catch_commandline.hpp +++ b/include/internal/catch_commandline.hpp @@ -401,6 +401,29 @@ namespace Catch { config.allowThrows = false; } }; + + class WarningsOptionParser : public OptionParser { + public: + WarningsOptionParser() : OptionParser( 1, -1 ) { + m_optionNames.push_back( "-w" ); + m_optionNames.push_back( "--warnings" ); + } + virtual std::string argsSynopsis() const { + return ""; + } + virtual std::string optionSummary() const { + return "!TBD"; + } + + virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) { + for( std::size_t i = 0; i < cmd.argsCount(); ++i ) { + if( cmd[i] == "NoAssertions" ) + config.warnings = (ConfigData::WarnAbout::What)( config.warnings | ConfigData::WarnAbout::NoAssertions ); + else + cmd.raiseError( "Unrecognised warning: " + cmd[i] ); + } + } + }; } class AllOptions @@ -410,8 +433,9 @@ namespace Catch { typedef Parsers::const_iterator const_iterator; typedef Parsers::const_iterator iterator; - AllOptions() { - add(); + AllOptions() { + add(); // Keep this one first + add(); add(); add(); @@ -420,7 +444,9 @@ namespace Catch { add(); add(); add(); - add(); + add(); + + add(); // Keep this one last } void parseIntoConfig( const CommandParser& parser, ConfigData& config ) { diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index f859f004..c2b989b0 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -9,8 +9,8 @@ #define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED #include "catch_test_spec.h" -#include "catch_interfaces_reporter.h" #include "catch_context.h" +#include "catch_interfaces_config.h" #include #include @@ -36,18 +36,25 @@ namespace Catch { WhatMask = 0xf, AsText = 0x10, - AsXml = 0x11, + AsXml = 0x20, AsMask = 0xf0 }; }; struct ConfigData { + + struct WarnAbout { enum What { + Nothing = 0x00, + NoAssertions = 0x01 + }; }; + ConfigData() : listSpec( List::None ), shouldDebugBreak( false ), includeWhichResults( Include::FailedOnly ), cutoff( -1 ), - allowThrows( true ) + allowThrows( true ), + warnings( WarnAbout::Nothing ) {} std::string reporter; @@ -60,6 +67,7 @@ namespace Catch { std::string name; int cutoff; bool allowThrows; + WarnAbout::What warnings; }; diff --git a/include/internal/catch_context.h b/include/internal/catch_context.h index c3460e3d..7ddd1f53 100644 --- a/include/internal/catch_context.h +++ b/include/internal/catch_context.h @@ -8,8 +8,6 @@ #ifndef TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED -#include "catch_interfaces_reporter.h" -#include "catch_interfaces_config.h" #include "catch_interfaces_generators.h" #include @@ -22,6 +20,7 @@ namespace Catch { struct IResultCapture; struct IRunner; struct IGeneratorsForTest; + struct IConfig; class StreamBufBase : public std::streambuf { public: diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index f6b90872..792d6ff3 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -11,6 +11,7 @@ #include "catch_common.h" #include "catch_totals.hpp" #include "catch_ptr.hpp" +#include "catch_config.hpp" #include #include @@ -22,16 +23,19 @@ namespace Catch { ReporterConfig( const std::string& _name, std::ostream& _stream, - bool _includeSuccessfulResults = false ) + bool _includeSuccessfulResults, + const ConfigData& _fullConfig ) : name( _name ), stream( _stream ), - includeSuccessfulResults( _includeSuccessfulResults ) + includeSuccessfulResults( _includeSuccessfulResults ), + fullConfig( _fullConfig ) {} std::string name; std::ostream& stream; bool includeSuccessfulResults; - }; + ConfigData fullConfig; + }; class TestCaseInfo; class ResultInfo; diff --git a/include/internal/catch_interfaces_testcase.h b/include/internal/catch_interfaces_testcase.h index 7d5192aa..94ddf6f7 100644 --- a/include/internal/catch_interfaces_testcase.h +++ b/include/internal/catch_interfaces_testcase.h @@ -8,6 +8,8 @@ #ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED +#include "catch_ptr.hpp" + #include namespace Catch { diff --git a/include/internal/catch_test_spec.h b/include/internal/catch_test_spec.h index 4aa03855..69a76b82 100644 --- a/include/internal/catch_test_spec.h +++ b/include/internal/catch_test_spec.h @@ -8,7 +8,10 @@ #ifndef TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED #define TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED +#include "catch_test_case_info.h" + #include +#include namespace Catch { diff --git a/include/reporters/catch_reporter_basic.hpp b/include/reporters/catch_reporter_basic.hpp index 4cff4729..28304d73 100644 --- a/include/reporters/catch_reporter_basic.hpp +++ b/include/reporters/catch_reporter_basic.hpp @@ -129,6 +129,11 @@ namespace Catch { } 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() ) { m_config.stream << "[End of section: '" << sectionName << "' ";