mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-22 11:23:29 +01:00
Normalize C++ namespace in JUnit's reporter classname field
Closes #2468
This commit is contained in:
parent
1bd233866c
commit
9c9f35068e
@ -67,6 +67,15 @@ namespace Catch {
|
||||
return rss.str();
|
||||
}
|
||||
|
||||
static void normalizeNamespaceMarkers(std::string& str) {
|
||||
std::size_t pos = str.find( "::" );
|
||||
while ( pos != str.npos ) {
|
||||
str.replace( pos, 2, "." );
|
||||
pos += 1;
|
||||
pos = str.find( "::", pos );
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
JunitReporter::JunitReporter( ReporterConfig&& _config )
|
||||
@ -170,6 +179,8 @@ namespace Catch {
|
||||
if ( !m_config->name().empty() )
|
||||
className = static_cast<std::string>(m_config->name()) + '.' + className;
|
||||
|
||||
normalizeNamespaceMarkers(className);
|
||||
|
||||
writeSection( className, "", rootSection, stats.testInfo->okToFail() );
|
||||
}
|
||||
|
||||
|
@ -553,6 +553,17 @@ set_tests_properties("Colours::ColourModeCanBeExplicitlySetToAnsi"
|
||||
PASS_REGULAR_EXPRESSION "\\[1\;32mAll tests passed"
|
||||
)
|
||||
|
||||
add_test(NAME "Reporters::JUnit::NamespacesAreNormalized"
|
||||
COMMAND
|
||||
$<TARGET_FILE:SelfTest>
|
||||
--reporter junit
|
||||
"A TEST_CASE_METHOD testing junit classname normalization"
|
||||
)
|
||||
set_tests_properties("Reporters::JUnit::NamespacesAreNormalized"
|
||||
PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "testcase classname=\"SelfTest(\.exe)?\\.A\\.B\\.TestClass\""
|
||||
)
|
||||
|
||||
if (CATCH_ENABLE_CONFIGURE_TESTS)
|
||||
foreach(testName "DefaultReporter" "Disable" "DisableStringification"
|
||||
"ExperimentalRedirect")
|
||||
|
@ -114,4 +114,20 @@ namespace Inner
|
||||
{
|
||||
REQUIRE(Template_Fixture_2<TestType>{}.m_a.size() < 2);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
// We want a class in nested namespace so we can test JUnit's classname normalization.
|
||||
namespace {
|
||||
namespace A {
|
||||
namespace B {
|
||||
class TestClass {};
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE_METHOD( A::B::TestClass,
|
||||
"A TEST_CASE_METHOD testing junit classname normalization",
|
||||
"[class][approvals]" ) {
|
||||
SUCCEED();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user