Skip to content

Commit 160d1b7

Browse files
authored
Process only tsconfig-referenced files in compiler tests with tsconfig files (#54506)
1 parent 9583850 commit 160d1b7

File tree

232 files changed

+8639
-7880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+8639
-7880
lines changed

src/harness/harnessIO.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ export namespace Compiler {
556556
outputLines += content;
557557
}
558558
if (pretty) {
559-
outputLines += ts.getErrorSummaryText(ts.getErrorCountForSummary(diagnostics), ts.getFilesInErrorForSummary(diagnostics), IO.newLine(), { getCurrentDirectory: () => "" });
559+
outputLines += Utils.removeTestPathPrefixes(ts.getErrorSummaryText(ts.getErrorCountForSummary(diagnostics), ts.getFilesInErrorForSummary(diagnostics), IO.newLine(), { getCurrentDirectory: () => "" }));
560560
}
561561
return outputLines;
562562
}
@@ -597,6 +597,7 @@ export namespace Compiler {
597597
if (error.relatedInformation) {
598598
for (const info of error.relatedInformation) {
599599
let location = info.file ? " " + ts.formatLocation(info.file, info.start!, formatDiagnsoticHost, ts.identity) : "";
600+
location = Utils.removeTestPathPrefixes(location);
600601
if (location && isDefaultLibraryFile(info.file!.fileName)) {
601602
location = location.replace(/(lib(?:.*)\.d\.ts):\d+:\d+/i, "$1:--:--");
602603
}
@@ -641,7 +642,7 @@ export namespace Compiler {
641642

642643

643644
// Header
644-
outputLines += (newLine() + "==== " + inputFile.unitName + " (" + fileErrors.length + " errors) ====");
645+
outputLines += (newLine() + "==== " + Utils.removeTestPathPrefixes(inputFile.unitName) + " (" + fileErrors.length + " errors) ====");
645646

646647
// Make sure we emit something for every error
647648
let markedErrorCount = 0;
@@ -1282,8 +1283,31 @@ export namespace TestCaseParser {
12821283
// unit tests always list files explicitly
12831284
const parseConfigHost: ts.ParseConfigHost = {
12841285
useCaseSensitiveFileNames: false,
1285-
readDirectory: () => [],
1286-
fileExists: () => true,
1286+
readDirectory: (directory, extensions, excludes, includes, depth) => {
1287+
return ts.matchFiles(directory, extensions, excludes, includes, /*useCaseSensitiveFileNames*/ false, "", depth, dir => {
1288+
const files: string[] = [];
1289+
const directories = new Set<string>();
1290+
for (const unit of testUnitData) {
1291+
const unitName = ts.getNormalizedAbsolutePath(unit.name, rootDir);
1292+
if (unitName.toLowerCase().startsWith(dir.toLowerCase())) {
1293+
let path = unitName.substring(dir.length);
1294+
if (path.startsWith("/")) {
1295+
path = path.substring(1);
1296+
}
1297+
if (path.includes("/")) {
1298+
const directoryName = path.substring(0, path.indexOf("/"));
1299+
directories.add(directoryName);
1300+
}
1301+
else {
1302+
files.push(path);
1303+
}
1304+
}
1305+
}
1306+
return { files, directories: ts.arrayFrom(directories) };
1307+
1308+
}, ts.identity);
1309+
},
1310+
fileExists: fileName => testUnitData.some(data => data.name.toLowerCase() === fileName.toLowerCase()),
12871311
readFile: (name) => ts.forEach(testUnitData, data => data.name.toLowerCase() === name.toLowerCase() ? data.content : undefined)
12881312
};
12891313

@@ -1299,8 +1323,7 @@ export namespace TestCaseParser {
12991323
if (rootDir) {
13001324
baseDir = ts.getNormalizedAbsolutePath(baseDir, rootDir);
13011325
}
1302-
tsConfig = ts.parseJsonSourceFileConfigFileContent(configJson, parseConfigHost, baseDir);
1303-
tsConfig.options.configFilePath = data.name;
1326+
tsConfig = ts.parseJsonSourceFileConfigFileContent(configJson, parseConfigHost, baseDir, /*existingOptions*/ undefined, ts.getNormalizedAbsolutePath(data.name, rootDir));
13041327
tsConfigFileUnitData = data;
13051328

13061329
// delete entry from the list

src/harness/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const replaceTypesVersionsMessage = createDiagnosticMessageReplacer(
2121
([entry, , moduleName], compilerVersion) => [entry, compilerVersion, moduleName]);
2222

2323
export function sanitizeTraceResolutionLogEntry(text: string) {
24-
return text && removeTestPathPrefixes(replaceTypesVersionsMessage(text, "3.1.0-dev"));
24+
return text && replaceTypesVersionsMessage(text, "3.1.0-dev");
2525
}
2626

2727
/**
@@ -126,4 +126,4 @@ export function defer<T = void>(): Deferred<T> {
126126
reject = _reject;
127127
});
128128
return { resolve, reject, promise };
129-
}
129+
}

src/testRunner/compilerRunner.ts

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from "./_namespaces/Harness";
1414
import * as ts from "./_namespaces/ts";
1515
import * as Utils from "./_namespaces/Utils";
16+
import * as vfs from "./_namespaces/vfs";
1617
import * as vpath from "./_namespaces/vpath";
1718

1819
export const enum CompilerTestType {
@@ -91,11 +92,12 @@ export class CompilerBaselineRunner extends RunnerBase {
9192
let compilerTest!: CompilerTest;
9293
before(() => {
9394
let payload;
95+
let rootDir = ts.combinePaths(vfs.srcFolder, fileName.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(fileName) + "/");
9496
if (test && test.content) {
95-
const rootDir = test.file.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(test.file) + "/";
97+
rootDir = ts.combinePaths(vfs.srcFolder, test.file.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(test.file) + "/");
9698
payload = TestCaseParser.makeUnitsFromTest(test.content, test.file, rootDir);
9799
}
98-
compilerTest = new CompilerTest(fileName, payload, configuration);
100+
compilerTest = new CompilerTest(fileName, rootDir, payload, configuration);
99101
});
100102
it(`Correct errors for ${fileName}`, () => compilerTest.verifyDiagnostics());
101103
it(`Correct module resolution tracing for ${fileName}`, () => compilerTest.verifyModuleResolution());
@@ -167,7 +169,6 @@ class CompilerTest {
167169
private fileName: string;
168170
private justName: string;
169171
private configuredName: string;
170-
private lastUnit: TestCaseParser.TestUnitData;
171172
private harnessSettings: TestCaseParser.CompilerSettings;
172173
private hasNonDtsFiles: boolean;
173174
private result: compiler.CompilationResult;
@@ -178,7 +179,7 @@ class CompilerTest {
178179
// equivalent to other files on the file system not directly passed to the compiler (ie things that are referenced by other files)
179180
private otherFiles: Compiler.TestFile[];
180181

181-
constructor(fileName: string, testCaseContent?: TestCaseParser.TestCaseContent, configurationOverrides?: TestCaseParser.CompilerSettings) {
182+
constructor(fileName: string, rootDir: string, testCaseContent?: TestCaseParser.TestCaseContent, configurationOverrides?: TestCaseParser.CompilerSettings) {
182183
this.fileName = fileName;
183184
this.justName = vpath.basename(fileName);
184185
this.configuredName = this.justName;
@@ -200,8 +201,6 @@ class CompilerTest {
200201
}
201202
}
202203

203-
const rootDir = fileName.indexOf("conformance") === -1 ? "tests/cases/compiler/" : ts.getDirectoryPath(fileName) + "/";
204-
205204
if (testCaseContent === undefined) {
206205
testCaseContent = TestCaseParser.makeUnitsFromTest(IO.readFile(fileName)!, fileName, rootDir);
207206
}
@@ -211,43 +210,48 @@ class CompilerTest {
211210
}
212211

213212
const units = testCaseContent.testUnitData;
213+
this.toBeCompiled = [];
214+
this.otherFiles = [];
215+
this.hasNonDtsFiles = units.some(unit => !ts.fileExtensionIs(unit.name, ts.Extension.Dts));
214216
this.harnessSettings = testCaseContent.settings;
215217
let tsConfigOptions: ts.CompilerOptions | undefined;
216218
this.tsConfigFiles = [];
217219
if (testCaseContent.tsConfig) {
218-
assert.equal(testCaseContent.tsConfig.fileNames.length, 0, `list of files in tsconfig is not currently supported`);
219-
assert.equal(testCaseContent.tsConfig.raw.exclude, undefined, `exclude in tsconfig is not currently supported`);
220-
221220
tsConfigOptions = ts.cloneCompilerOptions(testCaseContent.tsConfig.options);
222-
this.tsConfigFiles.push(this.createHarnessTestFile(testCaseContent.tsConfigFileUnitData!, rootDir, ts.combinePaths(rootDir, tsConfigOptions.configFilePath)));
221+
this.tsConfigFiles.push(this.createHarnessTestFile(testCaseContent.tsConfigFileUnitData!, rootDir, tsConfigOptions.configFilePath));
222+
for (const unit of units) {
223+
if (testCaseContent.tsConfig.fileNames.includes(ts.getNormalizedAbsolutePath(unit.name, rootDir))) {
224+
this.toBeCompiled.push(this.createHarnessTestFile(unit, rootDir));
225+
}
226+
else {
227+
this.otherFiles.push(this.createHarnessTestFile(unit, rootDir));
228+
}
229+
}
223230
}
224231
else {
225232
const baseUrl = this.harnessSettings.baseUrl;
226233
if (baseUrl !== undefined && !ts.isRootedDiskPath(baseUrl)) {
227234
this.harnessSettings.baseUrl = ts.getNormalizedAbsolutePath(baseUrl, rootDir);
228235
}
229-
}
230-
231-
this.lastUnit = units[units.length - 1];
232-
this.hasNonDtsFiles = units.some(unit => !ts.fileExtensionIs(unit.name, ts.Extension.Dts));
233-
// 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)
234-
// 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,
235-
// otherwise, assume all files are just meant to be in the same compilation session without explicit references to one another.
236-
this.toBeCompiled = [];
237-
this.otherFiles = [];
238236

239-
if (testCaseContent.settings.noImplicitReferences || /require\(/.test(this.lastUnit.content) || /reference\spath/.test(this.lastUnit.content)) {
240-
this.toBeCompiled.push(this.createHarnessTestFile(this.lastUnit, rootDir));
241-
units.forEach(unit => {
242-
if (unit.name !== this.lastUnit.name) {
243-
this.otherFiles.push(this.createHarnessTestFile(unit, rootDir));
244-
}
245-
});
246-
}
247-
else {
248-
this.toBeCompiled = units.map(unit => {
249-
return this.createHarnessTestFile(unit, rootDir);
250-
});
237+
const lastUnit = units[units.length - 1];
238+
// 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)
239+
// 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,
240+
// otherwise, assume all files are just meant to be in the same compilation session without explicit references to one another.
241+
242+
if (testCaseContent.settings.noImplicitReferences || /require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) {
243+
this.toBeCompiled.push(this.createHarnessTestFile(lastUnit, rootDir));
244+
units.forEach(unit => {
245+
if (unit.name !== lastUnit.name) {
246+
this.otherFiles.push(this.createHarnessTestFile(unit, rootDir));
247+
}
248+
});
249+
}
250+
else {
251+
this.toBeCompiled = units.map(unit => {
252+
return this.createHarnessTestFile(unit, rootDir);
253+
});
254+
}
251255
}
252256

253257
if (tsConfigOptions && tsConfigOptions.configFilePath !== undefined) {

tests/baselines/reference/DateTimeFormatAndNumberFormatES2021.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(5,25): error TS2551:
1515
new Intl.NumberFormat().formatRangeToParts
1616
~~~~~~~~~~~~~~~~~~
1717
!!! error TS2551: Property 'formatRangeToParts' does not exist on type 'NumberFormat'. Did you mean 'formatToParts'?
18-
!!! related TS2728 /.ts/lib.es2018.intl.d.ts:--:--: 'formatToParts' is declared here.
18+
!!! related TS2728 lib.es2018.intl.d.ts:--:--: 'formatToParts' is declared here.
1919
new Intl.DateTimeFormat().formatRange
2020
new Intl.DateTimeFormat().formatRangeToParts

tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction9_es20
1616
!!! error TS1005: ',' expected.
1717
~~~~~~~
1818
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'.
19-
!!! related TS6203 /.ts/lib.es2015.promise.d.ts:--:--: 'Promise' was also declared here.
19+
!!! related TS6203 lib.es2015.promise.d.ts:--:--: 'Promise' was also declared here.
2020
~
2121
!!! error TS1005: ',' expected.
2222
~~

tests/baselines/reference/asyncArrowFunction9_es5.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(
1616
!!! error TS1005: ',' expected.
1717
~~~~~~~
1818
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'.
19-
!!! related TS6203 /.ts/lib.es2015.promise.d.ts:--:--: 'Promise' was also declared here.
19+
!!! related TS6203 lib.es2015.promise.d.ts:--:--: 'Promise' was also declared here.
2020
~
2121
!!! error TS1005: ',' expected.
2222
~~

tests/baselines/reference/asyncArrowFunction9_es6.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(
1616
!!! error TS1005: ',' expected.
1717
~~~~~~~
1818
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'.
19-
!!! related TS6203 /.ts/lib.es2015.promise.d.ts:--:--: 'Promise' was also declared here.
19+
!!! related TS6203 lib.es2015.promise.d.ts:--:--: 'Promise' was also declared here.
2020
~
2121
!!! error TS1005: ',' expected.
2222
~~

tests/baselines/reference/baseCheck.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'.
2121
super(0, loc);
2222
~~~
2323
!!! error TS2552: Cannot find name 'loc'. Did you mean 'Lock'?
24-
!!! related TS2728 /.ts/lib.dom.d.ts:--:--: 'Lock' is declared here.
24+
!!! related TS2728 lib.dom.d.ts:--:--: 'Lock' is declared here.
2525
}
2626

2727
m() {

0 commit comments

Comments
 (0)