Skip to content

Commit 66f0715

Browse files
author
Yui T
committed
Allow RWC runner to use default library instead of the one in json file
1 parent 4894fee commit 66f0715

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

src/harness/harness.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,14 @@ module Harness {
17031703
return (Path.getFileName(filePath) === 'lib.d.ts') || (Path.getFileName(filePath) === 'lib.core.d.ts');
17041704
}
17051705

1706+
export function getDefaultLibraryFile(): { unitName: string, content: string } {
1707+
var libFile = Harness.userSpecifiedroot + Harness.libFolder + "/" + "lib.d.ts";
1708+
return {
1709+
unitName: libFile,
1710+
content: IO.readFile(libFile)
1711+
}
1712+
}
1713+
17061714
if (Error) (<any>Error).stackTraceLimit = 1;
17071715
}
17081716

src/harness/loggedIO.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface IOLog {
1515
arguments: string[];
1616
executingPath: string;
1717
currentDirectory: string;
18+
useDefaultLibFile?: boolean;
1819
filesRead: {
1920
path: string;
2021
codepage: number;

src/harness/rwcRunner.ts

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module RWC {
3232
};
3333
var baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2];
3434
var currentDirectory: string;
35+
var useDefaultLibFile: boolean;
3536

3637
after(() => {
3738
// Mocha holds onto the closure environment of the describe callback even after the test is done.
@@ -43,6 +44,10 @@ module RWC {
4344
baselineOpts = undefined;
4445
baseName = undefined;
4546
currentDirectory = undefined;
47+
// useDefaultLibFile is a flag specified in the json object to indicate whether to use built/local/lib.d.ts
48+
// or to use lib.d.ts inside the json object. If the flag is true or undefine, use the build/local/lib.d.ts
49+
// otherwise use the lib.d.ts from the json object.
50+
useDefaultLibFile = undefined;
4651
});
4752

4853
it('can compile', () => {
@@ -51,32 +56,52 @@ module RWC {
5156

5257
var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath));
5358
currentDirectory = ioLog.currentDirectory;
59+
useDefaultLibFile = ioLog.useDefaultLibFile;
60+
if (useDefaultLibFile === undefined) {
61+
useDefaultLibFile = true;
62+
}
5463
runWithIOLog(ioLog, () => {
5564
opts = ts.parseCommandLine(ioLog.arguments);
5665
assert.equal(opts.errors.length, 0);
66+
67+
// To provide test coverage of output javascript file,
68+
// we will set noEmitOnError flag to be false.
69+
opts.options.noEmitOnError = false;
5770
});
5871

5972
runWithIOLog(ioLog, () => {
6073
harnessCompiler.reset();
74+
6175
// Load the files
6276
ts.forEach(opts.fileNames, fileName => {
6377
inputFiles.push(getHarnessCompilerInputUnit(fileName));
6478
});
6579

66-
if (!opts.options.noLib) {
67-
// Find the lib.d.ts file in the input file and add it to the input files list
68-
var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined);
69-
if (libFile) {
70-
inputFiles.push(getHarnessCompilerInputUnit(libFile));
71-
}
72-
}
73-
80+
// Add files to compilation
7481
ts.forEach(ioLog.filesRead, fileRead => {
82+
// Check if the file is already added into the set of input files.
7583
var resolvedPath = ts.normalizeSlashes(ts.sys.resolvePath(fileRead.path));
7684
var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath);
77-
if (!inInputList) {
78-
// Add the file to other files
79-
otherFiles.push(getHarnessCompilerInputUnit(fileRead.path));
85+
86+
if (!Harness.isLibraryFile(fileRead.path)) {
87+
if (!inInputList) {
88+
otherFiles.push(getHarnessCompilerInputUnit(fileRead.path));
89+
}
90+
}
91+
else if (!opts.options.noLib && Harness.isLibraryFile(fileRead.path)){
92+
if (!inInputList) {
93+
// If useDefaultLibFile is true, we will use built/local/lib.d.ts
94+
// instead of the provided lib.d.ts from json object.
95+
// Majority of RWC code will be using built/local/lib.d.ts instead of
96+
// lib.d.ts inside json file. However, some RWC cases will still use
97+
// their own version of lib.d.ts because they have customized lib.d.ts
98+
if (useDefaultLibFile) {
99+
inputFiles.push(Harness.getDefaultLibraryFile());
100+
}
101+
else {
102+
inputFiles.push(getHarnessCompilerInputUnit(fileRead.path));
103+
}
104+
}
80105
}
81106
});
82107

@@ -115,9 +140,7 @@ module RWC {
115140

116141
it('has the expected declaration file content', () => {
117142
Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => {
118-
if (compilerResult.errors.length || !compilerResult.declFilesCode.length) {
119-
return null;
120-
}
143+
if (!compilerResult.declFilesCode.length) { return null; }
121144
return Harness.Compiler.collateOutputs(compilerResult.declFilesCode);
122145
}, false, baselineOpts);
123146
});

0 commit comments

Comments
 (0)