Apply requested changes.
This commit is contained in:
parent
f20688737a
commit
3fc1ab6632
@ -723,23 +723,16 @@ static bool PatternMatchesString(const std::string& name_str,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Filter {
|
namespace {
|
||||||
std::vector<std::string> patterns_;
|
class UnitTestFilter {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
UnitTestFilter() = default;
|
||||||
|
|
||||||
// Constructs a filter form a string of patterns separated by `:`.
|
// Constructs a filter form a string of patterns separated by `:`.
|
||||||
explicit Filter(const std::string& filter) {
|
explicit UnitTestFilter(const std::string& filter) {
|
||||||
if (filter.empty()) return;
|
if (filter.empty()) return;
|
||||||
|
|
||||||
auto pattern_start = filter.begin();
|
SplitString(filter, ':', &patterns_);
|
||||||
while (true) {
|
|
||||||
const auto delimiter = std::find(pattern_start, filter.end(), ':');
|
|
||||||
patterns_.emplace_back(pattern_start, delimiter);
|
|
||||||
|
|
||||||
if (delimiter == filter.end())
|
|
||||||
break;
|
|
||||||
pattern_start = std::next(delimiter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if and only if name matches at least one of the patterns in
|
// Returns true if and only if name matches at least one of the patterns in
|
||||||
@ -752,35 +745,33 @@ class Filter {
|
|||||||
return std::any_of(patterns_.begin(), patterns_.end(),
|
return std::any_of(patterns_.begin(), patterns_.end(),
|
||||||
pattern_matches_name);
|
pattern_matches_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::string> patterns_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PositiveAndNegativeFilter {
|
class PositiveAndNegativeUnitTestFilter {
|
||||||
Filter positive_filter_;
|
|
||||||
Filter negative_filter_;
|
|
||||||
|
|
||||||
static std::pair<std::string, std::string>
|
|
||||||
BreakIntoPositiveAndNegativeFilters(const std::string& filter) {
|
|
||||||
const auto dash_pos = filter.find('-');
|
|
||||||
if (dash_pos == std::string::npos) {
|
|
||||||
return {filter, {}}; // Whole string is a positive filter
|
|
||||||
} else {
|
|
||||||
return {dash_pos ? filter.substr(0, dash_pos) : kUniversalFilter,
|
|
||||||
filter.substr(dash_pos + 1)};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PositiveAndNegativeFilter(
|
|
||||||
const std::pair<std::string, std::string>& positive_and_negative_filters)
|
|
||||||
: positive_filter_(positive_and_negative_filters.first),
|
|
||||||
negative_filter_(positive_and_negative_filters.second) {}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructs a positive and a negative filter from a string. The string
|
// Constructs a positive and a negative filter from a string. The string
|
||||||
// contains a positive filter optionally followed by a '-' character and a
|
// contains a positive filter optionally followed by a '-' character and a
|
||||||
// negative filter. In case only a negative filter is provided the positive
|
// negative filter. In case only a negative filter is provided the positive
|
||||||
// filter will be assumed "*".
|
// filter will be assumed "*".
|
||||||
// A filter is a list of patterns separated by ':'.
|
// A filter is a list of patterns separated by ':'.
|
||||||
explicit PositiveAndNegativeFilter(const std::string& filter)
|
explicit PositiveAndNegativeUnitTestFilter(const std::string& filter) {
|
||||||
: PositiveAndNegativeFilter(BreakIntoPositiveAndNegativeFilters(filter)) {
|
std::vector<std::string> positive_and_negative_filters;
|
||||||
|
|
||||||
|
SplitString(filter, '-', &positive_and_negative_filters);
|
||||||
|
const auto& positive_filter = positive_and_negative_filters.front();
|
||||||
|
|
||||||
|
if (positive_and_negative_filters.size() > 1) {
|
||||||
|
positive_filter_ = UnitTestFilter{
|
||||||
|
positive_filter.size() ? positive_filter : kUniversalFilter};
|
||||||
|
negative_filter_ = UnitTestFilter{positive_and_negative_filters.back()};
|
||||||
|
} else {
|
||||||
|
// In case positive filter is empty
|
||||||
|
// we do not use kUniversalFilter by design
|
||||||
|
positive_filter_ = UnitTestFilter{positive_filter};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if and only if test name (this is generated by appending test
|
// Returns true if and only if test name (this is generated by appending test
|
||||||
@ -799,7 +790,12 @@ class PositiveAndNegativeFilter {
|
|||||||
return positive_filter_.MatchesName(name) &&
|
return positive_filter_.MatchesName(name) &&
|
||||||
!negative_filter_.MatchesName(name);
|
!negative_filter_.MatchesName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
UnitTestFilter positive_filter_;
|
||||||
|
UnitTestFilter negative_filter_;
|
||||||
};
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
// Returns true if and only if the user-specified filter matches the test
|
// Returns true if and only if the user-specified filter matches the test
|
||||||
// suite name and the test name.
|
// suite name and the test name.
|
||||||
@ -807,7 +803,7 @@ bool UnitTestOptions::FilterMatchesTest(const std::string& test_suite_name,
|
|||||||
const std::string& test_name) {
|
const std::string& test_name) {
|
||||||
// Split --gtest_filter at '-', if there is one, to separate into
|
// Split --gtest_filter at '-', if there is one, to separate into
|
||||||
// positive filter and negative filter portions
|
// positive filter and negative filter portions
|
||||||
return PositiveAndNegativeFilter{GTEST_FLAG_GET(filter)}.MatchesTest(test_suite_name, test_name);
|
return PositiveAndNegativeUnitTestFilter{GTEST_FLAG_GET(filter)}.MatchesTest(test_suite_name, test_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTEST_HAS_SEH
|
#if GTEST_HAS_SEH
|
||||||
@ -5785,7 +5781,7 @@ TestSuite* UnitTestImpl::GetTestSuite(
|
|||||||
auto* const new_test_suite =
|
auto* const new_test_suite =
|
||||||
new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc);
|
new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc);
|
||||||
|
|
||||||
const Filter death_test_suite_filter{kDeathTestSuiteFilter};
|
const UnitTestFilter death_test_suite_filter{kDeathTestSuiteFilter};
|
||||||
// Is this a death test suite?
|
// Is this a death test suite?
|
||||||
if (death_test_suite_filter.MatchesName(test_suite_name)) {
|
if (death_test_suite_filter.MatchesName(test_suite_name)) {
|
||||||
// Yes. Inserts the test suite after the last death test suite
|
// Yes. Inserts the test suite after the last death test suite
|
||||||
@ -6120,8 +6116,8 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
|
|||||||
const int32_t shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
|
const int32_t shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
|
||||||
Int32FromEnvOrDie(kTestShardIndex, -1) : -1;
|
Int32FromEnvOrDie(kTestShardIndex, -1) : -1;
|
||||||
|
|
||||||
const PositiveAndNegativeFilter gtest_flag_filter{GTEST_FLAG_GET(filter)};
|
const PositiveAndNegativeUnitTestFilter gtest_flag_filter{GTEST_FLAG_GET(filter)};
|
||||||
const Filter disable_test_filter{kDisableTestFilter};
|
const UnitTestFilter disable_test_filter{kDisableTestFilter};
|
||||||
// num_runnable_tests are the number of tests that will
|
// num_runnable_tests are the number of tests that will
|
||||||
// run across all shards (i.e., match filter and are not disabled).
|
// run across all shards (i.e., match filter and are not disabled).
|
||||||
// num_selected_tests are the number of tests to be run on
|
// num_selected_tests are the number of tests to be run on
|
||||||
|
Loading…
Reference in New Issue
Block a user