| OLD | NEW |
| 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 Loading... |
| 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; |
| 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 for (int i = 0; i < segments.length; i++) { |
| 150 String[] filters = segments[i].split(":"); |
| 151 for (int j = 0; j < filters.length; j++) { |
| 152 if (filters[j].length() == 0) continue; |
| 153 RegExp r = convert(filters[j]); |
| 154 if (i > 0 && j == 0) { |
| 155 neg.add(r); |
| 156 } else { |
| 157 pos.add(r); |
| 158 } |
| 159 } |
| 160 } |
| 131 } | 161 } |
| 132 | 162 |
| 133 public boolean test(String className, String methodName) { | 163 public boolean test(String className, String methodName) { |
| 134 if (regexp == null) return true; | 164 boolean ans = false; |
| 135 return regexp.test(className + "." + methodName); | 165 if (pos.size() == 0) ans = true; |
| 166 for (int i = 0; i < pos.size(); i++) { |
| 167 if (pos.get(i).test(className + "." + methodName)) { |
| 168 ans = true; |
| 169 } |
| 170 } |
| 171 for (int i = 0; i < neg.size(); i++) { |
| 172 if (neg.get(i).test(className + "." + methodName)) { |
| 173 ans = false; |
| 174 } |
| 175 } |
| 176 return ans; |
| 136 } | 177 } |
| 137 } | 178 } |
| 138 | 179 |
| 139 private TreeMap<String, TestCase> testCases; | 180 private TreeMap<String, TestCase> testCases; |
| 140 | 181 |
| 141 public JsTestSuiteBase() { | 182 public JsTestSuiteBase() { |
| 142 testCases = new TreeMap<String, TestCase>(); | 183 testCases = new TreeMap<String, TestCase>(); |
| 143 debug = "1".equals(Window.Location.getParameter("debug")); | 184 debug = "1".equals(Window.Location.getParameter("debug")); |
| 144 } | 185 } |
| 145 | 186 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 240 } |
| 200 | 241 |
| 201 public static String stackFrameString(StackTraceElement ste) { | 242 public static String stackFrameString(StackTraceElement ste) { |
| 202 String mangledName = ste.getMethodName(); | 243 String mangledName = ste.getMethodName(); |
| 203 mangledName = mangledName.split("__")[0]; | 244 mangledName = mangledName.split("__")[0]; |
| 204 String demangledName = | 245 String demangledName = |
| 205 mangledName.replaceAll("_1", "~~").replaceAll("_", ".").replaceA
ll("~~", "_"); | 246 mangledName.replaceAll("_1", "~~").replaceAll("_", ".").replaceA
ll("~~", "_"); |
| 206 return demangledName + "(" + ste.getFileName() + ":" + ste.getLineNumber
() + ")"; | 247 return demangledName + "(" + ste.getFileName() + ":" + ste.getLineNumber
() + ")"; |
| 207 } | 248 } |
| 208 } | 249 } |
| OLD | NEW |