Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: javatests/org/chromium/distiller/JsTestSuiteBase.java

Issue 1047853004: Use gtest_filter syntax in jstest filter (Closed) Base URL: git@github.com:chromium/dom-distiller.git@master
Patch Set: fix logic Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.distiller; 5 package org.chromium.distiller;
6 6
7 import com.google.gwt.core.client.JavaScriptException; 7 import com.google.gwt.core.client.JavaScriptException;
8 import com.google.gwt.regexp.shared.RegExp; 8 import com.google.gwt.regexp.shared.RegExp;
9 import com.google.gwt.user.client.Window; 9 import com.google.gwt.user.client.Window;
10 10
11 import java.util.ArrayList;
12 import java.util.List;
11 import java.util.Map; 13 import java.util.Map;
12 import java.util.Set; 14 import java.util.Set;
13 import java.util.TreeMap; 15 import java.util.TreeMap;
14 16
15 public class JsTestSuiteBase { 17 public class JsTestSuiteBase {
16 private boolean debug = false; 18 private boolean debug = false;
17 19
18 public interface TestCaseRunner { 20 public interface TestCaseRunner {
19 public void run(JsTestCase testCase) throws Throwable; 21 public void run(JsTestCase testCase) throws Throwable;
20 } 22 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 120 }
119 return results; 121 return results;
120 } 122 }
121 123
122 public Set<String> getTestNames() { 124 public Set<String> getTestNames() {
123 return tests.keySet(); 125 return tests.keySet();
124 } 126 }
125 } 127 }
126 128
127 private class TestFilter { 129 private class TestFilter {
128 RegExp regexp; 130 List<RegExp> pos;
nyquist 2015/04/01 18:27:07 Nit: private final?
wychen 2015/04/01 19:05:53 Done.
131 List<RegExp> neg;
132
133 private RegExp convert(String q) {
134 // This is a simplified conversion, and doesn't handle all
135 // possible glob strings correctly.
136 q = q.replace(".", "\\.");
137 q = q.replace("*", ".*");
138 q = q.replace("?", ".");
139 return RegExp.compile("^" + q + "$");
140 }
141
129 TestFilter(String filter) { 142 TestFilter(String filter) {
130 if (filter != null) regexp = RegExp.compile(filter); 143 pos = new ArrayList<RegExp>();
144 neg = new ArrayList<RegExp>();
145
146 if (filter == null) return;
147
148 String[] segments = filter.split("-");
149 if (segments.length > 2) {
150 LogUtil.logToConsole("[ERROR] filter \"" + filter + "\" is malfo rmed.");
151 }
152 for (int i = 0; i < segments.length; i++) {
153 String[] filters = segments[i].split(":");
154 for (int j = 0; j < filters.length; j++) {
155 if (filters[j].length() == 0) continue;
156 RegExp r = convert(filters[j]);
157 if (i > 0) {
nyquist 2015/04/01 18:27:07 Could we reorder the if/else and do |if (i == 0)|
wychen 2015/04/01 19:05:53 Done.
158 neg.add(r);
159 } else {
160 pos.add(r);
161 }
162 }
163 }
131 } 164 }
132 165
133 public boolean test(String className, String methodName) { 166 public boolean test(String className, String methodName) {
134 if (regexp == null) return true; 167 boolean ans = false;
135 return regexp.test(className + "." + methodName); 168 if (pos.size() == 0) ans = true;
169 for (int i = 0; i < pos.size(); i++) {
170 if (pos.get(i).test(className + "." + methodName)) {
171 ans = true;
172 }
173 }
174 for (int i = 0; i < neg.size(); i++) {
175 if (neg.get(i).test(className + "." + methodName)) {
176 ans = false;
177 }
178 }
179 return ans;
136 } 180 }
137 } 181 }
138 182
139 private TreeMap<String, TestCase> testCases; 183 private TreeMap<String, TestCase> testCases;
140 184
141 public JsTestSuiteBase() { 185 public JsTestSuiteBase() {
142 testCases = new TreeMap<String, TestCase>(); 186 testCases = new TreeMap<String, TestCase>();
143 debug = "1".equals(Window.Location.getParameter("debug")); 187 debug = "1".equals(Window.Location.getParameter("debug"));
144 } 188 }
145 189
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 243 }
200 244
201 public static String stackFrameString(StackTraceElement ste) { 245 public static String stackFrameString(StackTraceElement ste) {
202 String mangledName = ste.getMethodName(); 246 String mangledName = ste.getMethodName();
203 mangledName = mangledName.split("__")[0]; 247 mangledName = mangledName.split("__")[0];
204 String demangledName = 248 String demangledName =
205 mangledName.replaceAll("_1", "~~").replaceAll("_", ".").replaceA ll("~~", "_"); 249 mangledName.replaceAll("_1", "~~").replaceAll("_", ".").replaceA ll("~~", "_");
206 return demangledName + "(" + ste.getFileName() + ":" + ste.getLineNumber () + ")"; 250 return demangledName + "(" + ste.getFileName() + ":" + ste.getLineNumber () + ")";
207 } 251 }
208 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698