Provide round-tripping serialization for TestSpec

This commit is contained in:
Martin Hořeňovský
2022-10-27 17:10:28 +02:00
parent c6dfeb5e7d
commit e19ed221bd
4 changed files with 112 additions and 10 deletions

View File

@@ -249,7 +249,7 @@ add_test(NAME TestSpecs::CombiningMatchingAndNonMatchingIsOk-1 COMMAND $<TARGET_
add_test(NAME TestSpecs::CombiningMatchingAndNonMatchingIsOk-2 COMMAND $<TARGET_FILE:SelfTest> Tracker, "___nonexistent_test___")
set_tests_properties(TestSpecs::CombiningMatchingAndNonMatchingIsOk-2 PROPERTIES
PASS_REGULAR_EXPRESSION "No test cases matched '___nonexistent_test___'"
PASS_REGULAR_EXPRESSION "No test cases matched '\"___nonexistent_test___\"'"
FAIL_REGULAR_EXPRESSION "No tests ran"
)

View File

@@ -325,3 +325,40 @@ TEST_CASE("#1912 -- test spec parser handles escaping", "[command-line][test-spe
REQUIRE(spec.matches(*fakeTestCase(R"(spec \ char)")));
}
}
TEST_CASE("Test spec serialization is round-trippable", "[test-spec][serialization][approvals]") {
using Catch::parseTestSpec;
using Catch::TestSpec;
auto serializedTestSpec = []( std::string const& spec ) {
Catch::ReusableStringStream sstr;
sstr << parseTestSpec( spec );
return sstr.str();
};
SECTION("Spaces are normalized") {
CHECK( serializedTestSpec( "[abc][def]" ) == "[abc] [def]" );
CHECK( serializedTestSpec( "[def] [abc]" ) == "[def] [abc]" );
CHECK( serializedTestSpec( "[def] [abc]" ) == "[def] [abc]" );
}
SECTION("Output is order dependent") {
CHECK( serializedTestSpec( "[abc][def]" ) == "[abc] [def]" );
CHECK( serializedTestSpec( "[def][abc]" ) == "[def] [abc]" );
}
SECTION("Multiple disjunct filters") {
CHECK( serializedTestSpec( "[abc],[def]" ) == "[abc],[def]" );
CHECK( serializedTestSpec( "[def],[abc],[idkfa]" ) == "[def],[abc],[idkfa]" );
}
SECTION("Test names are enclosed in string") {
CHECK( serializedTestSpec( "Some test" ) == "\"Some test\"" );
CHECK( serializedTestSpec( "*Some test" ) == "\"*Some test\"" );
CHECK( serializedTestSpec( "* Some test" ) == "\"* Some test\"" );
CHECK( serializedTestSpec( "* Some test *" ) == "\"* Some test *\"" );
}
SECTION( "Mixing test names and tags" ) {
CHECK( serializedTestSpec( "some test[abcd]" ) ==
"\"some test\" [abcd]" );
CHECK( serializedTestSpec( "[ab]some test[cd]" ) ==
"[ab] \"some test\" [cd]" );
}
}