Skip to content

Commit fc842eb

Browse files
lauraharkercopybara-github
authored andcommitted
Support aggregating multiple .addExterns() calls TypeCheckTestCase
PiperOrigin-RevId: 781078234
1 parent 6d88a32 commit fc842eb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

test/com/google/javascript/jscomp/TypeCheckTestCase.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.javascript.jscomp;
1818

1919
import static com.google.common.base.Preconditions.checkState;
20-
import static com.google.common.base.Strings.nullToEmpty;
2120
import static com.google.common.truth.Truth.assertThat;
2221
import static com.google.common.truth.Truth.assertWithMessage;
2322
import static com.google.javascript.jscomp.testing.JSCompCorrespondences.DESCRIPTION_EQUALITY;
@@ -122,12 +121,13 @@ final TypeTestBuilder newTest() {
122121
@CheckReturnValue
123122
public final class TypeTestBuilder {
124123
private String source;
125-
private String externs;
124+
private final List<String> externs = new ArrayList<>();
126125
private String sourceNameExtension = "";
127126
private boolean includeDefaultExterns = false;
128127
private final ArrayList<DiagnosticType> diagnosticTypes = new ArrayList<>();
129128
private final ArrayList<String> diagnosticDescriptions = new ArrayList<>();
130129
private boolean diagnosticsAreErrors = false;
130+
private boolean hasRun = false;
131131

132132
private TypeTestBuilder() {}
133133

@@ -138,8 +138,7 @@ public TypeTestBuilder addSource(String source) {
138138
}
139139

140140
public TypeTestBuilder addExterns(String externs) {
141-
checkState(this.externs == null, "Can only have one externs right now.");
142-
this.externs = externs;
141+
this.externs.add(externs);
143142
return this;
144143
}
145144

@@ -174,10 +173,13 @@ public void run() {
174173
this.diagnosticTypes.isEmpty() || this.diagnosticDescriptions.isEmpty(),
175174
"Cannot expect both diagnostic types and diagnostic descriptions");
176175
checkState(this.source != null, "Must provide source");
176+
checkState(!this.hasRun, "Cannot run the same test twice");
177+
this.hasRun = true;
178+
if (this.includeDefaultExterns) {
179+
this.externs.add(0, DEFAULT_EXTERNS);
180+
}
177181

178-
String allExterns =
179-
String.join(
180-
"\n", this.includeDefaultExterns ? DEFAULT_EXTERNS : "", nullToEmpty(this.externs));
182+
String allExterns = String.join("\n", this.externs);
181183

182184
final List<Object> diagnostics;
183185
final Correspondence<JSError, Object> correspondence;

0 commit comments

Comments
 (0)