catch_test_case_registry_impl.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Created by Phil on 7/1/2011
  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_CASE_REGISTRY_IMPL_HPP_INCLUDED
  9. #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  10. #include "catch_test_registry.h"
  11. #include "catch_test_spec.h"
  12. #include "catch_interfaces_config.h"
  13. #include <vector>
  14. #include <set>
  15. #include <algorithm>
  16. #include <ios>
  17. namespace Catch {
  18. class TestCase;
  19. struct IConfig;
  20. std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
  21. bool isThrowSafe( TestCase const& testCase, IConfig const& config );
  22. bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
  23. void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions );
  24. std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
  25. std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
  26. class TestRegistry : public ITestCaseRegistry {
  27. public:
  28. virtual ~TestRegistry() = default;
  29. virtual void registerTest( TestCase const& testCase );
  30. std::vector<TestCase> const& getAllTests() const override;
  31. std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const override;
  32. private:
  33. std::vector<TestCase> m_functions;
  34. mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder;
  35. mutable std::vector<TestCase> m_sortedFunctions;
  36. std::size_t m_unnamedCount = 0;
  37. std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
  38. };
  39. ///////////////////////////////////////////////////////////////////////////
  40. class TestInvokerAsFunction : public ITestInvoker {
  41. void(*m_testAsFunction)();
  42. public:
  43. TestInvokerAsFunction( void(*testAsFunction)() ) noexcept;
  44. void invoke() const override;
  45. };
  46. std::string extractClassName( StringRef const& classOrQualifiedMethodName );
  47. ///////////////////////////////////////////////////////////////////////////
  48. } // end namespace Catch
  49. #endif // TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED