17
17
package com .google .javascript .jscomp ;
18
18
19
19
import static com .google .common .base .Preconditions .checkState ;
20
- import static com .google .common .base .Strings .nullToEmpty ;
21
20
import static com .google .common .truth .Truth .assertThat ;
22
21
import static com .google .common .truth .Truth .assertWithMessage ;
23
22
import static com .google .javascript .jscomp .testing .JSCompCorrespondences .DESCRIPTION_EQUALITY ;
@@ -122,12 +121,13 @@ final TypeTestBuilder newTest() {
122
121
@ CheckReturnValue
123
122
public final class TypeTestBuilder {
124
123
private String source ;
125
- private String externs ;
124
+ private final List < String > externs = new ArrayList <>() ;
126
125
private String sourceNameExtension = "" ;
127
126
private boolean includeDefaultExterns = false ;
128
127
private final ArrayList <DiagnosticType > diagnosticTypes = new ArrayList <>();
129
128
private final ArrayList <String > diagnosticDescriptions = new ArrayList <>();
130
129
private boolean diagnosticsAreErrors = false ;
130
+ private boolean hasRun = false ;
131
131
132
132
private TypeTestBuilder () {}
133
133
@@ -138,8 +138,7 @@ public TypeTestBuilder addSource(String source) {
138
138
}
139
139
140
140
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 );
143
142
return this ;
144
143
}
145
144
@@ -174,10 +173,13 @@ public void run() {
174
173
this .diagnosticTypes .isEmpty () || this .diagnosticDescriptions .isEmpty (),
175
174
"Cannot expect both diagnostic types and diagnostic descriptions" );
176
175
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
+ }
177
181
178
- String allExterns =
179
- String .join (
180
- "\n " , this .includeDefaultExterns ? DEFAULT_EXTERNS : "" , nullToEmpty (this .externs ));
182
+ String allExterns = String .join ("\n " , this .externs );
181
183
182
184
final List <Object > diagnostics ;
183
185
final Correspondence <JSError , Object > correspondence ;
0 commit comments