Skip to content

Commit 97d170b

Browse files
committed
Support to tests for absolute paths, add common src dir edgecase tests
1 parent 6dcf3cf commit 97d170b

15 files changed

Lines changed: 131 additions & 15 deletions

src/harness/compilerRunner.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ class CompilerBaselineRunner extends RunnerBase {
4545
// Mocha holds onto the closure environment of the describe callback even after the test is done.
4646
// Everything declared here should be cleared out in the "after" callback.
4747
let justName: string;
48-
let content: string;
49-
let testCaseContent: { settings: Harness.TestCaseParser.CompilerSettings; testUnitData: Harness.TestCaseParser.TestUnitData[]; };
5048

51-
let units: Harness.TestCaseParser.TestUnitData[];
5249
let tcSettings: Harness.TestCaseParser.CompilerSettings;
5350

5451
let lastUnit: Harness.TestCaseParser.TestUnitData;
55-
let rootDir: string;
5652

5753
let result: Harness.Compiler.CompilerResult;
5854
let program: ts.Program;
@@ -65,29 +61,29 @@ class CompilerBaselineRunner extends RunnerBase {
6561

6662
before(() => {
6763
justName = fileName.replace(/^.*[\\\/]/, ""); // strips the fileName from the path.
68-
content = Harness.IO.readFile(fileName);
69-
testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName);
70-
units = testCaseContent.testUnitData;
64+
const content = Harness.IO.readFile(fileName);
65+
const testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName);
66+
const units = testCaseContent.testUnitData;
7167
tcSettings = testCaseContent.settings;
7268
lastUnit = units[units.length - 1];
73-
rootDir = lastUnit.originalFilePath.indexOf("conformance") === -1 ? "tests/cases/compiler/" : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf("/")) + "/";
69+
const rootDir = lastUnit.originalFilePath.indexOf("conformance") === -1 ? "tests/cases/compiler/" : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf("/")) + "/";
7470
harnessCompiler = Harness.Compiler.getCompiler();
7571
// We need to assemble the list of input files for the compiler and other related files on the 'filesystem' (ie in a multi-file test)
7672
// If the last file in a test uses require or a triple slash reference we'll assume all other files will be brought in via references,
7773
// otherwise, assume all files are just meant to be in the same compilation session without explicit references to one another.
7874
toBeCompiled = [];
7975
otherFiles = [];
8076
if (/require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) {
81-
toBeCompiled.push({ unitName: rootDir + lastUnit.name, content: lastUnit.content });
77+
toBeCompiled.push({ unitName: ts.isRootedDiskPath(lastUnit.name) ? lastUnit.name : rootDir + lastUnit.name, content: lastUnit.content });
8278
units.forEach(unit => {
8379
if (unit.name !== lastUnit.name) {
84-
otherFiles.push({ unitName: rootDir + unit.name, content: unit.content });
80+
otherFiles.push({ unitName: ts.isRootedDiskPath(unit.name) ? unit.name : rootDir + unit.name, content: unit.content });
8581
}
8682
});
8783
}
8884
else {
8985
toBeCompiled = units.map(unit => {
90-
return { unitName: rootDir + unit.name, content: unit.content };
86+
return { unitName: ts.isRootedDiskPath(unit.name) ? unit.name : rootDir + unit.name, content: unit.content };
9187
});
9288
}
9389

@@ -104,12 +100,8 @@ class CompilerBaselineRunner extends RunnerBase {
104100
// Mocha holds onto the closure environment of the describe callback even after the test is done.
105101
// Therefore we have to clean out large objects after the test is done.
106102
justName = undefined;
107-
content = undefined;
108-
testCaseContent = undefined;
109-
units = undefined;
110103
tcSettings = undefined;
111104
lastUnit = undefined;
112-
rootDir = undefined;
113105
result = undefined;
114106
program = undefined;
115107
options = undefined;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/compiler/commonSourceDir1.ts] ////
2+
3+
//// [bar.ts]
4+
var x: number;
5+
6+
//// [baz.ts]
7+
var y: number;
8+
9+
10+
//// [bar.js]
11+
var x;
12+
//// [baz.js]
13+
var y;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== A:/foo/bar.ts ===
2+
var x: number;
3+
>x : Symbol(x, Decl(bar.ts, 0, 3))
4+
5+
=== A:/foo/baz.ts ===
6+
var y: number;
7+
>y : Symbol(y, Decl(baz.ts, 0, 3))
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== A:/foo/bar.ts ===
2+
var x: number;
3+
>x : number
4+
5+
=== A:/foo/baz.ts ===
6+
var y: number;
7+
>y : number
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error TS5009: Cannot find the common subdirectory path for the input files.
2+
3+
4+
!!! error TS5009: Cannot find the common subdirectory path for the input files.
5+
==== A:/foo/bar.ts (0 errors) ====
6+
var x: number;
7+
8+
==== B:/foo/baz.ts (0 errors) ====
9+
var y: number;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/compiler/commonSourceDir2.ts] ////
2+
3+
//// [bar.ts]
4+
var x: number;
5+
6+
//// [baz.ts]
7+
var y: number;
8+
9+
//// [bar.js]
10+
var x;
11+
//// [baz.js]
12+
var y;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/compiler/commonSourceDir3.ts] ////
2+
3+
//// [bar.ts]
4+
var x: number;
5+
6+
//// [baz.ts]
7+
var y: number;
8+
9+
//// [bar.js]
10+
var x;
11+
//// [baz.js]
12+
var y;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== A:/foo/bar.ts ===
2+
var x: number;
3+
>x : Symbol(x, Decl(bar.ts, 0, 3))
4+
5+
=== a:/foo/baz.ts ===
6+
var y: number;
7+
>y : Symbol(y, Decl(baz.ts, 0, 3))
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== A:/foo/bar.ts ===
2+
var x: number;
3+
>x : number
4+
5+
=== a:/foo/baz.ts ===
6+
var y: number;
7+
>y : number
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error TS5009: Cannot find the common subdirectory path for the input files.
2+
3+
4+
!!! error TS5009: Cannot find the common subdirectory path for the input files.
5+
==== A:/foo/bar.ts (0 errors) ====
6+
var x: number;
7+
8+
==== a:/foo/baz.ts (0 errors) ====
9+
var y: number;

0 commit comments

Comments
 (0)