mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-30 01:03:30 +01:00
Added warnings - first one: no assertions
This commit is contained in:
parent
78c92e68aa
commit
55764c8d47
@ -102,7 +102,7 @@ namespace Catch {
|
|||||||
? "basic"
|
? "basic"
|
||||||
: m_config.reporter;
|
: 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 );
|
m_reporter = getRegistryHub().getReporterRegistry().create( reporterName, reporterConfig );
|
||||||
if( !m_reporter ) {
|
if( !m_reporter ) {
|
||||||
|
@ -401,6 +401,29 @@ namespace Catch {
|
|||||||
config.allowThrows = false;
|
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
|
class AllOptions
|
||||||
@ -411,7 +434,8 @@ namespace Catch {
|
|||||||
typedef Parsers::const_iterator iterator;
|
typedef Parsers::const_iterator iterator;
|
||||||
|
|
||||||
AllOptions() {
|
AllOptions() {
|
||||||
add<Options::TestCaseOptionParser>();
|
add<Options::TestCaseOptionParser>(); // Keep this one first
|
||||||
|
|
||||||
add<Options::ListOptionParser>();
|
add<Options::ListOptionParser>();
|
||||||
add<Options::ReporterOptionParser>();
|
add<Options::ReporterOptionParser>();
|
||||||
add<Options::OutputOptionParser>();
|
add<Options::OutputOptionParser>();
|
||||||
@ -420,7 +444,9 @@ namespace Catch {
|
|||||||
add<Options::NameOptionParser>();
|
add<Options::NameOptionParser>();
|
||||||
add<Options::AbortOptionParser>();
|
add<Options::AbortOptionParser>();
|
||||||
add<Options::NoThrowOptionParser>();
|
add<Options::NoThrowOptionParser>();
|
||||||
add<Options::HelpOptionParser>();
|
add<Options::WarningsOptionParser>();
|
||||||
|
|
||||||
|
add<Options::HelpOptionParser>(); // Keep this one last
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseIntoConfig( const CommandParser& parser, ConfigData& config ) {
|
void parseIntoConfig( const CommandParser& parser, ConfigData& config ) {
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
#define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
|
||||||
|
|
||||||
#include "catch_test_spec.h"
|
#include "catch_test_spec.h"
|
||||||
#include "catch_interfaces_reporter.h"
|
|
||||||
#include "catch_context.h"
|
#include "catch_context.h"
|
||||||
|
#include "catch_interfaces_config.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -36,18 +36,25 @@ namespace Catch {
|
|||||||
WhatMask = 0xf,
|
WhatMask = 0xf,
|
||||||
|
|
||||||
AsText = 0x10,
|
AsText = 0x10,
|
||||||
AsXml = 0x11,
|
AsXml = 0x20,
|
||||||
|
|
||||||
AsMask = 0xf0
|
AsMask = 0xf0
|
||||||
}; };
|
}; };
|
||||||
|
|
||||||
struct ConfigData {
|
struct ConfigData {
|
||||||
|
|
||||||
|
struct WarnAbout { enum What {
|
||||||
|
Nothing = 0x00,
|
||||||
|
NoAssertions = 0x01
|
||||||
|
}; };
|
||||||
|
|
||||||
ConfigData()
|
ConfigData()
|
||||||
: listSpec( List::None ),
|
: listSpec( List::None ),
|
||||||
shouldDebugBreak( false ),
|
shouldDebugBreak( false ),
|
||||||
includeWhichResults( Include::FailedOnly ),
|
includeWhichResults( Include::FailedOnly ),
|
||||||
cutoff( -1 ),
|
cutoff( -1 ),
|
||||||
allowThrows( true )
|
allowThrows( true ),
|
||||||
|
warnings( WarnAbout::Nothing )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string reporter;
|
std::string reporter;
|
||||||
@ -60,6 +67,7 @@ namespace Catch {
|
|||||||
std::string name;
|
std::string name;
|
||||||
int cutoff;
|
int cutoff;
|
||||||
bool allowThrows;
|
bool allowThrows;
|
||||||
|
WarnAbout::What warnings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
||||||
#define 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 "catch_interfaces_generators.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -22,6 +20,7 @@ namespace Catch {
|
|||||||
struct IResultCapture;
|
struct IResultCapture;
|
||||||
struct IRunner;
|
struct IRunner;
|
||||||
struct IGeneratorsForTest;
|
struct IGeneratorsForTest;
|
||||||
|
struct IConfig;
|
||||||
|
|
||||||
class StreamBufBase : public std::streambuf {
|
class StreamBufBase : public std::streambuf {
|
||||||
public:
|
public:
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
#include "catch_totals.hpp"
|
#include "catch_totals.hpp"
|
||||||
#include "catch_ptr.hpp"
|
#include "catch_ptr.hpp"
|
||||||
|
#include "catch_config.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@ -22,15 +23,18 @@ namespace Catch
|
|||||||
{
|
{
|
||||||
ReporterConfig( const std::string& _name,
|
ReporterConfig( const std::string& _name,
|
||||||
std::ostream& _stream,
|
std::ostream& _stream,
|
||||||
bool _includeSuccessfulResults = false )
|
bool _includeSuccessfulResults,
|
||||||
|
const ConfigData& _fullConfig )
|
||||||
: name( _name ),
|
: name( _name ),
|
||||||
stream( _stream ),
|
stream( _stream ),
|
||||||
includeSuccessfulResults( _includeSuccessfulResults )
|
includeSuccessfulResults( _includeSuccessfulResults ),
|
||||||
|
fullConfig( _fullConfig )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::ostream& stream;
|
std::ostream& stream;
|
||||||
bool includeSuccessfulResults;
|
bool includeSuccessfulResults;
|
||||||
|
ConfigData fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestCaseInfo;
|
class TestCaseInfo;
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_ptr.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
@ -8,7 +8,10 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_test_case_info.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
@ -129,6 +129,11 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) {
|
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();
|
SpanInfo& sectionSpan = m_sectionSpans.back();
|
||||||
if( sectionSpan.emitted && !sectionSpan.name.empty() ) {
|
if( sectionSpan.emitted && !sectionSpan.name.empty() ) {
|
||||||
m_config.stream << "[End of section: '" << sectionName << "' ";
|
m_config.stream << "[End of section: '" << sectionName << "' ";
|
||||||
|
Loading…
Reference in New Issue
Block a user