14
14
15
15
package com .google .firebase .firestore .spec ;
16
16
17
+ import static com .google .common .base .Strings .emptyToNull ;
17
18
import static com .google .firebase .firestore .TestUtil .waitFor ;
18
19
import static com .google .firebase .firestore .testutil .TestUtil .ARBITRARY_SEQUENCE_NUMBER ;
19
20
import static com .google .firebase .firestore .testutil .TestUtil .deleteMutation ;
93
94
import java .util .Map ;
94
95
import java .util .Set ;
95
96
import java .util .logging .Logger ;
97
+ import java .util .regex .Pattern ;
96
98
import java .util .stream .Stream ;
97
99
import javax .annotation .Nullable ;
98
100
import org .json .JSONArray ;
@@ -132,6 +134,16 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
132
134
// this tag and they'll all be run (but all others won't).
133
135
private static final String EXCLUSIVE_TAG = "exclusive" ;
134
136
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" ;
146
+
135
147
// Tags on tests that should be excluded from execution, useful to allow the platforms to
136
148
// temporarily diverge or for features that are designed to be platform specific (such as
137
149
// 'multi-client').
@@ -1097,6 +1109,16 @@ public void testSpecTests() throws Exception {
1097
1109
parsedSpecFiles .add (new Pair <>(f .getName (), fileJSON ));
1098
1110
}
1099
1111
1112
+ String testNameFilterFromSystemProperty =
1113
+ emptyToNull (System .getProperty (TEST_FILTER_PROPERTY ));
1114
+ Pattern testNameFilter ;
1115
+ if (testNameFilterFromSystemProperty == null ) {
1116
+ testNameFilter = null ;
1117
+ } else {
1118
+ exclusiveMode = true ;
1119
+ testNameFilter = Pattern .compile (testNameFilterFromSystemProperty );
1120
+ }
1121
+
1100
1122
for (Pair <String , JSONObject > parsedSpecFile : parsedSpecFiles ) {
1101
1123
String fileName = parsedSpecFile .first ;
1102
1124
JSONObject fileJSON = parsedSpecFile .second ;
@@ -1115,7 +1137,19 @@ public void testSpecTests() throws Exception {
1115
1137
JSONArray steps = testJSON .getJSONArray ("steps" );
1116
1138
Set <String > tags = getTestTags (testJSON );
1117
1139
1118
- boolean runTest = shouldRunTest (tags ) && (!exclusiveMode || tags .contains (EXCLUSIVE_TAG ));
1140
+ boolean runTest ;
1141
+ if (!shouldRunTest (tags )) {
1142
+ runTest = false ;
1143
+ } else if (!exclusiveMode ) {
1144
+ runTest = true ;
1145
+ } else if (tags .contains (EXCLUSIVE_TAG )) {
1146
+ runTest = true ;
1147
+ } else if (testNameFilter != null ) {
1148
+ runTest = testNameFilter .matcher (name ).find ();
1149
+ } else {
1150
+ runTest = false ;
1151
+ }
1152
+
1119
1153
boolean measureRuntime = tags .contains (BENCHMARK_TAG );
1120
1154
if (runTest ) {
1121
1155
long start = System .currentTimeMillis ();
0 commit comments