Skip to content

Commit 22a1f02

Browse files
Merge pull request microsoft#3371 from Microsoft/harnessDiagnostics
Remove HarnessDiagnostics. Just use the normal ts Diagnostic instead.
2 parents ca4bf6b + b5077bf commit 22a1f02

14 files changed

Lines changed: 103 additions & 146 deletions

src/harness/harness.ts

Lines changed: 26 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ module Harness {
899899
private compileOptions: ts.CompilerOptions;
900900
private settings: Harness.TestCaseParser.CompilerSetting[] = [];
901901

902-
private lastErrors: HarnessDiagnostic[];
902+
private lastErrors: ts.Diagnostic[];
903903

904904
public reset() {
905905
this.inputFiles = [];
@@ -1078,10 +1078,6 @@ module Harness {
10781078
}
10791079
break;
10801080

1081-
case 'normalizenewline':
1082-
newLine = setting.value;
1083-
break;
1084-
10851081
case 'comments':
10861082
options.removeComments = setting.value === 'false';
10871083
break;
@@ -1144,11 +1140,7 @@ module Harness {
11441140

11451141
var emitResult = program.emit();
11461142

1147-
var errors: HarnessDiagnostic[] = [];
1148-
ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics).forEach(err => {
1149-
// TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now
1150-
errors.push(getMinimalDiagnostic(err));
1151-
});
1143+
var errors = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
11521144
this.lastErrors = errors;
11531145

11541146
var result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult.sourceMaps);
@@ -1235,70 +1227,50 @@ module Harness {
12351227
return normalized;
12361228
}
12371229

1238-
export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic {
1239-
var errorLineInfo = err.file ? err.file.getLineAndCharacterOfPosition(err.start) : { line: -1, character: -1 };
1240-
return {
1241-
fileName: err.file && err.file.fileName,
1242-
start: err.start,
1243-
end: err.start + err.length,
1244-
line: errorLineInfo.line + 1,
1245-
character: errorLineInfo.character + 1,
1246-
message: ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine),
1247-
category: ts.DiagnosticCategory[err.category].toLowerCase(),
1248-
code: err.code
1249-
};
1250-
}
1251-
1252-
export function minimalDiagnosticsToString(diagnostics: HarnessDiagnostic[]) {
1230+
export function minimalDiagnosticsToString(diagnostics: ts.Diagnostic[]) {
12531231
// This is basically copied from tsc.ts's reportError to replicate what tsc does
12541232
var errorOutput = "";
1255-
ts.forEach(diagnostics, diagnotic => {
1256-
if (diagnotic.fileName) {
1257-
errorOutput += diagnotic.fileName + "(" + diagnotic.line + "," + diagnotic.character + "): ";
1233+
ts.forEach(diagnostics, diagnostic => {
1234+
if (diagnostic.file) {
1235+
var lineAndCharacter = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
1236+
errorOutput += diagnostic.file.fileName + "(" + (lineAndCharacter.line + 1) + "," + (lineAndCharacter.character + 1) + "): ";
12581237
}
12591238

1260-
errorOutput += diagnotic.category + " TS" + diagnotic.code + ": " + diagnotic.message + ts.sys.newLine;
1239+
errorOutput += ts.DiagnosticCategory[diagnostic.category].toLowerCase() + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine;
12611240
});
12621241

12631242
return errorOutput;
12641243
}
12651244

1266-
function compareDiagnostics(d1: HarnessDiagnostic, d2: HarnessDiagnostic) {
1267-
return ts.compareValues(d1.fileName, d2.fileName) ||
1268-
ts.compareValues(d1.start, d2.start) ||
1269-
ts.compareValues(d1.end, d2.end) ||
1270-
ts.compareValues(d1.code, d2.code) ||
1271-
ts.compareValues(d1.message, d2.message) ||
1272-
0;
1273-
}
1274-
1275-
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: HarnessDiagnostic[]) {
1276-
diagnostics.sort(compareDiagnostics);
1245+
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: ts.Diagnostic[]) {
1246+
diagnostics.sort(ts.compareDiagnostics);
12771247
var outputLines: string[] = [];
12781248
// Count up all the errors we find so we don't miss any
12791249
var totalErrorsReported = 0;
12801250

1281-
function outputErrorText(error: Harness.Compiler.HarnessDiagnostic) {
1282-
var errLines = RunnerBase.removeFullPaths(error.message)
1251+
function outputErrorText(error: ts.Diagnostic) {
1252+
var message = ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine);
1253+
1254+
var errLines = RunnerBase.removeFullPaths(message)
12831255
.split('\n')
12841256
.map(s => s.length > 0 && s.charAt(s.length - 1) === '\r' ? s.substr(0, s.length - 1) : s)
12851257
.filter(s => s.length > 0)
1286-
.map(s => '!!! ' + error.category + " TS" + error.code + ": " + s);
1258+
.map(s => '!!! ' + ts.DiagnosticCategory[error.category].toLowerCase() + " TS" + error.code + ": " + s);
12871259
errLines.forEach(e => outputLines.push(e));
12881260

12891261
totalErrorsReported++;
12901262
}
12911263

12921264
// Report global errors
1293-
var globalErrors = diagnostics.filter(err => !err.fileName);
1265+
var globalErrors = diagnostics.filter(err => !err.file);
12941266
globalErrors.forEach(outputErrorText);
12951267

12961268
// 'merge' the lines of each input file with any errors associated with it
12971269
inputFiles.filter(f => f.content !== undefined).forEach(inputFile => {
12981270
// Filter down to the errors in the file
12991271
var fileErrors = diagnostics.filter(e => {
1300-
var errFn = e.fileName;
1301-
return errFn && errFn === inputFile.unitName;
1272+
var errFn = e.file;
1273+
return errFn && errFn.fileName === inputFile.unitName;
13021274
});
13031275

13041276

@@ -1334,18 +1306,19 @@ module Harness {
13341306
outputLines.push(' ' + line);
13351307
fileErrors.forEach(err => {
13361308
// Does any error start or continue on to this line? Emit squiggles
1337-
if ((err.end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) {
1309+
let end = ts.textSpanEnd(err);
1310+
if ((end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) {
13381311
// How many characters from the start of this line the error starts at (could be positive or negative)
13391312
var relativeOffset = err.start - thisLineStart;
13401313
// How many characters of the error are on this line (might be longer than this line in reality)
1341-
var length = (err.end - err.start) - Math.max(0, thisLineStart - err.start);
1314+
var length = (end - err.start) - Math.max(0, thisLineStart - err.start);
13421315
// Calculate the start of the squiggle
13431316
var squiggleStart = Math.max(0, relativeOffset);
13441317
// TODO/REVIEW: this doesn't work quite right in the browser if a multi file test has files whose names are just the right length relative to one another
13451318
outputLines.push(' ' + line.substr(0, squiggleStart).replace(/[^\s]/g, ' ') + new Array(Math.min(length, line.length - squiggleStart) + 1).join('~'));
13461319

13471320
// If the error ended here, or we're at the end of the file, emit its message
1348-
if ((lineIndex === lines.length - 1) || nextLineStart > err.end) {
1321+
if ((lineIndex === lines.length - 1) || nextLineStart > end) {
13491322
// Just like above, we need to do a split on a string instead of on a regex
13501323
// because the JS engine does regexes wrong
13511324

@@ -1361,12 +1334,12 @@ module Harness {
13611334
});
13621335

13631336
var numLibraryDiagnostics = ts.countWhere(diagnostics, diagnostic => {
1364-
return diagnostic.fileName && (isLibraryFile(diagnostic.fileName) || isBuiltFile(diagnostic.fileName));
1337+
return diagnostic.file && (isLibraryFile(diagnostic.file.fileName) || isBuiltFile(diagnostic.file.fileName));
13651338
});
13661339

13671340
var numTest262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => {
13681341
// Count an error generated from tests262-harness folder.This should only apply for test262
1369-
return diagnostic.fileName && diagnostic.fileName.indexOf("test262-harness") >= 0;
1342+
return diagnostic.file && diagnostic.file.fileName.indexOf("test262-harness") >= 0;
13701343
});
13711344

13721345
// Verify we didn't miss any errors in total
@@ -1419,17 +1392,6 @@ module Harness {
14191392
//harnessCompiler.compileString(code, unitName, callback);
14201393
}
14211394

1422-
export interface HarnessDiagnostic {
1423-
fileName: string;
1424-
start: number;
1425-
end: number;
1426-
line: number;
1427-
character: number;
1428-
message: string;
1429-
category: string;
1430-
code: number;
1431-
}
1432-
14331395
export interface GeneratedFile {
14341396
fileName: string;
14351397
code: string;
@@ -1459,12 +1421,12 @@ module Harness {
14591421
/** Contains the code and errors of a compilation and some helper methods to check its status. */
14601422
export class CompilerResult {
14611423
public files: GeneratedFile[] = [];
1462-
public errors: HarnessDiagnostic[] = [];
1424+
public errors: ts.Diagnostic[] = [];
14631425
public declFilesCode: GeneratedFile[] = [];
14641426
public sourceMaps: GeneratedFile[] = [];
14651427

14661428
/** @param fileResults an array of strings for the fileName and an ITextWriter with its code */
1467-
constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], public program: ts.Program,
1429+
constructor(fileResults: GeneratedFile[], errors: ts.Diagnostic[], public program: ts.Program,
14681430
public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[]) {
14691431

14701432
fileResults.forEach(emittedFile => {
@@ -1489,15 +1451,6 @@ module Harness {
14891451
return Harness.SourceMapRecoder.getSourceMapRecord(this.sourceMapData, this.program, this.files);
14901452
}
14911453
}
1492-
1493-
public isErrorAt(line: number, column: number, message: string) {
1494-
for (var i = 0; i < this.errors.length; i++) {
1495-
if ((this.errors[i].line + 1) === line && (this.errors[i].character + 1) === column && this.errors[i].message === message)
1496-
return true;
1497-
}
1498-
1499-
return false;
1500-
}
15011454
}
15021455
}
15031456

src/harness/projectsRunner.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,8 @@ class ProjectRunner extends RunnerBase {
323323
sourceFile => {
324324
return { unitName: sourceFile.fileName, content: sourceFile.text };
325325
});
326-
var diagnostics = ts.map(compilerResult.errors, error => Harness.Compiler.getMinimalDiagnostic(error));
327326

328-
return Harness.Compiler.getErrorBaseline(inputFiles, diagnostics);
327+
return Harness.Compiler.getErrorBaseline(inputFiles, compilerResult.errors);
329328
}
330329

331330
var name = 'Compiling project for ' + testCase.scenario + ': testcase ' + testCaseFileName;

tests/baselines/reference/contextualTyping.errors.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
tests/cases/compiler/contextualTyping.ts(189,18): error TS2384: Overload signatures must all be ambient or non-ambient.\ntests/cases/compiler/contextualTyping.ts(197,15): error TS2300: Duplicate identifier 'Point'.\ntests/cases/compiler/contextualTyping.ts(207,10): error TS2300: Duplicate identifier 'Point'.\ntests/cases/compiler/contextualTyping.ts(230,5): error TS2322: Type '{}' is not assignable to type 'B'.
2-
Property 'x' is missing in type '{}'.\n\n\n==== tests/cases/compiler/contextualTyping.ts (4 errors) ====
1+
tests/cases/compiler/contextualTyping.ts(189,18): error TS2384: Overload signatures must all be ambient or non-ambient.
2+
tests/cases/compiler/contextualTyping.ts(197,15): error TS2300: Duplicate identifier 'Point'.
3+
tests/cases/compiler/contextualTyping.ts(207,10): error TS2300: Duplicate identifier 'Point'.
4+
tests/cases/compiler/contextualTyping.ts(230,5): error TS2322: Type '{}' is not assignable to type 'B'.
5+
Property 'x' is missing in type '{}'.
6+
7+
8+
==== tests/cases/compiler/contextualTyping.ts (4 errors) ====
39
// DEFAULT INTERFACES
410
interface IFoo {
511
n: number;

tests/baselines/reference/inlineSourceMap2.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'.
2-
error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'.
31
error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'.
2+
error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'.
3+
error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'.
44
tests/cases/compiler/inlineSourceMap2.ts(5,1): error TS2304: Cannot find name 'console'.
55

66

7-
!!! error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'.
8-
!!! error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'.
97
!!! error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'.
8+
!!! error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'.
9+
!!! error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'.
1010
==== tests/cases/compiler/inlineSourceMap2.ts (1 errors) ====
1111

1212
// configuration errors

tests/baselines/reference/noDefaultLib.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error TS2318: Cannot find global type 'IArguments'.
21
error TS2318: Cannot find global type 'Boolean'.
2+
error TS2318: Cannot find global type 'IArguments'.
33
tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s).
44

55

6-
!!! error TS2318: Cannot find global type 'IArguments'.
76
!!! error TS2318: Cannot find global type 'Boolean'.
7+
!!! error TS2318: Cannot find global type 'IArguments'.
88
==== tests/cases/compiler/noDefaultLib.ts (1 errors) ====
99
/// <reference no-default-lib="true"/>
1010
var x;

tests/baselines/reference/parser509698.errors.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
error TS2318: Cannot find global type 'String'.
2-
error TS2318: Cannot find global type 'RegExp'.
3-
error TS2318: Cannot find global type 'Object'.
4-
error TS2318: Cannot find global type 'Number'.
5-
error TS2318: Cannot find global type 'IArguments'.
6-
error TS2318: Cannot find global type 'Function'.
7-
error TS2318: Cannot find global type 'Boolean'.
81
error TS2318: Cannot find global type 'Array'.
2+
error TS2318: Cannot find global type 'Boolean'.
3+
error TS2318: Cannot find global type 'Function'.
4+
error TS2318: Cannot find global type 'IArguments'.
5+
error TS2318: Cannot find global type 'Number'.
6+
error TS2318: Cannot find global type 'Object'.
7+
error TS2318: Cannot find global type 'RegExp'.
8+
error TS2318: Cannot find global type 'String'.
99

1010

11-
!!! error TS2318: Cannot find global type 'String'.
12-
!!! error TS2318: Cannot find global type 'RegExp'.
13-
!!! error TS2318: Cannot find global type 'Object'.
14-
!!! error TS2318: Cannot find global type 'Number'.
15-
!!! error TS2318: Cannot find global type 'IArguments'.
16-
!!! error TS2318: Cannot find global type 'Function'.
17-
!!! error TS2318: Cannot find global type 'Boolean'.
1811
!!! error TS2318: Cannot find global type 'Array'.
12+
!!! error TS2318: Cannot find global type 'Boolean'.
13+
!!! error TS2318: Cannot find global type 'Function'.
14+
!!! error TS2318: Cannot find global type 'IArguments'.
15+
!!! error TS2318: Cannot find global type 'Number'.
16+
!!! error TS2318: Cannot find global type 'Object'.
17+
!!! error TS2318: Cannot find global type 'RegExp'.
18+
!!! error TS2318: Cannot find global type 'String'.
1919
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ====
2020
/// <style requireSemi="on" />
2121
/// <reference no-default-lib="true"/>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
21
error TS6053: File 'a.ts' not found.
2+
error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
33

44

5-
!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
6-
!!! error TS6053: File 'a.ts' not found.
5+
!!! error TS6053: File 'a.ts' not found.
6+
!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
21
error TS6053: File 'a.ts' not found.
2+
error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
33

44

5-
!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.
6-
!!! error TS6053: File 'a.ts' not found.
5+
!!! error TS6053: File 'a.ts' not found.
6+
!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'.

tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.
21
error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option.
2+
error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.
33

44

5-
!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.
65
!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option.
6+
!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.
77
==== m1.ts (0 errors) ====
88
var m1_a1 = 10;
99
class m1_c1 {

tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.
21
error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option.
2+
error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.
33

44

5-
!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.
65
!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option.
6+
!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.
77
==== m1.ts (0 errors) ====
88
var m1_a1 = 10;
99
class m1_c1 {

0 commit comments

Comments
 (0)