mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Removed mocked output logging tests in favour of approval tests
This commit is contained in:
parent
8255acf88f
commit
37ce023a30
File diff suppressed because it is too large
Load Diff
@ -140,29 +140,6 @@ TEST_CASE( "./failing/exceptions/in-section", "Exceptions thrown from sections r
|
|||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST_CASE( "./succeeding/exceptions/error messages", "The error messages produced by exceptions caught by Catch matched the expected form" )
|
|
||||||
{
|
|
||||||
Catch::EmbeddedRunner runner;
|
|
||||||
using namespace Catch::Matchers;
|
|
||||||
|
|
||||||
SECTION( "custom, unexpected", "" )
|
|
||||||
{
|
|
||||||
runner.runMatching( "./failing/exceptions/custom" );
|
|
||||||
// CHECK_THAT( runner.getLog(), Contains( "Unexpected exception" ) ); // Mock reporter doesn't say this
|
|
||||||
CHECK_THAT( runner.getLog(), Contains( "custom exception" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION( "in section", "" )
|
|
||||||
{
|
|
||||||
runner.runMatching( "./failing/exceptions/in-section" );
|
|
||||||
INFO( runner.getLog() );
|
|
||||||
// CHECK( runner.getLog().find( "Unexpected exception" ) != std::string::npos ); // Mock reporter doesn't say this
|
|
||||||
CHECK_THAT( runner.getLog(), Contains( "Exception from section" ) );
|
|
||||||
CHECK_THAT( runner.getLog(), Contains( CATCH_GET_LINE_INFO( "the section2" ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int thisFunctionNotImplemented( int ) {
|
inline int thisFunctionNotImplemented( int ) {
|
||||||
CATCH_NOT_IMPLEMENTED;
|
CATCH_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
@ -90,36 +90,6 @@ TEST_CASE( "./Sections/nested/a/b", "nested SECTION tests" )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Sections/nested3", "nested SECTION tests" )
|
|
||||||
{
|
|
||||||
Catch::EmbeddedRunner runner;
|
|
||||||
|
|
||||||
runner.runMatching( "./Sections/nested/a/b", "mock" );
|
|
||||||
CHECK( runner.getLog() ==
|
|
||||||
"\\[g] ./Sections/nested/a/b\n"
|
|
||||||
" \\[tc] ./Sections/nested/a/b\n"
|
|
||||||
|
|
||||||
" \\ [s] c\n"
|
|
||||||
" \\ [s] d (leaf)\n"
|
|
||||||
" / [s] d (leaf)\n"
|
|
||||||
" / [s] c\n"
|
|
||||||
|
|
||||||
" \\ [s] c\n"
|
|
||||||
" \\ [s] e (leaf)\n"
|
|
||||||
" / [s] e (leaf)\n"
|
|
||||||
" / [s] c\n"
|
|
||||||
|
|
||||||
" \\ [s] c\n"
|
|
||||||
" / [s] c\n"
|
|
||||||
|
|
||||||
" \\ [s] f (leaf)\n"
|
|
||||||
" / [s] f (leaf)\n"
|
|
||||||
|
|
||||||
" /[tc] ./Sections/nested/a/b\n"
|
|
||||||
"/[g] ./Sections/nested/a/b\n" );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE( "./mixed/Misc/Sections/loops", "looped SECTION tests" )
|
TEST_CASE( "./mixed/Misc/Sections/loops", "looped SECTION tests" )
|
||||||
{
|
{
|
||||||
int a = 1;
|
int a = 1;
|
||||||
|
@ -37,7 +37,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
|||||||
SECTION( "selftest/test counts/succeeding tests",
|
SECTION( "selftest/test counts/succeeding tests",
|
||||||
"Number of 'succeeding' tests is fixed" ) {
|
"Number of 'succeeding' tests is fixed" ) {
|
||||||
Totals totals = runner.runMatching( "./succeeding/*" );
|
Totals totals = runner.runMatching( "./succeeding/*" );
|
||||||
CHECK( totals.assertions.passed == 294 );
|
CHECK( totals.assertions.passed == 291 );
|
||||||
CHECK( totals.assertions.failed == 0 );
|
CHECK( totals.assertions.failed == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
namespace Catch{
|
namespace Catch{
|
||||||
|
|
||||||
|
NullStreamingReporter::~NullStreamingReporter() {}
|
||||||
|
|
||||||
Totals EmbeddedRunner::runMatching( const std::string& rawTestSpec, const std::string& ) {
|
Totals EmbeddedRunner::runMatching( const std::string& rawTestSpec, const std::string& ) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
Config config;
|
Config config;
|
||||||
@ -24,88 +26,10 @@ namespace Catch{
|
|||||||
|
|
||||||
// Scoped because Runner doesn't report EndTesting until its destructor
|
// Scoped because Runner doesn't report EndTesting until its destructor
|
||||||
{
|
{
|
||||||
Runner runner( config, new LegacyReporterAdapter( m_reporter.get(), ReporterConfig( config.stream(), config.data() ) ) );
|
Runner runner( config, m_reporter.get() );
|
||||||
totals = runner.runMatching( rawTestSpec );
|
totals = runner.runMatching( rawTestSpec );
|
||||||
}
|
}
|
||||||
m_output = oss.str();
|
|
||||||
return totals;
|
return totals;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MockReporter::Result( const AssertionResult& assertionResult ) {
|
|
||||||
if( assertionResult.getResultType() == ResultWas::Ok )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_log << assertionResult.getSourceInfo() << " ";
|
|
||||||
|
|
||||||
switch( assertionResult.getResultType() ) {
|
|
||||||
case ResultWas::Info:
|
|
||||||
m_log << "Info";
|
|
||||||
break;
|
|
||||||
case ResultWas::Warning:
|
|
||||||
m_log << "Warning";
|
|
||||||
break;
|
|
||||||
case ResultWas::ExplicitFailure:
|
|
||||||
m_log << "ExplicitFailure";
|
|
||||||
break;
|
|
||||||
case ResultWas::ExpressionFailed:
|
|
||||||
m_log << "ExpressionFailed";
|
|
||||||
break;
|
|
||||||
case ResultWas::Unknown:
|
|
||||||
m_log << "Unknown";
|
|
||||||
break;
|
|
||||||
case ResultWas::ThrewException:
|
|
||||||
m_log << "ThrewException";
|
|
||||||
break;
|
|
||||||
case ResultWas::DidntThrowException:
|
|
||||||
m_log << "DidntThrowException";
|
|
||||||
break;
|
|
||||||
|
|
||||||
// We shouldn't ever see these
|
|
||||||
case ResultWas::Ok:
|
|
||||||
m_log << "Ok";
|
|
||||||
break;
|
|
||||||
case ResultWas::FailureBit:
|
|
||||||
m_log << "FailureBit";
|
|
||||||
break;
|
|
||||||
case ResultWas::Exception:
|
|
||||||
m_log << "Exception";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( assertionResult.hasExpression() )
|
|
||||||
m_log << assertionResult.getExpression();
|
|
||||||
|
|
||||||
if( assertionResult.hasMessage() )
|
|
||||||
m_log << "'" << assertionResult.getMessage() << "'";
|
|
||||||
|
|
||||||
if( assertionResult.hasExpandedExpression() )
|
|
||||||
m_log << assertionResult.getExpandedExpression();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MockReporter::openLabel( const std::string& label, const std::string& arg ) {
|
|
||||||
if( shouldRecord( label ) ) {
|
|
||||||
m_log << m_indent << "\\" << label;
|
|
||||||
if( !arg.empty() )
|
|
||||||
m_log << " " << arg;
|
|
||||||
m_log << "\n";
|
|
||||||
m_indent += " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MockReporter::closeLabel( const std::string& label, const std::string& arg ) {
|
|
||||||
if( shouldRecord( label ) ) {
|
|
||||||
m_indent = m_indent.substr( 0, m_indent.size()-1 );
|
|
||||||
m_log << m_indent << "/" << label;
|
|
||||||
if( !arg.empty() )
|
|
||||||
m_log << " " << arg;
|
|
||||||
m_log << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string MockReporter::recordGroups = "[g]";
|
|
||||||
const std::string MockReporter::recordTestCases = "[tc]";
|
|
||||||
const std::string MockReporter::recordSections =" [s]";
|
|
||||||
|
|
||||||
INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( "mock", MockReporter )
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,121 +20,43 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class MockReporter : public SharedImpl<IReporter> {
|
class NullStreamingReporter : public SharedImpl<IStreamingReporter> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static const std::string recordGroups;
|
virtual ~NullStreamingReporter();
|
||||||
static const std::string recordTestCases;
|
|
||||||
static const std::string recordSections;
|
|
||||||
|
|
||||||
void recordAll() {
|
|
||||||
addRecorder( recordGroups );
|
|
||||||
addRecorder( recordTestCases );
|
|
||||||
addRecorder( recordSections );
|
|
||||||
}
|
|
||||||
|
|
||||||
MockReporter( const ReporterConfig& ) {
|
|
||||||
recordAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
MockReporter() {
|
|
||||||
recordAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
void addRecorder( const std::string& recorder ) {
|
|
||||||
m_recorders.insert( recorder );
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string getDescription() {
|
static std::string getDescription() {
|
||||||
return "mock reporter";
|
return "null reporter";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getLog() const {
|
private: // IStreamingReporter
|
||||||
return m_log.str();
|
|
||||||
|
virtual ReporterPreferences getPreferences() const {
|
||||||
|
return ReporterPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
private: // IReporter
|
virtual void testRunStarting( std::string const& ) {}
|
||||||
|
virtual void testGroupStarting( std::string const& ) {}
|
||||||
virtual bool shouldRedirectStdout() const {
|
virtual void testCaseStarting( TestCaseInfo const& ) {}
|
||||||
return false;
|
virtual void sectionStarting( SectionInfo const& ) {}
|
||||||
}
|
virtual void assertionStarting( AssertionInfo const& ) {}
|
||||||
|
virtual void assertionEnded( Ptr<AssertionStats const> const& ) {}
|
||||||
virtual void StartTesting() {}
|
virtual void sectionEnded( Ptr<SectionStats const> const& ) {}
|
||||||
|
virtual void testCaseEnded( Ptr<TestCaseStats const> const& ) {}
|
||||||
virtual void EndTesting( const Totals& ) {}
|
virtual void testGroupEnded( Ptr<TestGroupStats const> const& ) {}
|
||||||
|
virtual void testRunEnded( Ptr<TestRunStats const> const& ) {}
|
||||||
virtual void StartGroup( const std::string& groupName ) {
|
|
||||||
openLabel( recordGroups, groupName );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void EndGroup( const std::string& groupName, const Totals& ) {
|
|
||||||
closeLabel( recordGroups, groupName );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void StartSection( const std::string& sectionName, const std::string& ) {
|
|
||||||
openLabel( recordSections, sectionName );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void NoAssertionsInSection( const std::string& ) {}
|
|
||||||
virtual void NoAssertionsInTestCase( const std::string& ) {}
|
|
||||||
|
|
||||||
virtual void EndSection( const std::string& sectionName, const Counts& ) {
|
|
||||||
closeLabel( recordSections, sectionName );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void StartTestCase( const TestCaseInfo& testInfo ) {
|
|
||||||
openLabel( recordTestCases, testInfo.name );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Aborted(){}
|
|
||||||
|
|
||||||
virtual void EndTestCase( const TestCaseInfo& testInfo,
|
|
||||||
const Totals&,
|
|
||||||
const std::string&,
|
|
||||||
const std::string& ) {
|
|
||||||
closeLabel( recordTestCases, testInfo.name );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Result( const AssertionResult& assertionResult );
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
bool shouldRecord( const std::string& recorder ) const {
|
|
||||||
return m_recorders.find( recorder ) != m_recorders.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void openLabel( const std::string& label, const std::string& arg = "" );
|
|
||||||
void closeLabel( const std::string& label, const std::string& arg = "" );
|
|
||||||
|
|
||||||
std::string m_indent;
|
|
||||||
std::ostringstream m_log;
|
|
||||||
std::set<std::string> m_recorders;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class EmbeddedRunner {
|
class EmbeddedRunner {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EmbeddedRunner() : m_reporter( new MockReporter() ) {}
|
EmbeddedRunner() : m_reporter( new NullStreamingReporter() ) {}
|
||||||
|
|
||||||
Totals runMatching( const std::string& rawTestSpec,
|
Totals runMatching( const std::string& rawTestSpec,
|
||||||
const std::string& reporter = "basic" );
|
const std::string& reporter = "basic" );
|
||||||
|
|
||||||
std::string getOutput() {
|
|
||||||
return m_output;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addRecorder( const std::string& recorder ) {
|
|
||||||
m_reporter->addRecorder( recorder );
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string getLog() const {
|
|
||||||
return m_reporter->getLog();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_output;
|
Ptr<IStreamingReporter> m_reporter;
|
||||||
Ptr<MockReporter> m_reporter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MetaTestRunner {
|
class MetaTestRunner {
|
||||||
@ -154,13 +76,16 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void operator()( const TestCase& testCase ) {
|
void operator()( const TestCase& testCase ) {
|
||||||
EmbeddedRunner runner;
|
std::string name;
|
||||||
std::string name = testCase.getTestCaseInfo().name;
|
Totals totals;
|
||||||
Totals totals = runner.runMatching( name );
|
{
|
||||||
|
EmbeddedRunner runner;
|
||||||
|
name = testCase.getTestCaseInfo().name;
|
||||||
|
totals = runner.runMatching( name );
|
||||||
|
}
|
||||||
switch( m_expectedResult ) {
|
switch( m_expectedResult ) {
|
||||||
case Expected::ToSucceed:
|
case Expected::ToSucceed:
|
||||||
if( totals.assertions.failed > 0 ) {
|
if( totals.assertions.failed > 0 ) {
|
||||||
INFO( runner.getOutput() );
|
|
||||||
FAIL( "Expected test case '"
|
FAIL( "Expected test case '"
|
||||||
<< name
|
<< name
|
||||||
<< "' to succeed but there was/ were "
|
<< "' to succeed but there was/ were "
|
||||||
@ -172,7 +97,6 @@ namespace Catch {
|
|||||||
break;
|
break;
|
||||||
case Expected::ToFail:
|
case Expected::ToFail:
|
||||||
if( totals.assertions.failed == 0 ) {
|
if( totals.assertions.failed == 0 ) {
|
||||||
INFO( runner.getOutput() );
|
|
||||||
FAIL( "Expected test case '"
|
FAIL( "Expected test case '"
|
||||||
<< name
|
<< name
|
||||||
<< "' to fail but there was/ were "
|
<< "' to fail but there was/ were "
|
||||||
|
Loading…
Reference in New Issue
Block a user