Skip to content

Commit 2938e57

Browse files
Add related errors to baselines.
1 parent 12123bd commit 2938e57

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

Diff for: src/harness/harness.ts

+28-13
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,8 @@ namespace Harness {
11131113
{ name: "fullEmitPaths", type: "boolean" }
11141114
];
11151115

1116+
const diagnosticHost = { getCanonicalFileName, getCurrentDirectory: () => "", getNewLine: () => IO.newLine() };
1117+
11161118
let optionsIndex: ts.Map<ts.CommandLineOption>;
11171119
function getCommandLineOption(name: string): ts.CommandLineOption | undefined {
11181120
if (!optionsIndex) {
@@ -1315,8 +1317,7 @@ namespace Harness {
13151317
}
13161318

13171319
export function minimalDiagnosticsToString(diagnostics: ReadonlyArray<ts.Diagnostic>, pretty?: boolean) {
1318-
const host = { getCanonicalFileName, getCurrentDirectory: () => "", getNewLine: () => IO.newLine() };
1319-
return (pretty ? ts.formatDiagnosticsWithColorAndContext : ts.formatDiagnostics)(diagnostics, host);
1320+
return (pretty ? ts.formatDiagnosticsWithColorAndContext : ts.formatDiagnostics)(diagnostics, diagnosticHost);
13201321
}
13211322

13221323
export function getErrorBaseline(inputFiles: ReadonlyArray<TestFile>, diagnostics: ReadonlyArray<ts.Diagnostic>, pretty?: boolean) {
@@ -1349,14 +1350,12 @@ namespace Harness {
13491350
}
13501351

13511352
function outputErrorText(error: ts.Diagnostic) {
1352-
const message = ts.flattenDiagnosticMessageText(error.messageText, IO.newLine());
1353-
1354-
const errLines = utils.removeTestPathPrefixes(message)
1355-
.split("\n")
1356-
.map(s => s.length > 0 && s.charAt(s.length - 1) === "\r" ? s.substr(0, s.length - 1) : s)
1357-
.filter(s => s.length > 0)
1358-
.map(s => "!!! " + ts.diagnosticCategoryName(error) + " TS" + error.code + ": " + s);
1359-
errLines.forEach(e => outputLines += (newLine() + e));
1353+
outputError(/*isRelatedError*/ false, error);
1354+
if (error.relatedInformation) {
1355+
for (const relErr of error.relatedInformation) {
1356+
outputError(/*isRelatedError*/ true, relErr);
1357+
}
1358+
}
13601359
errorsReported++;
13611360

13621361
// do not count errors from lib.d.ts here, they are computed separately as numLibraryDiagnostics
@@ -1369,6 +1368,23 @@ namespace Harness {
13691368
}
13701369
}
13711370

1371+
function outputError(isRelatedError: boolean, error: ts.Diagnostic) {
1372+
const message = ts.flattenDiagnosticMessageText(error.messageText, IO.newLine());
1373+
let suffix = "!!! ";
1374+
if (isRelatedError) {
1375+
const file = ts.Debug.assertDefined(error.file);
1376+
const { line, character } = ts.getLineAndCharacterOfPosition(file, error.start!);
1377+
const fileName = utils.removeTestPathPrefixes(file.fileName);
1378+
suffix += `(i) ${fileName}(${line + 1},${character + 1}): `;
1379+
}
1380+
const errLines = utils.removeTestPathPrefixes(message)
1381+
.split("\n")
1382+
.map(s => s.length > 0 && s.charAt(s.length - 1) === "\r" ? s.substr(0, s.length - 1) : s)
1383+
.filter(s => s.length > 0)
1384+
.map(s => suffix + ts.diagnosticCategoryName(error) + " TS" + error.code + ": " + s);
1385+
errLines.forEach(e => outputLines += (newLine() + e));
1386+
}
1387+
13721388
yield [diagnosticSummaryMarker, utils.removeTestPathPrefixes(minimalDiagnosticsToString(diagnostics, options && options.pretty)) + IO.newLine() + IO.newLine(), diagnostics.length];
13731389

13741390
// Report global errors
@@ -1419,8 +1435,7 @@ namespace Harness {
14191435
}
14201436
// Emit this line from the original file
14211437
outputLines += (newLine() + " " + line);
1422-
fileErrors.forEach(errDiagnostic => {
1423-
const err = errDiagnostic as ts.TextSpan; // TODO: GH#18217
1438+
fileErrors.forEach(err => {
14241439
// Does any error start or continue on to this line? Emit squiggles
14251440
const end = ts.textSpanEnd(err);
14261441
if ((end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) {
@@ -1438,7 +1453,7 @@ namespace Harness {
14381453
// Just like above, we need to do a split on a string instead of on a regex
14391454
// because the JS engine does regexes wrong
14401455

1441-
outputErrorText(errDiagnostic);
1456+
outputErrorText(err);
14421457
markedErrorCount++;
14431458
}
14441459
}

0 commit comments

Comments
 (0)