@@ -12,6 +12,10 @@ const enum CompilerTestType {
12
12
Test262
13
13
}
14
14
15
+ interface CompilerFileBasedTest extends Harness . FileBasedTest {
16
+ payload ?: Harness . TestCaseParser . TestCaseContent ;
17
+ }
18
+
15
19
class CompilerBaselineRunner extends RunnerBase {
16
20
private basePath = "tests/cases" ;
17
21
private testSuiteName : TestRunnerKind ;
@@ -42,7 +46,8 @@ class CompilerBaselineRunner extends RunnerBase {
42
46
}
43
47
44
48
public enumerateTestFiles ( ) {
45
- return this . enumerateFiles ( this . basePath , / \. t s x ? $ / , { recursive : true } ) ;
49
+ // see also: `enumerateTestFiles` in tests/webTestServer.ts
50
+ return this . enumerateFiles ( this . basePath , / \. t s x ? $ / , { recursive : true } ) . map ( CompilerTest . getConfigurations ) ;
46
51
}
47
52
48
53
public initializeTests ( ) {
@@ -52,24 +57,32 @@ class CompilerBaselineRunner extends RunnerBase {
52
57
} ) ;
53
58
54
59
// this will set up a series of describe/it blocks to run between the setup and cleanup phases
55
- const files = this . tests . length > 0 ? this . tests : this . enumerateTestFiles ( ) ;
56
- files . forEach ( file => { this . checkTestCodeOutput ( vpath . normalizeSeparators ( file ) ) ; } ) ;
60
+ const files = this . tests . length > 0 ? this . tests : Harness . IO . enumerateTestFiles ( this ) ;
61
+ files . forEach ( test => {
62
+ const file = typeof test === "string" ? test : test . file ;
63
+ this . checkTestCodeOutput ( vpath . normalizeSeparators ( file ) , typeof test === "string" ? CompilerTest . getConfigurations ( test ) : test ) ;
64
+ } ) ;
57
65
} ) ;
58
66
}
59
67
60
- public checkTestCodeOutput ( fileName : string ) {
61
- for ( const { name, payload } of CompilerTest . getConfigurations ( fileName ) ) {
62
- describe ( `${ this . testSuiteName } tests for ${ fileName } ${ name ? ` (${ name } )` : `` } ` , ( ) => {
63
- this . runSuite ( fileName , payload ) ;
68
+ public checkTestCodeOutput ( fileName : string , test ?: CompilerFileBasedTest ) {
69
+ if ( test && test . configurations ) {
70
+ test . configurations . forEach ( configuration => {
71
+ describe ( `${ this . testSuiteName } tests for ${ fileName } ${ configuration ? ` (${ Harness . getFileBasedTestConfigurationDescription ( configuration ) } )` : `` } ` , ( ) => {
72
+ this . runSuite ( fileName , test , configuration ) ;
73
+ } ) ;
64
74
} ) ;
65
75
}
76
+ describe ( `${ this . testSuiteName } tests for ${ fileName } }` , ( ) => {
77
+ this . runSuite ( fileName , test ) ;
78
+ } ) ;
66
79
}
67
80
68
- private runSuite ( fileName : string , testCaseContent : Harness . TestCaseParser . TestCaseContent ) {
81
+ private runSuite ( fileName : string , test ?: CompilerFileBasedTest , configuration ?: Harness . FileBasedTestConfiguration ) {
69
82
// Mocha holds onto the closure environment of the describe callback even after the test is done.
70
83
// Everything declared here should be cleared out in the "after" callback.
71
84
let compilerTest : CompilerTest | undefined ;
72
- before ( ( ) => { compilerTest = new CompilerTest ( fileName , testCaseContent ) ; } ) ;
85
+ before ( ( ) => { compilerTest = new CompilerTest ( fileName , test && test . payload , configuration ) ; } ) ;
73
86
it ( `Correct errors for ${ fileName } ` , ( ) => { compilerTest . verifyDiagnostics ( ) ; } ) ;
74
87
it ( `Correct module resolution tracing for ${ fileName } ` , ( ) => { compilerTest . verifyModuleResolution ( ) ; } ) ;
75
88
it ( `Correct sourcemap content for ${ fileName } ` , ( ) => { compilerTest . verifySourceMapRecord ( ) ; } ) ;
@@ -97,11 +110,6 @@ class CompilerBaselineRunner extends RunnerBase {
97
110
}
98
111
}
99
112
100
- interface CompilerTestConfiguration {
101
- name : string ;
102
- payload : Harness . TestCaseParser . TestCaseContent ;
103
- }
104
-
105
113
class CompilerTest {
106
114
private fileName : string ;
107
115
private justName : string ;
@@ -116,10 +124,20 @@ class CompilerTest {
116
124
// equivalent to other files on the file system not directly passed to the compiler (ie things that are referenced by other files)
117
125
private otherFiles : Harness . Compiler . TestFile [ ] ;
118
126
119
- constructor ( fileName : string , testCaseContent : Harness . TestCaseParser . TestCaseContent ) {
127
+ constructor ( fileName : string , testCaseContent ? : Harness . TestCaseParser . TestCaseContent , configurationOverrides ?: Harness . TestCaseParser . CompilerSettings ) {
120
128
this . fileName = fileName ;
121
129
this . justName = vpath . basename ( fileName ) ;
130
+
122
131
const rootDir = fileName . indexOf ( "conformance" ) === - 1 ? "tests/cases/compiler/" : ts . getDirectoryPath ( fileName ) + "/" ;
132
+
133
+ if ( testCaseContent === undefined ) {
134
+ testCaseContent = Harness . TestCaseParser . makeUnitsFromTest ( Harness . IO . readFile ( fileName ) , fileName , rootDir ) ;
135
+ }
136
+
137
+ if ( configurationOverrides ) {
138
+ testCaseContent = { ...testCaseContent , settings : { ...testCaseContent . settings , ...configurationOverrides } } ;
139
+ }
140
+
123
141
const units = testCaseContent . testUnitData ;
124
142
this . harnessSettings = testCaseContent . settings ;
125
143
let tsConfigOptions : ts . CompilerOptions ;
@@ -174,32 +192,14 @@ class CompilerTest {
174
192
this . options = this . result . options ;
175
193
}
176
194
177
- public static getConfigurations ( fileName : string ) {
178
- const content = Harness . IO . readFile ( fileName ) ;
179
- const rootDir = fileName . indexOf ( "conformance" ) === - 1 ? "tests/cases/compiler/" : ts . getDirectoryPath ( fileName ) + "/" ;
180
- const testCaseContent = Harness . TestCaseParser . makeUnitsFromTest ( content , fileName , rootDir ) ;
181
- const configurations : CompilerTestConfiguration [ ] = [ ] ;
182
- const scriptTargets = this . _split ( testCaseContent . settings . target ) ;
183
- const moduleKinds = this . _split ( testCaseContent . settings . module ) ;
184
- for ( const scriptTarget of scriptTargets ) {
185
- for ( const moduleKind of moduleKinds ) {
186
- let name = "" ;
187
- if ( moduleKinds . length > 1 ) {
188
- name += `@module: ${ moduleKind || "none" } ` ;
189
- }
190
- if ( scriptTargets . length > 1 ) {
191
- if ( name ) name += ", " ;
192
- name += `@target: ${ scriptTarget || "none" } ` ;
193
- }
194
-
195
- const settings = { ...testCaseContent . settings } ;
196
- if ( scriptTarget ) settings . target = scriptTarget ;
197
- if ( moduleKind ) settings . module = moduleKind ;
198
- configurations . push ( { name, payload : { ...testCaseContent , settings } } ) ;
199
- }
200
- }
201
-
202
- return configurations ;
195
+ public static getConfigurations ( file : string ) : CompilerFileBasedTest {
196
+ // also see `parseCompilerTestConfigurations` in tests/webTestServer.ts
197
+ const content = Harness . IO . readFile ( file ) ;
198
+ const rootDir = file . indexOf ( "conformance" ) === - 1 ? "tests/cases/compiler/" : ts . getDirectoryPath ( file ) + "/" ;
199
+ const payload = Harness . TestCaseParser . makeUnitsFromTest ( content , file , rootDir ) ;
200
+ const settings = Harness . TestCaseParser . extractCompilerSettings ( content ) ;
201
+ const configurations = Harness . getFileBasedTestConfigurations ( settings , /*varyBy*/ [ "module" , "target" ] ) ;
202
+ return { file, payload, configurations } ;
203
203
}
204
204
205
205
public verifyDiagnostics ( ) {
@@ -267,11 +267,6 @@ class CompilerTest {
267
267
this . toBeCompiled . concat ( this . otherFiles ) . filter ( file => ! ! this . result . program . getSourceFile ( file . unitName ) ) ) ;
268
268
}
269
269
270
- private static _split ( text : string ) {
271
- const entries = text && text . split ( "," ) . map ( s => s . toLowerCase ( ) . trim ( ) ) . filter ( s => s . length > 0 ) ;
272
- return entries && entries . length > 0 ? entries : [ "" ] ;
273
- }
274
-
275
270
private makeUnitName ( name : string , root : string ) {
276
271
const path = ts . toPath ( name , root , ts . identity ) ;
277
272
const pathStart = ts . toPath ( Harness . IO . getCurrentDirectory ( ) , "" , ts . identity ) ;
0 commit comments