1+ /// <reference path='harness.ts' />
2+ /// <reference path='runnerbase.ts' />
3+ /// <reference path='syntacticCleaner.ts' />
4+
5+ class Test262BaselineRunner extends RunnerBase {
6+ private static basePath = 'tests/cases/test262' ;
7+ private static helpersFilePath = 'tests/cases/test262-harness/helpers.d.ts' ;
8+ private static helperFile = {
9+ unitName : Test262BaselineRunner . helpersFilePath ,
10+ content : Harness . IO . readFile ( Test262BaselineRunner . helpersFilePath )
11+ } ;
12+ private static testFileExtensionRegex = / \. j s $ / ;
13+ private static options : ts . CompilerOptions = {
14+ allowNonTsExtensions : true ,
15+ target : ts . ScriptTarget . Latest ,
16+ module : ts . ModuleKind . CommonJS
17+ } ;
18+ private static baselineOptions : Harness . Baseline . BaselineOptions = { Subfolder : 'test262' } ;
19+
20+ private runTest ( filePath : string ) {
21+ describe ( 'test262 test for ' + filePath , ( ) => {
22+ // Mocha holds onto the closure environment of the describe callback even after the test is done.
23+ // Everything declared here should be cleared out in the "after" callback.
24+ var testState : {
25+ filename : string ;
26+ compilerResult : Harness . Compiler . CompilerResult ;
27+ inputFiles : { unitName : string ; content : string } [ ] ;
28+ } ;
29+
30+ before ( ( ) => {
31+ var content = Harness . IO . readFile ( filePath ) ;
32+ var testFilename = ts . removeFileExtension ( filePath ) . replace ( / \/ / g, '_' ) + ".test" ;
33+ var testCaseContent = Harness . TestCaseParser . makeUnitsFromTest ( content , testFilename ) ;
34+
35+ var inputFiles = testCaseContent . testUnitData . map ( unit => {
36+ return { unitName : Test262BaselineRunner . basePath + "/" + unit . name , content : unit . content } ;
37+ } ) ;
38+
39+ // Emit the results
40+ testState = {
41+ filename : testFilename ,
42+ inputFiles : inputFiles ,
43+ compilerResult : undefined ,
44+ } ;
45+
46+ Harness . Compiler . getCompiler ( ) . compileFiles ( [ Test262BaselineRunner . helperFile ] . concat ( inputFiles ) , /*otherFiles*/ [ ] , compilerResult => {
47+ testState . compilerResult = compilerResult ;
48+ } , /*settingsCallback*/ undefined , Test262BaselineRunner . options ) ;
49+ } ) ;
50+
51+ after ( ( ) => {
52+ testState = undefined ;
53+ } ) ;
54+
55+ it ( 'has the expected emitted code' , ( ) => {
56+ Harness . Baseline . runBaseline ( 'has the expected emitted code' , testState . filename + '.output.js' , ( ) => {
57+ var files = testState . compilerResult . files . filter ( f => f . fileName !== Test262BaselineRunner . helpersFilePath ) ;
58+ return RWC . collateOutputs ( files , s => SyntacticCleaner . clean ( s ) ) ;
59+ } , false , Test262BaselineRunner . baselineOptions ) ;
60+ } ) ;
61+
62+ it ( 'has the expected errors' , ( ) => {
63+ Harness . Baseline . runBaseline ( 'has the expected errors' , testState . filename + '.errors.txt' , ( ) => {
64+ var errors = testState . compilerResult . errors ;
65+ if ( errors . length === 0 ) {
66+ return null ;
67+ }
68+
69+ return Harness . Compiler . getErrorBaseline ( testState . inputFiles , errors ) ;
70+ } , false , Test262BaselineRunner . baselineOptions ) ;
71+ } ) ;
72+ } ) ;
73+ }
74+
75+ public initializeTests ( ) {
76+ // this will set up a series of describe/it blocks to run between the setup and cleanup phases
77+ if ( this . tests . length === 0 ) {
78+ var testFiles = this . enumerateFiles ( Test262BaselineRunner . basePath , Test262BaselineRunner . testFileExtensionRegex , { recursive : true } ) ;
79+ testFiles . forEach ( fn => {
80+ this . runTest ( ts . normalizePath ( fn ) ) ;
81+ } ) ;
82+ }
83+ else {
84+ this . tests . forEach ( test => this . runTest ( test ) ) ;
85+ }
86+ }
87+ }
0 commit comments