@@ -12,6 +12,10 @@ const enum CompilerTestType {
1212 Test262
1313}
1414
15+ interface CompilerFileBasedTest extends Harness . FileBasedTest {
16+ payload ?: Harness . TestCaseParser . TestCaseContent ;
17+ }
18+
1519class CompilerBaselineRunner extends RunnerBase {
1620 private basePath = "tests/cases" ;
1721 private testSuiteName : TestRunnerKind ;
@@ -42,7 +46,8 @@ class CompilerBaselineRunner extends RunnerBase {
4246 }
4347
4448 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 ) ;
4651 }
4752
4853 public initializeTests ( ) {
@@ -52,24 +57,32 @@ class CompilerBaselineRunner extends RunnerBase {
5257 } ) ;
5358
5459 // 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+ } ) ;
5765 } ) ;
5866 }
5967
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+ } ) ;
6474 } ) ;
6575 }
76+ describe ( `${ this . testSuiteName } tests for ${ fileName } }` , ( ) => {
77+ this . runSuite ( fileName , test ) ;
78+ } ) ;
6679 }
6780
68- private runSuite ( fileName : string , testCaseContent : Harness . TestCaseParser . TestCaseContent ) {
81+ private runSuite ( fileName : string , test ?: CompilerFileBasedTest , configuration ?: Harness . FileBasedTestConfiguration ) {
6982 // Mocha holds onto the closure environment of the describe callback even after the test is done.
7083 // Everything declared here should be cleared out in the "after" callback.
7184 let compilerTest : CompilerTest | undefined ;
72- before ( ( ) => { compilerTest = new CompilerTest ( fileName , testCaseContent ) ; } ) ;
85+ before ( ( ) => { compilerTest = new CompilerTest ( fileName , test && test . payload , configuration ) ; } ) ;
7386 it ( `Correct errors for ${ fileName } ` , ( ) => { compilerTest . verifyDiagnostics ( ) ; } ) ;
7487 it ( `Correct module resolution tracing for ${ fileName } ` , ( ) => { compilerTest . verifyModuleResolution ( ) ; } ) ;
7588 it ( `Correct sourcemap content for ${ fileName } ` , ( ) => { compilerTest . verifySourceMapRecord ( ) ; } ) ;
@@ -97,11 +110,6 @@ class CompilerBaselineRunner extends RunnerBase {
97110 }
98111}
99112
100- interface CompilerTestConfiguration {
101- name : string ;
102- payload : Harness . TestCaseParser . TestCaseContent ;
103- }
104-
105113class CompilerTest {
106114 private fileName : string ;
107115 private justName : string ;
@@ -116,10 +124,20 @@ class CompilerTest {
116124 // equivalent to other files on the file system not directly passed to the compiler (ie things that are referenced by other files)
117125 private otherFiles : Harness . Compiler . TestFile [ ] ;
118126
119- constructor ( fileName : string , testCaseContent : Harness . TestCaseParser . TestCaseContent ) {
127+ constructor ( fileName : string , testCaseContent ? : Harness . TestCaseParser . TestCaseContent , configurationOverrides ?: Harness . TestCaseParser . CompilerSettings ) {
120128 this . fileName = fileName ;
121129 this . justName = vpath . basename ( fileName ) ;
130+
122131 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+
123141 const units = testCaseContent . testUnitData ;
124142 this . harnessSettings = testCaseContent . settings ;
125143 let tsConfigOptions : ts . CompilerOptions ;
@@ -174,32 +192,14 @@ class CompilerTest {
174192 this . options = this . result . options ;
175193 }
176194
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 } ;
203203 }
204204
205205 public verifyDiagnostics ( ) {
@@ -267,11 +267,6 @@ class CompilerTest {
267267 this . toBeCompiled . concat ( this . otherFiles ) . filter ( file => ! ! this . result . program . getSourceFile ( file . unitName ) ) ) ;
268268 }
269269
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-
275270 private makeUnitName ( name : string , root : string ) {
276271 const path = ts . toPath ( name , root , ts . identity ) ;
277272 const pathStart = ts . toPath ( Harness . IO . getCurrentDirectory ( ) , "" , ts . identity ) ;
0 commit comments