Tag.tests.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include "catch.hpp"
  9. #include "internal/catch_tag_alias_registry.h"
  10. TEST_CASE( "Tag alias can be registered against tag patterns" ) {
  11. Catch::TagAliasRegistry registry;
  12. registry.add( "[@zzz]", "[one][two]", Catch::SourceLineInfo( "file", 2 ) );
  13. SECTION( "The same tag alias can only be registered once" ) {
  14. try {
  15. registry.add( "[@zzz]", "[one][two]", Catch::SourceLineInfo( "file", 10 ) );
  16. FAIL( "expected exception" );
  17. }
  18. catch( std::exception& ex ) {
  19. #ifndef CATCH_CONFIG_DISABLE_MATCHERS
  20. std::string what = ex.what();
  21. using namespace Catch::Matchers;
  22. CHECK_THAT( what, Contains( "[@zzz]" ) );
  23. CHECK_THAT( what, Contains( "file" ) );
  24. CHECK_THAT( what, Contains( "2" ) );
  25. CHECK_THAT( what, Contains( "10" ) );
  26. #endif
  27. }
  28. }
  29. SECTION( "Tag aliases must be of the form [@name]" ) {
  30. CHECK_THROWS( registry.add( "[no ampersat]", "", Catch::SourceLineInfo( "file", 3 ) ) );
  31. CHECK_THROWS( registry.add( "[the @ is not at the start]", "", Catch::SourceLineInfo( "file", 3 ) ) );
  32. CHECK_THROWS( registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) );
  33. CHECK_THROWS( registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) );
  34. }
  35. }
  36. TEST_CASE("shortened hide tags are split apart") {
  37. auto testcase = Catch::makeTestCase(nullptr, "", {"fake test name", "[.magic-tag]"}, CATCH_INTERNAL_LINEINFO);
  38. REQUIRE_THAT(testcase.tags, Catch::VectorContains(std::string("magic-tag")) && Catch::VectorContains(std::string(".")));
  39. }
  40. TEST_CASE("adding a hide tag implicitly enables all others", "[tags]") {
  41. using Catch::VectorContains;
  42. auto tag = GENERATE(as<char const*>{}, "[!hide]", "[.]", "[.foo]");
  43. auto testcase = Catch::makeTestCase(nullptr, "", {"fake test name", tag}, CATCH_INTERNAL_LINEINFO);
  44. REQUIRE_THAT(testcase.tags, VectorContains(std::string(".")) && VectorContains(std::string("!hide")));
  45. }