Skip to content

Commit 6c6d9bf

Browse files
committed
Add test262 test runner
1 parent 0629bba commit 6c6d9bf

8 files changed

Lines changed: 110 additions & 22 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tests/cases/*/*/*.js.map
1111
tests/cases/*/*/*/*.js.map
1212
tests/cases/*/*/*/*/*.js.map
1313
tests/cases/rwc/*
14+
tests/cases/test262/*
1415
tests/cases/perf/*
1516
!tests/cases/webharness/compilerToString.js
1617
test-args.txt
@@ -19,6 +20,7 @@ tests/baselines/local/*
1920
tests/services/baselines/local/*
2021
tests/baselines/prototyping/local/*
2122
tests/baselines/rwc/*
23+
tests/baselines/test262/*
2224
tests/services/baselines/prototyping/local/*
2325
tests/services/browser/typescriptServices.js
2426
scripts/processDiagnosticMessages.d.ts

Jakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ var harnessSources = [
7878
"projectsRunner.ts",
7979
"loggedIO.ts",
8080
"rwcRunner.ts",
81+
"test262Runner.ts",
8182
"runner.ts"
8283
].map(function (f) {
8384
return path.join(harnessDirectory, f);
@@ -347,6 +348,9 @@ var refBaseline = "tests/baselines/reference/";
347348
var localRwcBaseline = "tests/baselines/rwc/local/";
348349
var refRwcBaseline = "tests/baselines/rwc/reference/";
349350

351+
var localTest262Baseline = "tests/baselines/test262/local/";
352+
var refTest262Baseline = "tests/baselines/test262/reference/";
353+
350354
desc("Builds the test infrastructure using the built compiler");
351355
task("tests", ["local", run].concat(libraryTargets));
352356

@@ -515,6 +519,12 @@ task("baseline-accept-rwc", function() {
515519
fs.renameSync(localRwcBaseline, refRwcBaseline);
516520
});
517521

522+
desc("Makes the most recent test262 test results the new baseline, overwriting the old baseline");
523+
task("baseline-accept-test262", function() {
524+
jake.rmRf(refTest262Baseline);
525+
fs.renameSync(localTest262Baseline, refTest262Baseline);
526+
});
527+
518528

519529
// Webhost
520530
var webhostPath = "tests/webhost/webtsc.ts";

src/harness/compilerRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const enum CompilerTestType {
1010
}
1111

1212
class CompilerBaselineRunner extends RunnerBase {
13-
protected basePath = 'tests/cases';
13+
private basePath = 'tests/cases';
1414
private errors: boolean;
1515
private emit: boolean;
1616
private decl: boolean;

src/harness/harness.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,8 @@ module Harness {
537537

538538
export var defaultLibFileName = 'lib.d.ts';
539539
export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*version:*/ "0");
540+
export var defaultES6LibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*version:*/ "0");
541+
540542

541543
// Cache these between executions so we don't have to re-parse them for every test
542544
export var fourslashFilename = 'fourslash.ts';
@@ -579,9 +581,8 @@ module Harness {
579581
return fourslashSourceFile;
580582
}
581583
else {
582-
var lib = defaultLibFileName;
583584
if (fn === defaultLibFileName) {
584-
return defaultLibSourceFile;
585+
return languageVersion === ts.ScriptTarget.ES6 ? defaultES6LibSourceFile : defaultLibSourceFile;
585586
}
586587
// Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
587588
return null;
@@ -799,7 +800,6 @@ module Harness {
799800
checker.checkProgram();
800801

801802
var hasEarlyErrors = checker.hasEarlyErrors();
802-
803803
// only emit if there weren't parse errors
804804
var emitResult: ts.EmitResult;
805805
if (!hadParseErrors && !hasEarlyErrors) {
@@ -1009,20 +1009,6 @@ module Harness {
10091009
sys.newLine + sys.newLine + outputLines.join('\r\n');
10101010
}
10111011

1012-
/* TODO: Delete?
1013-
export function makeDefaultCompilerSettings(options?: { useMinimalDefaultLib: boolean; noImplicitAny: boolean; }) {
1014-
var useMinimalDefaultLib = options ? options.useMinimalDefaultLib : true;
1015-
var noImplicitAny = options ? options.noImplicitAny : false;
1016-
var settings = new TypeScript.CompilationSettings();
1017-
settings.codeGenTarget = TypeScript.LanguageVersion.EcmaScript5;
1018-
settings.moduleGenTarget = TypeScript.ModuleGenTarget.Synchronous;
1019-
settings.noLib = useMinimalDefaultLib;
1020-
settings.noResolve = false;
1021-
settings.noImplicitAny = noImplicitAny;
1022-
return settings;
1023-
}
1024-
*/
1025-
10261012
/** The harness' compiler instance used when tests are actually run. Reseting or changing settings of this compiler instance must be done within a test case (i.e., describe/it) */
10271013
var harnessCompiler: HarnessCompiler;
10281014

src/harness/projectsRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class ProjectRunner extends RunnerBase {
169169
function getSourceFile(filename: string, languageVersion: ts.ScriptTarget): ts.SourceFile {
170170
var sourceFile: ts.SourceFile = undefined;
171171
if (filename === Harness.Compiler.defaultLibFileName) {
172-
sourceFile = Harness.Compiler.defaultLibSourceFile;
172+
sourceFile = languageVersion === ts.ScriptTarget.ES6 ? Harness.Compiler.defaultES6LibSourceFile : Harness.Compiler.defaultLibSourceFile;
173173
}
174174
else {
175175
var text = getSourceFileText(filename);

src/harness/runner.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// limitations under the License.
1414
//
1515

16+
/// <reference path='test262Runner.ts' />
1617
/// <reference path='compilerRunner.ts' />
17-
// TODO: re-enable
18-
// ///<reference path='fourslashRunner.ts' />
18+
/// <reference path='fourslashRunner.ts' />
1919
/// <reference path='projectsRunner.ts' />
2020
/// <reference path='rwcRunner.ts' />
2121

@@ -69,6 +69,9 @@ if (testConfigFile !== '') {
6969
case 'rwc':
7070
runners.push(new RWCRunner());
7171
break;
72+
case 'test262':
73+
runners.push(new Test262BaselineRunner());
74+
break;
7275
case 'reverse':
7376
reverse = true;
7477
break;

src/harness/rwcRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module RWC {
2020
}
2121
}
2222

23-
function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) {
23+
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) {
2424
// Collect, test, and sort the filenames
2525
function cleanName(fn: string) {
2626
var lastSlash = ts.normalizeSlashes(fn).lastIndexOf('/');

src/harness/test262Runner.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 = /\.js$/;
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

Comments
 (0)