Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/catch2/reporters/catch_reporter_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ namespace Catch {

// And... Print a result applicable to each result type.
switch( result.getResultType() ) {
case ResultWas::ExpressionFailed:
m_xml.startElement( "ExpressionFailed" );
writeSourceInfo( result.getSourceInfo() );
m_xml.writeText( result.getMessage() );
m_xml.endElement();
break;
case ResultWas::ThrewException:
m_xml.startElement( "Exception" );
writeSourceInfo( result.getSourceInfo() );
Expand Down
29 changes: 29 additions & 0 deletions tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <catch2/catch_test_macros.hpp>

#include <catch2/catch_test_case_info.hpp>
#include <catch2/catch_assertion_result.hpp>
#include <catch2/catch_config.hpp>
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
Expand All @@ -23,6 +24,7 @@
#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/reporters/catch_reporter_streaming_base.hpp>
#include <catch2/reporters/catch_reporter_multi.hpp>
#include <catch2/reporters/catch_reporter_xml.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>

#include <sstream>
Expand Down Expand Up @@ -151,6 +153,33 @@ TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) {
}
}

TEST_CASE( "XML reporter includes messages from failed expressions",
"[reporters][xml]" ) {
using Catch::Matchers::ContainsSubstring;
Catch::Config config( Catch::ConfigData{} );
Catch::LazyExpression lazyExpression( false );
Catch::AssertionResultData resultData( Catch::ResultWas::ExpressionFailed,
lazyExpression );
resultData.message = "Actual sequence: one.Func1()";
Catch::AssertionInfo assertionInfo{
"CHECK", { "fake-file.cpp", 42 }, "mocked_call()",
Catch::ResultDisposition::ContinueOnFailure };
Catch::AssertionResult result( assertionInfo, CATCH_MOVE( resultData ) );
Catch::AssertionStats stats( result, {}, Catch::Totals{} );

auto stream = Catch::Detail::make_unique<StringIStream>();
auto& streamRef = *stream;
Catch::XmlReporter reporter( Catch::ReporterConfig{
&config, CATCH_MOVE( stream ), Catch::ColourMode::None,
Catch::Verbosity::Normal, {} } );

reporter.assertionEnded( stats );

REQUIRE_THAT( streamRef.str(),
ContainsSubstring( "<ExpressionFailed" ) &&
ContainsSubstring( "Actual sequence: one.Func1()" ) );
}


TEST_CASE("Reproducer for #2309 - a very long description past 80 chars (default console width) with a late colon : blablabla", "[console-reporter]") {
SUCCEED();
Expand Down