2014-06-30 08:33:17 +02:00
|
|
|
/*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
|
2020-03-01 19:59:18 +01:00
|
|
|
#include <catch2/matchers/catch_matchers_string.hpp>
|
|
|
|
#include <catch2/matchers/catch_matchers_vector.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_tag_alias_registry.hpp>
|
2020-01-20 23:24:04 +01:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/catch_test_case_info.hpp>
|
2014-06-30 08:33:17 +02:00
|
|
|
|
2017-07-13 10:20:37 +02:00
|
|
|
TEST_CASE( "Tag alias can be registered against tag patterns" ) {
|
2014-06-30 08:33:17 +02:00
|
|
|
|
|
|
|
Catch::TagAliasRegistry registry;
|
|
|
|
|
|
|
|
registry.add( "[@zzz]", "[one][two]", Catch::SourceLineInfo( "file", 2 ) );
|
|
|
|
|
2017-07-13 10:20:37 +02:00
|
|
|
SECTION( "The same tag alias can only be registered once" ) {
|
2014-06-30 08:33:17 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
registry.add( "[@zzz]", "[one][two]", Catch::SourceLineInfo( "file", 10 ) );
|
|
|
|
FAIL( "expected exception" );
|
|
|
|
}
|
|
|
|
catch( std::exception& ex ) {
|
|
|
|
std::string what = ex.what();
|
2017-08-09 13:10:14 +02:00
|
|
|
using namespace Catch::Matchers;
|
2014-06-30 08:33:17 +02:00
|
|
|
CHECK_THAT( what, Contains( "[@zzz]" ) );
|
|
|
|
CHECK_THAT( what, Contains( "file" ) );
|
|
|
|
CHECK_THAT( what, Contains( "2" ) );
|
|
|
|
CHECK_THAT( what, Contains( "10" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 10:20:37 +02:00
|
|
|
SECTION( "Tag aliases must be of the form [@name]" ) {
|
2014-06-30 08:33:17 +02:00
|
|
|
CHECK_THROWS( registry.add( "[no ampersat]", "", Catch::SourceLineInfo( "file", 3 ) ) );
|
|
|
|
CHECK_THROWS( registry.add( "[the @ is not at the start]", "", Catch::SourceLineInfo( "file", 3 ) ) );
|
|
|
|
CHECK_THROWS( registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) );
|
|
|
|
CHECK_THROWS( registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) );
|
|
|
|
}
|
|
|
|
}
|
2019-03-29 10:48:56 +01:00
|
|
|
|
2021-05-28 20:49:05 +02:00
|
|
|
// Dummy line info for creating dummy test cases below
|
|
|
|
constexpr Catch::SourceLineInfo dummySourceLineInfo = CATCH_INTERNAL_LINEINFO;
|
|
|
|
|
2021-05-12 21:43:14 +02:00
|
|
|
TEST_CASE("shortened hide tags are split apart", "[tags]") {
|
2019-11-07 12:39:07 +01:00
|
|
|
using Catch::StringRef;
|
2020-02-18 23:31:16 +01:00
|
|
|
using Catch::Matchers::VectorContains;
|
2019-11-04 21:35:57 +01:00
|
|
|
auto testcase = Catch::makeTestCaseInfo("", {"fake test name", "[.magic-tag]"}, CATCH_INTERNAL_LINEINFO);
|
2021-05-12 21:43:14 +02:00
|
|
|
|
|
|
|
// Extract parsed tags into strings
|
2019-11-07 12:39:07 +01:00
|
|
|
std::vector<StringRef> tags;
|
|
|
|
for (auto const& tag : testcase->tags) {
|
2021-05-12 21:43:14 +02:00
|
|
|
tags.push_back(tag.lowerCased);
|
2019-11-07 12:39:07 +01:00
|
|
|
}
|
2020-02-18 23:31:16 +01:00
|
|
|
REQUIRE_THAT(tags, VectorContains("magic-tag"_catch_sr) && VectorContains("."_catch_sr));
|
2019-03-29 10:48:56 +01:00
|
|
|
}
|
2021-05-12 21:43:14 +02:00
|
|
|
|
|
|
|
TEST_CASE("tags with dots in later positions are not parsed as hidden", "[tags]") {
|
|
|
|
using Catch::StringRef;
|
|
|
|
using Catch::Matchers::VectorContains;
|
|
|
|
auto testcase = Catch::makeTestCaseInfo("", { "fake test name", "[magic.tag]" }, CATCH_INTERNAL_LINEINFO);
|
|
|
|
|
|
|
|
REQUIRE(testcase->tags.size() == 1);
|
|
|
|
REQUIRE(testcase->tags[0].original == "magic.tag"_catch_sr);
|
|
|
|
}
|
2021-05-28 20:49:05 +02:00
|
|
|
|
|
|
|
TEST_CASE( "empty tags are not allowed", "[tags]" ) {
|
|
|
|
REQUIRE_THROWS(
|
|
|
|
Catch::TestCaseInfo("", { "test with an empty tag", "[]" }, dummySourceLineInfo)
|
|
|
|
);
|
|
|
|
}
|