Skip to content

Commit 2be88a3

Browse files
committed
Add support for -DexclusiveSpecTest=<TestName> to SpecTestCase.
1 parent 84ab316 commit 2be88a3

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.firestore.spec;
1616

17+
import static com.google.common.base.Strings.emptyToNull;
1718
import static com.google.firebase.firestore.TestUtil.waitFor;
1819
import static com.google.firebase.firestore.testutil.TestUtil.ARBITRARY_SEQUENCE_NUMBER;
1920
import static com.google.firebase.firestore.testutil.TestUtil.deleteMutation;
@@ -132,6 +133,14 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
132133
// this tag and they'll all be run (but all others won't).
133134
private static final String EXCLUSIVE_TAG = "exclusive";
134135

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";
143+
135144
// Tags on tests that should be excluded from execution, useful to allow the platforms to
136145
// temporarily diverge or for features that are designed to be platform specific (such as
137146
// 'multi-client').
@@ -1097,6 +1106,12 @@ public void testSpecTests() throws Exception {
10971106
parsedSpecFiles.add(new Pair<>(f.getName(), fileJSON));
10981107
}
10991108

1109+
String exclusiveTestNameFromSystemProperty =
1110+
emptyToNull(System.getProperty(EXCLUSIVE_PROPERTY));
1111+
if (exclusiveTestNameFromSystemProperty != null) {
1112+
exclusiveMode = true;
1113+
}
1114+
11001115
for (Pair<String, JSONObject> parsedSpecFile : parsedSpecFiles) {
11011116
String fileName = parsedSpecFile.first;
11021117
JSONObject fileJSON = parsedSpecFile.second;
@@ -1115,7 +1130,17 @@ public void testSpecTests() throws Exception {
11151130
JSONArray steps = testJSON.getJSONArray("steps");
11161131
Set<String> tags = getTestTags(testJSON);
11171132

1118-
boolean runTest = shouldRunTest(tags) && (!exclusiveMode || tags.contains(EXCLUSIVE_TAG));
1133+
boolean runTest;
1134+
if (!shouldRunTest(tags)) {
1135+
runTest = false;
1136+
} else if (!exclusiveMode) {
1137+
runTest = true;
1138+
} else if (tags.contains(EXCLUSIVE_TAG)) {
1139+
runTest = true;
1140+
} else {
1141+
runTest = name.equals(exclusiveTestNameFromSystemProperty);
1142+
}
1143+
11191144
boolean measureRuntime = tags.contains(BENCHMARK_TAG);
11201145
if (runTest) {
11211146
long start = System.currentTimeMillis();

0 commit comments

Comments
 (0)