17 #ifndef __STOUT_TESTS_ENVIRONMENT_HPP__ 18 #define __STOUT_TESTS_ENVIRONMENT_HPP__ 24 #include <gtest/gtest.h> 39 virtual bool disable(const ::testing::TestInfo*
test)
const = 0;
43 const ::testing::TestInfo* test,
44 const std::string& pattern)
51 if (test->type_param() !=
nullptr &&
56 if (test->value_param() !=
nullptr &&
67 static std::vector<std::string> disabled(
68 const ::testing::UnitTest* unitTest,
69 const std::vector<std::shared_ptr<TestFilter>>&
filters)
71 std::vector<std::string> disabled;
73 for (
int i = 0; i < unitTest->total_test_case_count(); i++) {
74 const ::testing::TestCase* testCase = unitTest->GetTestCase(i);
76 for (
int j = 0; j < testCase->total_test_count(); j++) {
77 const ::testing::TestInfo*
test = testCase->GetTestInfo(j);
79 foreach (
const std::shared_ptr<TestFilter>&
filter,
filters) {
80 if (filter->disable(test)) {
82 test->test_case_name() + std::string(
".") + test->name());
107 const std::string& filtered_tests = ::testing::GTEST_FLAG(
filter);
110 if (filtered_tests.empty()) {
114 std::string enabled_tests;
115 std::string disabled_tests;
117 size_t dash = filtered_tests.find(
'-');
118 if (dash != std::string::npos) {
119 enabled_tests = filtered_tests.substr(0, dash);
120 disabled_tests = filtered_tests.substr(dash + 1);
122 enabled_tests = filtered_tests;
126 if (enabled_tests.empty()) {
132 disabled_tests +=
":";
136 ::testing::UnitTest* unitTest = ::testing::UnitTest::GetInstance();
141 ::testing::GTEST_FLAG(
filter) = enabled_tests +
"-" + disabled_tests;
149 #endif // __STOUT_TESTS_ENVIRONMENT_HPP__ bool endsWith(const std::string &s, const std::string &suffix)
Definition: strings.hpp:402
virtual ~TestFilter()=default
std::stringstream & join(std::stringstream &stream, const std::string &separator, T &&...args)
Definition: strings.hpp:307
bool contains(const std::string &s, const std::string &substr)
Definition: strings.hpp:423
static bool matches(const ::testing::TestInfo *test, const std::string &pattern)
Definition: environment.hpp:42
Result< std::vector< Filter< Classifier > > > filters(const std::string &_link, const Handle &parent)
Definition: internal.hpp:769
Definition: environment.hpp:94
Definition: attributes.hpp:24
Definition: environment.hpp:28
Environment(const std::vector< std::shared_ptr< TestFilter >> &filters)
Definition: environment.hpp:103
Result< bool > test(const std::string &_link, unsigned int flags)
Definition: internal.hpp:111
Definition: environment.hpp:32
virtual bool disable(const ::testing::TestInfo *test) const =0
void filter(Filter *filter)