mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
Added warnings - first one: no assertions
This commit is contained in:
parent
78c92e68aa
commit
55764c8d47
@ -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 ) {
|
||||
|
@ -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 "<warning>";
|
||||
}
|
||||
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<Options::TestCaseOptionParser>();
|
||||
AllOptions() {
|
||||
add<Options::TestCaseOptionParser>(); // Keep this one first
|
||||
|
||||
add<Options::ListOptionParser>();
|
||||
add<Options::ReporterOptionParser>();
|
||||
add<Options::OutputOptionParser>();
|
||||
@ -420,7 +444,9 @@ namespace Catch {
|
||||
add<Options::NameOptionParser>();
|
||||
add<Options::AbortOptionParser>();
|
||||
add<Options::NoThrowOptionParser>();
|
||||
add<Options::HelpOptionParser>();
|
||||
add<Options::WarningsOptionParser>();
|
||||
|
||||
add<Options::HelpOptionParser>(); // Keep this one last
|
||||
}
|
||||
|
||||
void parseIntoConfig( const CommandParser& parser, ConfigData& config ) {
|
||||
|
@ -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 <memory>
|
||||
#include <vector>
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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 <memory>
|
||||
@ -22,6 +20,7 @@ namespace Catch {
|
||||
struct IResultCapture;
|
||||
struct IRunner;
|
||||
struct IGeneratorsForTest;
|
||||
struct IConfig;
|
||||
|
||||
class StreamBufBase : public std::streambuf {
|
||||
public:
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "catch_common.h"
|
||||
#include "catch_totals.hpp"
|
||||
#include "catch_ptr.hpp"
|
||||
#include "catch_config.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
@ -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;
|
||||
|
@ -8,6 +8,8 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
||||
|
||||
#include "catch_ptr.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Catch {
|
||||
|
@ -8,7 +8,10 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
|
||||
|
||||
#include "catch_test_case_info.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
|
@ -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 << "' ";
|
||||
|
Loading…
Reference in New Issue
Block a user