Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ namespace ts {
return s;
}

export function formatDiagnosticsWithColorAndContext(diagnostics: Diagnostic[], host: FormatDiagnosticsHost): string {
export function formatDiagnosticsWithColorAndContext(diagnostics: ReadonlyArray<Diagnostic>, host: FormatDiagnosticsHost): string {
let output = "";
for (const diagnostic of diagnostics) {
if (diagnostic.file) {
Expand All @@ -284,12 +284,12 @@ namespace ts {
gutterWidth = Math.max(ellipsis.length, gutterWidth);
}

output += sys.newLine;
output += host.getNewLine();
for (let i = firstLine; i <= lastLine; i++) {
// If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
// so we'll skip ahead to the second-to-last line.
if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {
output += formatAndReset(padLeft(ellipsis, gutterWidth), gutterStyleSequence) + gutterSeparator + sys.newLine;
output += formatAndReset(padLeft(ellipsis, gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine();
i = lastLine - 1;
}

Expand All @@ -301,7 +301,7 @@ namespace ts {

// Output the gutter and the actual contents of the line.
output += formatAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator;
output += lineContent + sys.newLine;
output += lineContent + host.getNewLine();

// Output the gutter and the error span for the line using tildes.
output += formatAndReset(padLeft("", gutterWidth), gutterStyleSequence) + gutterSeparator;
Expand All @@ -323,17 +323,17 @@ namespace ts {
}
output += resetEscapeSequence;

output += sys.newLine;
output += host.getNewLine();
}

output += sys.newLine;
output += host.getNewLine();
output += `${ relativeFileName }(${ firstLine + 1 },${ firstLineChar + 1 }): `;
}

const categoryColor = getCategoryFormat(diagnostic.category);
const category = DiagnosticCategory[diagnostic.category].toLowerCase();
output += `${ formatAndReset(category, categoryColor) } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }`;
output += sys.newLine;
output += `${ formatAndReset(category, categoryColor) } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) }`;
output += host.getNewLine();
}
return output;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ namespace ts {
Debug.assert(res < lineStarts[line + 1]);
}
else if (debugText !== undefined) {
Debug.assert(res < debugText.length);
Debug.assert(res <= debugText.length); // Allow single character overflow for trailing newline
}
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/harness/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class CompilerBaselineRunner extends RunnerBase {

// check errors
it("Correct errors for " + fileName, () => {
Harness.Compiler.doErrorBaseline(justName, tsConfigFiles.concat(toBeCompiled, otherFiles), result.errors);
Harness.Compiler.doErrorBaseline(justName, tsConfigFiles.concat(toBeCompiled, otherFiles), result.errors, !!options.pretty);
});

it (`Correct module resolution tracing for ${fileName}`, () => {
Expand Down
13 changes: 7 additions & 6 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1284,11 +1284,12 @@ namespace Harness {
return normalized;
}

export function minimalDiagnosticsToString(diagnostics: ReadonlyArray<ts.Diagnostic>) {
return ts.formatDiagnostics(diagnostics, { getCanonicalFileName, getCurrentDirectory: () => "", getNewLine: () => Harness.IO.newLine() });
export function minimalDiagnosticsToString(diagnostics: ReadonlyArray<ts.Diagnostic>, pretty?: boolean) {
const host = { getCanonicalFileName, getCurrentDirectory: () => "", getNewLine: () => Harness.IO.newLine() };
return (pretty ? ts.formatDiagnosticsWithColorAndContext : ts.formatDiagnostics)(diagnostics, host);
}

export function getErrorBaseline(inputFiles: ReadonlyArray<TestFile>, diagnostics: ReadonlyArray<ts.Diagnostic>) {
export function getErrorBaseline(inputFiles: ReadonlyArray<TestFile>, diagnostics: ReadonlyArray<ts.Diagnostic>, pretty?: boolean) {
diagnostics = diagnostics.slice().sort(ts.compareDiagnostics);
let outputLines = "";
// Count up all errors that were found in files other than lib.d.ts so we don't miss any
Expand Down Expand Up @@ -1408,18 +1409,18 @@ namespace Harness {
// Verify we didn't miss any errors in total
assert.equal(totalErrorsReportedInNonLibraryFiles + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length, "total number of errors");

return minimalDiagnosticsToString(diagnostics) +
return minimalDiagnosticsToString(diagnostics, pretty) +
Harness.IO.newLine() + Harness.IO.newLine() + outputLines;
}

export function doErrorBaseline(baselinePath: string, inputFiles: TestFile[], errors: ts.Diagnostic[]) {
export function doErrorBaseline(baselinePath: string, inputFiles: TestFile[], errors: ts.Diagnostic[], pretty?: boolean) {
Harness.Baseline.runBaseline(baselinePath.replace(/\.tsx?$/, ".errors.txt"), (): string => {
if (!errors || (errors.length === 0)) {
/* tslint:disable:no-null-keyword */
return null;
/* tslint:enable:no-null-keyword */
}
return getErrorBaseline(inputFiles, errors);
return getErrorBaseline(inputFiles, errors, pretty);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

  

tests/cases/compiler/index.ts(2,1): error TS1005: '}' expected.


==== tests/cases/compiler/index.ts (1 errors) ====
if (true) {


!!! error TS1005: '}' expected.
7 changes: 7 additions & 0 deletions tests/baselines/reference/prettyContextNotDebugAssertion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [index.ts]
if (true) {


//// [index.js]
if (true) {
}
3 changes: 3 additions & 0 deletions tests/cases/compiler/prettyContextNotDebugAssertion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @pretty: true
// @filename: index.ts
if (true) {