TestSpecParser.tests.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright Catch2 Authors
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // https://www.boost.org/LICENSE_1_0.txt)
  5. // SPDX-License-Identifier: BSL-1.0
  6. #include <catch2/catch_test_macros.hpp>
  7. #include <catch2/generators/catch_generators.hpp>
  8. #include <catch2/catch_test_case_info.hpp>
  9. #include <catch2/internal/catch_tag_alias_registry.hpp>
  10. #include <catch2/internal/catch_test_spec_parser.hpp>
  11. namespace {
  12. static constexpr Catch::SourceLineInfo dummySourceLineInfo = CATCH_INTERNAL_LINEINFO;
  13. static Catch::TestSpec parseAndCreateSpec(std::string const& str) {
  14. Catch::TagAliasRegistry registry;
  15. Catch::TestSpecParser parser( registry );
  16. parser.parse( str );
  17. auto spec = parser.testSpec();
  18. REQUIRE( spec.hasFilters() );
  19. REQUIRE( spec.getInvalidSpecs().empty());
  20. return spec;
  21. }
  22. }
  23. TEST_CASE( "Parsing tags with non-alphabetical characters is pass-through",
  24. "[test-spec][test-spec-parser]" ) {
  25. auto const& tagString = GENERATE( as<std::string>{},
  26. "[tag with spaces]",
  27. "[I said \"good day\" sir!]" );
  28. CAPTURE(tagString);
  29. auto spec = parseAndCreateSpec( tagString );
  30. Catch::TestCaseInfo testCase(
  31. "", { "fake test name", tagString }, dummySourceLineInfo );
  32. REQUIRE( spec.matches( testCase ) );
  33. }
  34. TEST_CASE("Parsed tags are matched case insensitive",
  35. "[test-spec][test-spec-parser]") {
  36. auto spec = parseAndCreateSpec( "[CASED tag]" );
  37. Catch::TestCaseInfo testCase(
  38. "", { "fake test name", "[cased TAG]" }, dummySourceLineInfo );
  39. REQUIRE( spec.matches( testCase ) );
  40. }