Skip to content

Commit a4f74a3

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

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/harness/harness.ts

Lines changed: 26 additions & 13 deletions
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,10 @@ 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) for (const relErr of error.relatedInformation) {
1355+
outputError(/*isRelatedError*/ true, relErr);
1356+
}
13601357
errorsReported++;
13611358

13621359
// do not count errors from lib.d.ts here, they are computed separately as numLibraryDiagnostics
@@ -1369,6 +1366,23 @@ namespace Harness {
13691366
}
13701367
}
13711368

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

13741388
// Report global errors
@@ -1419,8 +1433,7 @@ namespace Harness {
14191433
}
14201434
// Emit this line from the original file
14211435
outputLines += (newLine() + " " + line);
1422-
fileErrors.forEach(errDiagnostic => {
1423-
const err = errDiagnostic as ts.TextSpan; // TODO: GH#18217
1436+
fileErrors.forEach(err => {
14241437
// Does any error start or continue on to this line? Emit squiggles
14251438
const end = ts.textSpanEnd(err);
14261439
if ((end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) {
@@ -1438,7 +1451,7 @@ namespace Harness {
14381451
// Just like above, we need to do a split on a string instead of on a regex
14391452
// because the JS engine does regexes wrong
14401453

1441-
outputErrorText(errDiagnostic);
1454+
outputErrorText(err);
14421455
markedErrorCount++;
14431456
}
14441457
}

0 commit comments

Comments
 (0)