Skip to content

Commit 7e4b20e

Browse files
authored
Use compare paths for comparing diagnostic paths, since the canonicalization of fileName and unitName differ (#24340)
1 parent 0102f80 commit 7e4b20e

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/harness/harness.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ namespace Harness {
13431343

13441344
export function getErrorBaseline(inputFiles: ReadonlyArray<TestFile>, diagnostics: ReadonlyArray<ts.Diagnostic>, pretty?: boolean) {
13451345
let outputLines = "";
1346-
const gen = iterateErrorBaseline(inputFiles, diagnostics, pretty);
1346+
const gen = iterateErrorBaseline(inputFiles, diagnostics, { pretty });
13471347
for (let {done, value} = gen.next(); !done; { done, value } = gen.next()) {
13481348
const [, content] = value;
13491349
outputLines += content;
@@ -1353,7 +1353,7 @@ namespace Harness {
13531353

13541354
export const diagnosticSummaryMarker = "__diagnosticSummary";
13551355
export const globalErrorsMarker = "__globalErrors";
1356-
export function *iterateErrorBaseline(inputFiles: ReadonlyArray<TestFile>, diagnostics: ReadonlyArray<ts.Diagnostic>, pretty?: boolean): IterableIterator<[string, string, number]> {
1356+
export function *iterateErrorBaseline(inputFiles: ReadonlyArray<TestFile>, diagnostics: ReadonlyArray<ts.Diagnostic>, options?: { pretty?: boolean, caseSensitive?: boolean, currentDirectory?: string }): IterableIterator<[string, string, number]> {
13571357
diagnostics = ts.sort(diagnostics, ts.compareDiagnostics);
13581358
let outputLines = "";
13591359
// Count up all errors that were found in files other than lib.d.ts so we don't miss any
@@ -1391,7 +1391,7 @@ namespace Harness {
13911391
}
13921392
}
13931393

1394-
yield [diagnosticSummaryMarker, utils.removeTestPathPrefixes(minimalDiagnosticsToString(diagnostics, pretty)) + IO.newLine() + IO.newLine(), diagnostics.length];
1394+
yield [diagnosticSummaryMarker, utils.removeTestPathPrefixes(minimalDiagnosticsToString(diagnostics, options && options.pretty)) + IO.newLine() + IO.newLine(), diagnostics.length];
13951395

13961396
// Report global errors
13971397
const globalErrors = diagnostics.filter(err => !err.file);
@@ -1406,7 +1406,7 @@ namespace Harness {
14061406
// Filter down to the errors in the file
14071407
const fileErrors = diagnostics.filter((e): e is ts.DiagnosticWithLocation => {
14081408
const errFn = e.file;
1409-
return !!errFn && utils.removeTestPathPrefixes(errFn.fileName) === utils.removeTestPathPrefixes(inputFile.unitName);
1409+
return !!errFn && ts.comparePaths(utils.removeTestPathPrefixes(errFn.fileName), utils.removeTestPathPrefixes(inputFile.unitName), options && options.currentDirectory || "", !(options && options.caseSensitive)) === ts.Comparison.EqualTo;
14101410
});
14111411

14121412

src/harness/rwcRunner.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace RWC {
3535
const baseName = ts.getBaseFileName(jsonPath);
3636
let currentDirectory: string;
3737
let useCustomLibraryFile: boolean;
38+
let caseSensitive: boolean;
3839
after(() => {
3940
// Mocha holds onto the closure environment of the describe callback even after the test is done.
4041
// Therefore we have to clean out large objects after the test is done.
@@ -47,7 +48,8 @@ namespace RWC {
4748
// useCustomLibraryFile is a flag specified in the json object to indicate whether to use built/local/lib.d.ts
4849
// or to use lib.d.ts inside the json object. If the flag is true, use the lib.d.ts inside json file
4950
// otherwise use the lib.d.ts from built/local
50-
useCustomLibraryFile = undefined!;
51+
useCustomLibraryFile = false;
52+
caseSensitive = false;
5153
});
5254

5355
it("can compile", function(this: Mocha.ITestCallbackContext) {
@@ -93,7 +95,7 @@ namespace RWC {
9395
if (!uniqueNames.has(normalized)) {
9496
uniqueNames.set(normalized, true);
9597
// Load the file
96-
inputFiles.push(getHarnessCompilerInputUnit(normalized));
98+
inputFiles.push(getHarnessCompilerInputUnit(fileName));
9799
}
98100
}
99101

@@ -102,7 +104,7 @@ namespace RWC {
102104
const unitName = ts.normalizeSlashes(Harness.IO.resolvePath(fileRead.path)!);
103105
if (!uniqueNames.has(unitName) && !Harness.isDefaultLibraryFile(fileRead.path)) {
104106
uniqueNames.set(unitName, true);
105-
otherFiles.push(getHarnessCompilerInputUnit(unitName));
107+
otherFiles.push(getHarnessCompilerInputUnit(fileRead.path));
106108
}
107109
else if (!opts.options.noLib && Harness.isDefaultLibraryFile(fileRead.path) && !uniqueNames.has(unitName) && useCustomLibraryFile) {
108110
// If useCustomLibraryFile is true, we will use lib.d.ts from json object
@@ -111,7 +113,7 @@ namespace RWC {
111113
// lib.d.ts inside json file. However, some RWC cases will still use
112114
// their own version of lib.d.ts because they have customized lib.d.ts
113115
uniqueNames.set(unitName, true);
114-
inputFiles.push(getHarnessCompilerInputUnit(unitName));
116+
inputFiles.push(getHarnessCompilerInputUnit(fileRead.path));
115117
}
116118
}
117119
});
@@ -122,11 +124,12 @@ namespace RWC {
122124
opts.options.noLib = true;
123125
}
124126

127+
caseSensitive = ioLog.useCaseSensitiveFileNames || false;
125128
// Emit the results
126129
compilerResult = Harness.Compiler.compileFiles(
127130
inputFiles,
128131
otherFiles,
129-
{ useCaseSensitiveFileNames: "" + (ioLog.useCaseSensitiveFileNames || false) },
132+
{ useCaseSensitiveFileNames: "" + caseSensitive },
130133
opts.options,
131134
// Since each RWC json file specifies its current directory in its json file, we need
132135
// to pass this information in explicitly instead of acquiring it from the process.
@@ -182,7 +185,7 @@ namespace RWC {
182185
// Do not include the library in the baselines to avoid noise
183186
const baselineFiles = tsconfigFiles.concat(inputFiles, otherFiles).filter(f => !Harness.isDefaultLibraryFile(f.unitName));
184187
const errors = compilerResult.diagnostics.filter(e => !e.file || !Harness.isDefaultLibraryFile(e.file.fileName));
185-
return Harness.Compiler.iterateErrorBaseline(baselineFiles, errors);
188+
return Harness.Compiler.iterateErrorBaseline(baselineFiles, errors, { caseSensitive, currentDirectory });
186189
}, baselineOpts);
187190
});
188191

@@ -202,7 +205,7 @@ namespace RWC {
202205
compilerResult = undefined!;
203206
const declFileCompilationResult = Harness.Compiler.compileDeclarationFiles(declContext)!;
204207

205-
return Harness.Compiler.iterateErrorBaseline(tsconfigFiles.concat(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.diagnostics);
208+
return Harness.Compiler.iterateErrorBaseline(tsconfigFiles.concat(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.diagnostics, { caseSensitive, currentDirectory });
206209
}, baselineOpts);
207210
}
208211
});

0 commit comments

Comments
 (0)