1 /*
2  *  Created by Phil on 27/06/2014.
3  *  Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
4  *
5  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
6  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  */
8 
9 #include "catch.hpp"
10 #include "internal/catch_tag_alias_registry.h"
11 
12 TEST_CASE( "Tag alias can be registered against tag patterns" ) {
13 
14     Catch::TagAliasRegistry registry;
15 
16     registry.add( "[@zzz]", "[one][two]", Catch::SourceLineInfo( "file", 2 ) );
17 
18     SECTION( "The same tag alias can only be registered once" ) {
19 
20         try {
21             registry.add( "[@zzz]", "[one][two]", Catch::SourceLineInfo( "file", 10 ) );
22             FAIL( "expected exception" );
23         }
24         catch( std::exception& ex ) {
25 #ifndef CATCH_CONFIG_DISABLE_MATCHERS
26             std::string what = ex.what();
27             using namespace Catch::Matchers;
28             CHECK_THAT( what, Contains( "[@zzz]" ) );
29             CHECK_THAT( what, Contains( "file" ) );
30             CHECK_THAT( what, Contains( "2" ) );
31             CHECK_THAT( what, Contains( "10" ) );
32 #endif
33         }
34     }
35 
36     SECTION( "Tag aliases must be of the form [@name]" ) {
37         CHECK_THROWS( registry.add( "[no ampersat]", "", Catch::SourceLineInfo( "file", 3 ) ) );
38         CHECK_THROWS( registry.add( "[the @ is not at the start]", "", Catch::SourceLineInfo( "file", 3 ) ) );
39         CHECK_THROWS( registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) );
40         CHECK_THROWS( registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) );
41     }
42 }
43 
44 TEST_CASE("shortened hide tags are split apart") {
45     auto testcase = Catch::makeTestCase(nullptr, "", {"fake test name", "[.magic-tag]"}, CATCH_INTERNAL_LINEINFO);
46     REQUIRE_THAT(testcase.tags, Catch::VectorContains(std::string("magic-tag")) && Catch::VectorContains(std::string(".")));
47 }
48 
49 TEST_CASE("adding a hide tag implicitly enables all others", "[tags]") {
50     using Catch::VectorContains;
51     auto tag = GENERATE(as<char const*>{}, "[!hide]", "[.]", "[.foo]");
52     auto testcase = Catch::makeTestCase(nullptr, "", {"fake test name", tag}, CATCH_INTERNAL_LINEINFO);
53     REQUIRE_THAT(testcase.tags, VectorContains(std::string(".")) && VectorContains(std::string("!hide")));
54 }
55