mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +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
|
||||
#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 ) {
|
||||
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" )
|
||||
{
|
||||
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",
|
||||
"Number of 'succeeding' tests is fixed" ) {
|
||||
Totals totals = runner.runMatching( "./succeeding/*" );
|
||||
CHECK( totals.assertions.passed == 294 );
|
||||
CHECK( totals.assertions.passed == 291 );
|
||||
CHECK( totals.assertions.failed == 0 );
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
namespace Catch{
|
||||
|
||||
NullStreamingReporter::~NullStreamingReporter() {}
|
||||
|
||||
Totals EmbeddedRunner::runMatching( const std::string& rawTestSpec, const std::string& ) {
|
||||
std::ostringstream oss;
|
||||
Config config;
|
||||
@ -24,88 +26,10 @@ namespace Catch{
|
||||
|
||||
// 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 );
|
||||
}
|
||||
m_output = oss.str();
|
||||
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 {
|
||||
|
||||
class MockReporter : public SharedImpl<IReporter> {
|
||||
class NullStreamingReporter : public SharedImpl<IStreamingReporter> {
|
||||
public:
|
||||
|
||||
static const std::string recordGroups;
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
virtual ~NullStreamingReporter();
|
||||
|
||||
static std::string getDescription() {
|
||||
return "mock reporter";
|
||||
return "null reporter";
|
||||
}
|
||||
|
||||
std::string getLog() const {
|
||||
return m_log.str();
|
||||
}
|
||||
private: // IStreamingReporter
|
||||
|
||||
private: // IReporter
|
||||
|
||||
virtual bool shouldRedirectStdout() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void StartTesting() {}
|
||||
|
||||
virtual void EndTesting( const Totals& ) {}
|
||||
|
||||
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 ReporterPreferences getPreferences() const {
|
||||
return ReporterPreferences();
|
||||
}
|
||||
|
||||
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;
|
||||
virtual void testRunStarting( std::string const& ) {}
|
||||
virtual void testGroupStarting( std::string const& ) {}
|
||||
virtual void testCaseStarting( TestCaseInfo const& ) {}
|
||||
virtual void sectionStarting( SectionInfo const& ) {}
|
||||
virtual void assertionStarting( AssertionInfo const& ) {}
|
||||
virtual void assertionEnded( Ptr<AssertionStats const> const& ) {}
|
||||
virtual void sectionEnded( Ptr<SectionStats const> const& ) {}
|
||||
virtual void testCaseEnded( Ptr<TestCaseStats const> const& ) {}
|
||||
virtual void testGroupEnded( Ptr<TestGroupStats const> const& ) {}
|
||||
virtual void testRunEnded( Ptr<TestRunStats const> const& ) {}
|
||||
};
|
||||
|
||||
|
||||
class EmbeddedRunner {
|
||||
|
||||
public:
|
||||
EmbeddedRunner() : m_reporter( new MockReporter() ) {}
|
||||
EmbeddedRunner() : m_reporter( new NullStreamingReporter() ) {}
|
||||
|
||||
Totals runMatching( const std::string& rawTestSpec,
|
||||
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:
|
||||
std::string m_output;
|
||||
Ptr<MockReporter> m_reporter;
|
||||
Ptr<IStreamingReporter> m_reporter;
|
||||
};
|
||||
|
||||
class MetaTestRunner {
|
||||
@ -154,14 +76,17 @@ namespace Catch {
|
||||
}
|
||||
|
||||
void operator()( const TestCase& testCase ) {
|
||||
EmbeddedRunner runner;
|
||||
std::string name = testCase.getTestCaseInfo().name;
|
||||
Totals totals = runner.runMatching( name );
|
||||
std::string name;
|
||||
Totals totals;
|
||||
{
|
||||
EmbeddedRunner runner;
|
||||
name = testCase.getTestCaseInfo().name;
|
||||
totals = runner.runMatching( name );
|
||||
}
|
||||
switch( m_expectedResult ) {
|
||||
case Expected::ToSucceed:
|
||||
if( totals.assertions.failed > 0 ) {
|
||||
INFO( runner.getOutput() );
|
||||
FAIL( "Expected test case '"
|
||||
FAIL( "Expected test case '"
|
||||
<< name
|
||||
<< "' to succeed but there was/ were "
|
||||
<< totals.assertions.failed << " failure(s)" );
|
||||
@ -172,8 +97,7 @@ namespace Catch {
|
||||
break;
|
||||
case Expected::ToFail:
|
||||
if( totals.assertions.failed == 0 ) {
|
||||
INFO( runner.getOutput() );
|
||||
FAIL( "Expected test case '"
|
||||
FAIL( "Expected test case '"
|
||||
<< name
|
||||
<< "' to fail but there was/ were "
|
||||
<< totals.assertions.passed << " success(es)" );
|
||||
|
Loading…
Reference in New Issue
Block a user