From 883abbf1d92dd76e17ef35878b3d5b2f10e57e71 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Apr 2015 16:50:35 -0700 Subject: [PATCH 1/4] Jakefile -> Jakefile.js --- Jakefile => Jakefile.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Jakefile => Jakefile.js (100%) diff --git a/Jakefile b/Jakefile.js similarity index 100% rename from Jakefile rename to Jakefile.js From ebe17b107fa207441b4c89b7508b0618e213182a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Apr 2015 16:54:13 -0700 Subject: [PATCH 2/4] Remove global.runners. --- src/harness/runner.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/harness/runner.ts b/src/harness/runner.ts index e1e5429b007..fb4b344eb11 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -31,7 +31,6 @@ function runTests(runners: RunnerBase[]) { } var runners: RunnerBase[] = []; -global.runners = runners; var reverse: boolean = false; var iterations: number = 1; From f3b28c4a2ac03b0b153d1b9404ee4266bc6262b2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 27 Apr 2015 16:55:53 -0700 Subject: [PATCH 3/4] Remove 'reverse' option. --- src/harness/runner.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/harness/runner.ts b/src/harness/runner.ts index fb4b344eb11..37451639d75 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -20,9 +20,6 @@ /// function runTests(runners: RunnerBase[]) { - if (reverse) { - runners = runners.reverse(); - } for (var i = iterations; i > 0; i--) { for (var j = 0; j < runners.length; j++) { runners[j].initializeTests(); @@ -31,7 +28,6 @@ function runTests(runners: RunnerBase[]) { } var runners: RunnerBase[] = []; -var reverse: boolean = false; var iterations: number = 1; // users can define tests to run in mytest.config that will override cmd line args, otherwise use cmd line args (test.config), otherwise no options @@ -77,9 +73,6 @@ if (testConfigFile !== '') { case 'test262': runners.push(new Test262BaselineRunner()); break; - case 'reverse': - reverse = true; - break; } } } From 97cd07d1d432daae2d85254d9f331846ae886e7f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 28 Apr 2015 17:20:38 -0700 Subject: [PATCH 4/4] Cache the emit of 'fourslash.ts'. Yields a >25% decrease in running time for fourslash tests on my machine. --- src/compiler/program.ts | 6 +++--- src/harness/fourslash.ts | 44 +++++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 3b34e434472..cdffe8e9208 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -102,11 +102,11 @@ module ts { }; } - export function getPreEmitDiagnostics(program: Program): Diagnostic[] { - let diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics()); + export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile): Diagnostic[] { + let diagnostics = program.getSyntacticDiagnostics(sourceFile).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile)); if (program.getCompilerOptions().declaration) { - diagnostics.concat(program.getDeclarationDiagnostics()); + diagnostics.concat(program.getDeclarationDiagnostics(sourceFile)); } return sortAndDeduplicateDiagnostics(diagnostics); diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 7269b2db75d..c8f20746a07 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2192,38 +2192,62 @@ module FourSlash { xmlData.push(xml); } + // We don't want to recompile 'fourslash.ts' for every test, so + // here we cache the JS output and reuse it for every test. + let fourslashJsOutput: string; + { + let host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFileName, content: undefined }], + (fn, contents) => fourslashJsOutput = contents, + ts.ScriptTarget.Latest, + ts.sys.useCaseSensitiveFileNames); + + let program = ts.createProgram([Harness.Compiler.fourslashFileName], { noResolve: true, target: ts.ScriptTarget.ES3 }, host); + + program.emit(host.getSourceFile(Harness.Compiler.fourslashFileName, ts.ScriptTarget.ES3)); + } + + export function runFourSlashTestContent(basePath: string, testType: FourSlashTestType, content: string, fileName: string): TestXmlData { // Parse out the files and their metadata - var testData = parseTestData(basePath, content, fileName); + let testData = parseTestData(basePath, content, fileName); currentTestState = new TestState(basePath, testType, testData); - var result = ''; - var host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFileName, content: undefined }, - { unitName: fileName, content: content }], + let result = ''; + let host = Harness.Compiler.createCompilerHost( + [ + { unitName: Harness.Compiler.fourslashFileName, content: undefined }, + { unitName: fileName, content: content } + ], (fn, contents) => result = contents, ts.ScriptTarget.Latest, ts.sys.useCaseSensitiveFileNames); - // TODO (drosen): We need to enforce checking on these tests. - var program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host); - var diagnostics = ts.getPreEmitDiagnostics(program); + let program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host); + + let sourceFile = host.getSourceFile(fileName, ts.ScriptTarget.ES3); + + let diagnostics = ts.getPreEmitDiagnostics(program, sourceFile); if (diagnostics.length > 0) { throw new Error('Error compiling ' + fileName + ': ' + diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n')); } - program.emit(); + + program.emit(sourceFile); result = result || ''; // Might have an empty fourslash file + result = fourslashJsOutput + "\r\n" + result; + // Compile and execute the test try { eval(result); - } catch (err) { + } + catch (err) { // Debugging: FourSlash.currentTestState.printCurrentFileState(); throw err; } - var xmlData = currentTestState.getTestXmlData(); + let xmlData = currentTestState.getTestXmlData(); xmlData.originalName = fileName; return xmlData; }