mirror of
https://gitee.com/openharmony/third_party_typescript
synced 2024-11-30 18:42:25 +00:00
Updated error reporting within harness to match that of tsc.
This commit is contained in:
parent
d05a4c40b5
commit
7f4ae93904
@ -563,7 +563,7 @@ module Harness {
|
||||
private compileOptions: ts.CompilerOptions;
|
||||
private settings: Harness.TestCaseParser.CompilerSetting[] = [];
|
||||
|
||||
private lastErrors: MinimalDiagnostic[];
|
||||
private lastErrors: HarnessDiagnostic[];
|
||||
|
||||
public reset() {
|
||||
this.inputFiles = [];
|
||||
@ -750,7 +750,7 @@ module Harness {
|
||||
emitResult = checker.emitFiles();
|
||||
}
|
||||
|
||||
var errors: MinimalDiagnostic[] = [];
|
||||
var errors: HarnessDiagnostic[] = [];
|
||||
program.getDiagnostics().concat(checker.getDiagnostics()).concat(emitResult ? emitResult.errors : []).forEach(err => {
|
||||
// TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now
|
||||
errors.push(getMinimalDiagnostic(err));
|
||||
@ -768,35 +768,43 @@ module Harness {
|
||||
}
|
||||
}
|
||||
|
||||
export function getMinimalDiagnostic(err: ts.Diagnostic): MinimalDiagnostic {
|
||||
export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic {
|
||||
var errorLineInfo = err.file ? err.file.getLineAndCharacterFromPosition(err.start) : { line: 0, character: 0 };
|
||||
return { filename: err.file && err.file.filename, start: err.start, end: err.start + err.length, line: errorLineInfo.line, character: errorLineInfo.character, message: err.messageText };
|
||||
return {
|
||||
filename: err.file && err.file.filename,
|
||||
start: err.start,
|
||||
end: err.start + err.length,
|
||||
line: errorLineInfo.line,
|
||||
character: errorLineInfo.character,
|
||||
message: err.messageText,
|
||||
category: ts.DiagnosticCategory[err.category].toLowerCase(),
|
||||
code: err.code
|
||||
};
|
||||
}
|
||||
|
||||
export function minimalDiagnosticsToString(diagnostics: MinimalDiagnostic[]) {
|
||||
// This is copied from tsc.ts's reportError to replicate what tsc does
|
||||
var errors = "";
|
||||
export function minimalDiagnosticsToString(diagnostics: HarnessDiagnostic[]) {
|
||||
// This is basically copied from tsc.ts's reportError to replicate what tsc does
|
||||
var errorOutput = "";
|
||||
ts.forEach(diagnostics, diagnotic => {
|
||||
if (diagnotic.filename) {
|
||||
errors += diagnotic.filename + "(" + diagnotic.line + "," + diagnotic.character + "): " + diagnotic.message + sys.newLine;
|
||||
}
|
||||
else {
|
||||
errors += diagnotic.message + sys.newLine;
|
||||
errorOutput += diagnotic.filename + "(" + diagnotic.line + "," + diagnotic.character + "): ";
|
||||
}
|
||||
|
||||
errorOutput += diagnotic.category + " TS" + diagnotic.code + ": " + diagnotic.message + sys.newLine;
|
||||
});
|
||||
|
||||
return errors;
|
||||
return errorOutput;
|
||||
}
|
||||
|
||||
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[],
|
||||
diagnostics: MinimalDiagnostic[]
|
||||
diagnostics: HarnessDiagnostic[]
|
||||
) {
|
||||
|
||||
var outputLines: string[] = [];
|
||||
// Count up all the errors we find so we don't miss any
|
||||
var totalErrorsReported = 0;
|
||||
|
||||
function outputErrorText(error: Harness.Compiler.MinimalDiagnostic) {
|
||||
function outputErrorText(error: Harness.Compiler.HarnessDiagnostic) {
|
||||
var errLines = RunnerBase.removeFullPaths(error.message)
|
||||
.split('\n')
|
||||
.map(s => s.length > 0 && s.charAt(s.length - 1) === '\r' ? s.substr(0, s.length - 1) : s)
|
||||
@ -916,13 +924,15 @@ module Harness {
|
||||
//harnessCompiler.compileString(code, unitName, callback);
|
||||
}
|
||||
|
||||
export interface MinimalDiagnostic {
|
||||
export interface HarnessDiagnostic {
|
||||
filename: string;
|
||||
start: number;
|
||||
end: number;
|
||||
line: number;
|
||||
character: number;
|
||||
message: string;
|
||||
category: string;
|
||||
code: number;
|
||||
}
|
||||
|
||||
export interface GeneratedFile {
|
||||
@ -950,13 +960,13 @@ module Harness {
|
||||
/** Contains the code and errors of a compilation and some helper methods to check its status. */
|
||||
export class CompilerResult {
|
||||
public files: GeneratedFile[] = [];
|
||||
public errors: MinimalDiagnostic[] = [];
|
||||
public errors: HarnessDiagnostic[] = [];
|
||||
public declFilesCode: GeneratedFile[] = [];
|
||||
public sourceMaps: GeneratedFile[] = [];
|
||||
public sourceMapRecord: string;
|
||||
|
||||
/** @param fileResults an array of strings for the fileName and an ITextWriter with its code */
|
||||
constructor(fileResults: GeneratedFile[], errors: MinimalDiagnostic[], sourceMapRecordLines: string[]) {
|
||||
constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], sourceMapRecordLines: string[]) {
|
||||
var lines: string[] = [];
|
||||
|
||||
fileResults.forEach(emittedFile => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
decl.ts(1,26): Cannot find external module './foo/bar.js'.
|
||||
decl.ts(2,26): Cannot find external module 'baz'.
|
||||
decl.ts(3,26): Cannot find external module './baz'.
|
||||
decl.ts(1,26): error TS2307: Cannot find external module './foo/bar.js'.
|
||||
decl.ts(2,26): error TS2307: Cannot find external module 'baz'.
|
||||
decl.ts(3,26): error TS2307: Cannot find external module './baz'.
|
||||
|
||||
|
||||
==== decl.ts (3 errors) ====
|
||||
|
@ -1,6 +1,6 @@
|
||||
decl.ts(1,26): Cannot find external module './foo/bar.js'.
|
||||
decl.ts(2,26): Cannot find external module 'baz'.
|
||||
decl.ts(3,26): Cannot find external module './baz'.
|
||||
decl.ts(1,26): error TS2307: Cannot find external module './foo/bar.js'.
|
||||
decl.ts(2,26): error TS2307: Cannot find external module 'baz'.
|
||||
decl.ts(3,26): error TS2307: Cannot find external module './baz'.
|
||||
|
||||
|
||||
==== decl.ts (3 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
in2.d.ts(1,8): Duplicate identifier 'a'.
|
||||
in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'.
|
||||
|
||||
|
||||
==== decl.d.ts (0 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
in2.d.ts(1,8): Duplicate identifier 'a'.
|
||||
in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'.
|
||||
|
||||
|
||||
==== decl.d.ts (0 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
internal2.ts(2,2): Import declarations in an internal module cannot reference an external module.
|
||||
internal2.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== internal2.ts (1 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
internal2.ts(2,2): Import declarations in an internal module cannot reference an external module.
|
||||
internal2.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== internal2.ts (1 errors) ====
|
||||
|
@ -1,5 +1,5 @@
|
||||
Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
|
||||
|
||||
!!! Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
|
@ -1,5 +1,5 @@
|
||||
Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
|
||||
|
||||
!!! Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
|
@ -1,4 +1,4 @@
|
||||
Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
|
||||
|
||||
!!! Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
|
@ -1,4 +1,4 @@
|
||||
Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
error TS5038: Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
|
||||
|
||||
!!! Option mapRoot cannot be specified without specifying sourcemap option.
|
||||
|
@ -1,4 +1,4 @@
|
||||
test1.ts(2,2): Import declarations in an internal module cannot reference an external module.
|
||||
test1.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== test1.ts (1 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
test1.ts(2,2): Import declarations in an internal module cannot reference an external module.
|
||||
test1.ts(2,2): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== test1.ts (1 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
test1.ts(3,2): Import declarations in an internal module cannot reference an external module.
|
||||
test1.ts(3,2): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== test1.ts (1 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
test1.ts(3,2): Import declarations in an internal module cannot reference an external module.
|
||||
test1.ts(3,2): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== test1.ts (1 errors) ====
|
||||
|
@ -1,12 +1,12 @@
|
||||
Cannot find global type 'Array'.
|
||||
Cannot find global type 'Boolean'.
|
||||
Cannot find global type 'Function'.
|
||||
Cannot find global type 'IArguments'.
|
||||
Cannot find global type 'Number'.
|
||||
Cannot find global type 'Object'.
|
||||
Cannot find global type 'RegExp'.
|
||||
Cannot find global type 'String'.
|
||||
test.ts(3,8): Cannot find name 'Array'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
error TS2318: Cannot find global type 'Boolean'.
|
||||
error TS2318: Cannot find global type 'Function'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'Object'.
|
||||
error TS2318: Cannot find global type 'RegExp'.
|
||||
error TS2318: Cannot find global type 'String'.
|
||||
test.ts(3,8): error TS2304: Cannot find name 'Array'.
|
||||
|
||||
|
||||
!!! Cannot find global type 'Array'.
|
||||
|
@ -1,12 +1,12 @@
|
||||
Cannot find global type 'Array'.
|
||||
Cannot find global type 'Boolean'.
|
||||
Cannot find global type 'Function'.
|
||||
Cannot find global type 'IArguments'.
|
||||
Cannot find global type 'Number'.
|
||||
Cannot find global type 'Object'.
|
||||
Cannot find global type 'RegExp'.
|
||||
Cannot find global type 'String'.
|
||||
test.ts(3,8): Cannot find name 'Array'.
|
||||
error TS2318: Cannot find global type 'Array'.
|
||||
error TS2318: Cannot find global type 'Boolean'.
|
||||
error TS2318: Cannot find global type 'Function'.
|
||||
error TS2318: Cannot find global type 'IArguments'.
|
||||
error TS2318: Cannot find global type 'Number'.
|
||||
error TS2318: Cannot find global type 'Object'.
|
||||
error TS2318: Cannot find global type 'RegExp'.
|
||||
error TS2318: Cannot find global type 'String'.
|
||||
test.ts(3,8): error TS2304: Cannot find name 'Array'.
|
||||
|
||||
|
||||
!!! Cannot find global type 'Array'.
|
||||
|
@ -1,5 +1,5 @@
|
||||
testGlo.ts(2,5): Import declarations in an internal module cannot reference an external module.
|
||||
testGlo.ts(21,5): Import declarations in an internal module cannot reference an external module.
|
||||
testGlo.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== testGlo.ts (2 errors) ====
|
||||
|
@ -1,5 +1,5 @@
|
||||
testGlo.ts(2,5): Import declarations in an internal module cannot reference an external module.
|
||||
testGlo.ts(21,5): Import declarations in an internal module cannot reference an external module.
|
||||
testGlo.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
testGlo.ts(21,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== testGlo.ts (2 errors) ====
|
||||
|
@ -1,5 +1,5 @@
|
||||
test.ts(5,5): Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(24,5): Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(5,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(24,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== test.ts (2 errors) ====
|
||||
|
@ -1,5 +1,5 @@
|
||||
test.ts(5,5): Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(24,5): Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(5,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(24,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== test.ts (2 errors) ====
|
||||
|
@ -1,5 +1,5 @@
|
||||
test.ts(2,5): Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(42,5): Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(42,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== test.ts (2 errors) ====
|
||||
|
@ -1,5 +1,5 @@
|
||||
test.ts(2,5): Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(42,5): Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(2,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
test.ts(42,5): error TS1147: Import declarations in an internal module cannot reference an external module.
|
||||
|
||||
|
||||
==== test.ts (2 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
m'ain.d.ts(1,1): File 'li.ts' not found.
|
||||
m'ain.d.ts(1,1): error TS6053: File 'li.ts' not found.
|
||||
|
||||
|
||||
==== li'b/class'A.d.ts (0 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
m'ain.d.ts(1,1): File 'li.ts' not found.
|
||||
m'ain.d.ts(1,1): error TS6053: File 'li.ts' not found.
|
||||
|
||||
|
||||
==== li'b/class'A.d.ts (0 errors) ====
|
||||
|
@ -1,4 +1,4 @@
|
||||
Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
|
||||
|
||||
!!! Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
|
@ -1,4 +1,4 @@
|
||||
Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
error TS5039: Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
|
||||
|
||||
!!! Option sourceRoot cannot be specified without specifying sourcemap option.
|
||||
|
@ -1,5 +1,5 @@
|
||||
main.ts(2,1): File 'nonExistingFile1.ts' not found.
|
||||
main.ts(3,1): File 'nonExistingFile2.ts' not found.
|
||||
main.ts(2,1): error TS6053: File 'nonExistingFile1.ts' not found.
|
||||
main.ts(3,1): error TS6053: File 'nonExistingFile2.ts' not found.
|
||||
|
||||
|
||||
==== main.ts (2 errors) ====
|
||||
|
@ -1,5 +1,5 @@
|
||||
main.ts(2,1): File 'nonExistingFile1.ts' not found.
|
||||
main.ts(3,1): File 'nonExistingFile2.ts' not found.
|
||||
main.ts(2,1): error TS6053: File 'nonExistingFile1.ts' not found.
|
||||
main.ts(3,1): error TS6053: File 'nonExistingFile2.ts' not found.
|
||||
|
||||
|
||||
==== main.ts (2 errors) ====
|
||||
|
Loading…
Reference in New Issue
Block a user