summaryrefslogtreecommitdiffstats
path: root/src/ninja_test.cc
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-09-18 04:22:49 (GMT)
committerNico Weber <nicolasweber@gmx.de>2014-09-18 04:58:02 (GMT)
commit954669e9c53301989af3a05bbd69564a3eb41bec (patch)
tree4686764085dffeaadba0ea4c774646cdf2c7c549 /src/ninja_test.cc
parentd5bddeafc6bde19724f666617c1bc07f53d217c8 (diff)
downloadNinja-954669e9c53301989af3a05bbd69564a3eb41bec.zip
Ninja-954669e9c53301989af3a05bbd69564a3eb41bec.tar.gz
Ninja-954669e9c53301989af3a05bbd69564a3eb41bec.tar.bz2
Don't support ? and : for --gtest-filter, a bit simpler.
Let me know if you use these!
Diffstat (limited to 'src/ninja_test.cc')
-rw-r--r--src/ninja_test.cc34
1 files changed, 11 insertions, 23 deletions
diff --git a/src/ninja_test.cc b/src/ninja_test.cc
index 31c2e1f..54d8784 100644
--- a/src/ninja_test.cc
+++ b/src/ninja_test.cc
@@ -61,18 +61,15 @@ void Usage() {
"usage: ninja_tests [options]\n"
"\n"
"options:\n"
-" --gtest_filter=POSTIVE_PATTERNS[-NEGATIVE_PATTERNS]\n"
-" Run only the tests whose name matches one of the positive patterns but\n"
-" none of the negative patterns. '?' matches any single character; '*'\n"
-" matches any substring; ':' separates two patterns.\n");
+" --gtest_filter=POSTIVE_PATTERN[-NEGATIVE_PATTERN]\n"
+" Run tests whose names match the positive but not the negative pattern.\n"
+" '*' matches any substring. (gtest's ':', '?' are not implemented).\n");
}
bool PatternMatchesString(const char* pattern, const char* str) {
switch (*pattern) {
case '\0':
- case '-':
- case ':': return *str == '\0';
- case '?': return *str != '\0' && PatternMatchesString(pattern + 1, str + 1);
+ case '-': return *str == '\0';
case '*': return (*str != '\0' && PatternMatchesString(pattern, str + 1)) ||
PatternMatchesString(pattern + 1, str);
default: return *pattern == *str &&
@@ -80,23 +77,12 @@ bool PatternMatchesString(const char* pattern, const char* str) {
}
}
-bool MatchesFilter(const char* name, const char* filter) {
- for (const char* cur_pattern = filter - 1; cur_pattern != NULL;
- cur_pattern = strchr(cur_pattern, ':')) {
- cur_pattern++; // Skip the pattern separator (the ':' character).
- if (PatternMatchesString(cur_pattern, name))
- return true;
- }
- return false;
-}
-
bool TestMatchesFilter(const char* test, const char* filter) {
// Split --gtest_filter at '-' into positive and negative filters.
const char* const dash = strchr(filter, '-');
- const char* positive = // Treat '-test1' as '*-test1':
- dash == filter ? "*" : filter;
- const char* negative = dash ? dash + 1 : "";
- return MatchesFilter(test, positive) && !MatchesFilter(test, negative);
+ const char* pos = dash == filter ? "*" : filter; //Treat '-test1' as '*-test1'
+ const char* neg = dash ? dash + 1 : "";
+ return PatternMatchesString(pos, test) && !PatternMatchesString(neg, test);
}
bool ReadFlags(int* argc, char*** argv, const char** test_filter) {
@@ -110,8 +96,10 @@ bool ReadFlags(int* argc, char*** argv, const char** test_filter) {
while ((opt = getopt_long(*argc, *argv, "h", kLongOptions, NULL)) != -1) {
switch (opt) {
case OPT_GTEST_FILTER:
- *test_filter = optarg;
- break;
+ if (strchr(optarg, '?') == NULL && strchr(optarg, ':') == NULL) {
+ *test_filter = optarg;
+ break;
+ } // else fall through.
default:
Usage();
return false;