Skip to content

Commit 81f3bb7

Browse files
committed
Use a regex instead of an exact match for spec test filtering.
1 parent 2be88a3 commit 81f3bb7

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

firebase-firestore/src/test/java/com/google/firebase/firestore/spec/SpecTestCase.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import java.util.Map;
9595
import java.util.Set;
9696
import java.util.logging.Logger;
97+
import java.util.regex.Pattern;
9798
import java.util.stream.Stream;
9899
import javax.annotation.Nullable;
99100
import org.json.JSONArray;
@@ -133,13 +134,15 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
133134
// this tag and they'll all be run (but all others won't).
134135
private static final String EXCLUSIVE_TAG = "exclusive";
135136

136-
// The name of a Java system property ({@link System#getProperty(String)}) whose value is the name
137-
// of the sole spec test to execute. This is an alternative to setting the {@link #EXCLUSIVE_TAG}
138-
// tag, which requires modifying the JSON file. To use this property, specify
139-
// -DexclusiveSpecTest=<TestName> to the Java runtime, replacing <TestName> with the name of the
140-
// test to execute exclusively. The <TestName> value is the result of appending the "itName" of
141-
// the test to its "describeName", separated by a space character.
142-
private static final String EXCLUSIVE_PROPERTY = "exclusiveSpecTest";
137+
// The name of a Java system property ({@link System#getProperty(String)}) whose value is a filter
138+
// that specifies which tests to execute. The value of this property is a regular expression that
139+
// is matched against the name of each test. Using this property is an alternative to setting the
140+
// {@link #EXCLUSIVE_TAG} tag, which requires modifying the JSON file. To use this property,
141+
// specify -DspecTestFilter=<Regex> to the Java runtime, replacing <Regex> with a regular
142+
// expression; a test will be executed if and only if its name matches this regular expression.
143+
// In this context, a test's "name" is the result of appending its "itName" to its "describeName",
144+
// separated by a space character.
145+
private static final String TEST_FILTER_PROPERTY = "specTestFilter";
143146

144147
// Tags on tests that should be excluded from execution, useful to allow the platforms to
145148
// temporarily diverge or for features that are designed to be platform specific (such as
@@ -1106,10 +1109,14 @@ public void testSpecTests() throws Exception {
11061109
parsedSpecFiles.add(new Pair<>(f.getName(), fileJSON));
11071110
}
11081111

1109-
String exclusiveTestNameFromSystemProperty =
1110-
emptyToNull(System.getProperty(EXCLUSIVE_PROPERTY));
1111-
if (exclusiveTestNameFromSystemProperty != null) {
1112+
String testNameFilterFromSystemProperty =
1113+
emptyToNull(System.getProperty(TEST_FILTER_PROPERTY));
1114+
Pattern testNameFilter;
1115+
if (testNameFilterFromSystemProperty == null) {
1116+
testNameFilter = null;
1117+
} else {
11121118
exclusiveMode = true;
1119+
testNameFilter = Pattern.compile(testNameFilterFromSystemProperty);
11131120
}
11141121

11151122
for (Pair<String, JSONObject> parsedSpecFile : parsedSpecFiles) {
@@ -1137,8 +1144,10 @@ public void testSpecTests() throws Exception {
11371144
runTest = true;
11381145
} else if (tags.contains(EXCLUSIVE_TAG)) {
11391146
runTest = true;
1147+
} else if (testNameFilter != null) {
1148+
runTest = testNameFilter.matcher(name).find();
11401149
} else {
1141-
runTest = name.equals(exclusiveTestNameFromSystemProperty);
1150+
runTest = false;
11421151
}
11431152

11441153
boolean measureRuntime = tags.contains(BENCHMARK_TAG);

0 commit comments

Comments
 (0)