catch_test_spec.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Created by Phil on 14/8/2012.
  3. * Copyright 2010 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. #ifndef TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
  9. #define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
  10. #ifdef __clang__
  11. #pragma clang diagnostic push
  12. #pragma clang diagnostic ignored "-Wpadded"
  13. #endif
  14. #include "catch_wildcard_pattern.h"
  15. #include "catch_test_case_info.h"
  16. #include <string>
  17. #include <vector>
  18. #include <memory>
  19. namespace Catch {
  20. struct IConfig;
  21. class TestSpec {
  22. class Pattern {
  23. public:
  24. explicit Pattern( std::string const& name );
  25. virtual ~Pattern();
  26. virtual bool matches( TestCaseInfo const& testCase ) const = 0;
  27. std::string const& name() const;
  28. private:
  29. std::string const m_name;
  30. };
  31. using PatternPtr = std::shared_ptr<Pattern>;
  32. class NamePattern : public Pattern {
  33. public:
  34. explicit NamePattern( std::string const& name, std::string const& filterString );
  35. bool matches( TestCaseInfo const& testCase ) const override;
  36. private:
  37. WildcardPattern m_wildcardPattern;
  38. };
  39. class TagPattern : public Pattern {
  40. public:
  41. explicit TagPattern( std::string const& tag, std::string const& filterString );
  42. bool matches( TestCaseInfo const& testCase ) const override;
  43. private:
  44. std::string m_tag;
  45. };
  46. class ExcludedPattern : public Pattern {
  47. public:
  48. explicit ExcludedPattern( PatternPtr const& underlyingPattern );
  49. bool matches( TestCaseInfo const& testCase ) const override;
  50. private:
  51. PatternPtr m_underlyingPattern;
  52. };
  53. struct Filter {
  54. std::vector<PatternPtr> m_patterns;
  55. bool matches( TestCaseInfo const& testCase ) const;
  56. std::string name() const;
  57. };
  58. public:
  59. struct FilterMatch {
  60. std::string name;
  61. std::vector<TestCase const*> tests;
  62. };
  63. using Matches = std::vector<FilterMatch>;
  64. using vectorStrings = std::vector<std::string>;
  65. bool hasFilters() const;
  66. bool matches( TestCaseInfo const& testCase ) const;
  67. Matches matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const;
  68. const vectorStrings & getInvalidArgs() const;
  69. private:
  70. std::vector<Filter> m_filters;
  71. std::vector<std::string> m_invalidArgs;
  72. friend class TestSpecParser;
  73. };
  74. }
  75. #ifdef __clang__
  76. #pragma clang diagnostic pop
  77. #endif
  78. #endif // TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED