diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 78546f81c73..10a87108d43 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1340,8 +1340,8 @@ module Harness { export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: ts.Diagnostic[]) { diagnostics.sort(ts.compareDiagnostics); let outputLines: string[] = []; - // Count up all the errors we find so we don't miss any - let totalErrorsReported = 0; + // Count up all errors that were found in files other than lib.d.ts so we don't miss any + let totalErrorsReportedInNonLibraryFiles = 0; function outputErrorText(error: ts.Diagnostic) { let message = ts.flattenDiagnosticMessageText(error.messageText, Harness.IO.newLine()); @@ -1352,8 +1352,15 @@ module Harness { .filter(s => s.length > 0) .map(s => "!!! " + ts.DiagnosticCategory[error.category].toLowerCase() + " TS" + error.code + ": " + s); errLines.forEach(e => outputLines.push(e)); - - totalErrorsReported++; + + // do not count errors from lib.d.ts here, they are computed separately as numLibraryDiagnostics + // if lib.d.ts is explicitly included in input files and there are some errors in it (i.e. because of duplicate identifiers) + // then they will be added twice thus triggering 'total errors' assertion with condition + // 'totalErrorsReportedInNonLibraryFiles + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length + + if (!error.file || !isLibraryFile(error.file.fileName)) { + totalErrorsReportedInNonLibraryFiles++; + } } // Report global errors @@ -1438,7 +1445,7 @@ module Harness { }); // Verify we didn't miss any errors in total - assert.equal(totalErrorsReported + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length, "total number of errors"); + assert.equal(totalErrorsReportedInNonLibraryFiles + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length, "total number of errors"); return minimalDiagnosticsToString(diagnostics) + Harness.IO.newLine() + Harness.IO.newLine() + outputLines.join("\r\n"); @@ -1816,11 +1823,11 @@ module Harness { return filePath.indexOf(Harness.libFolder) === 0; } - export function getDefaultLibraryFile(): { unitName: string, content: string } { + export function getDefaultLibraryFile(io: Harness.IO): { unitName: string, content: string } { let libFile = Harness.userSpecifiedRoot + Harness.libFolder + "lib.d.ts"; return { unitName: libFile, - content: IO.readFile(libFile) + content: io.readFile(libFile) }; } diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index c89a8b1d910..a1aaeed3d55 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -4,7 +4,7 @@ /// module RWC { - function runWithIOLog(ioLog: IOLog, fn: () => void) { + function runWithIOLog(ioLog: IOLog, fn: (oldIO: Harness.IO) => void) { let oldIO = Harness.IO; let wrappedIO = Playback.wrapIO(oldIO); @@ -12,7 +12,7 @@ module RWC { Harness.IO = wrappedIO; try { - fn(); + fn(oldIO); } finally { wrappedIO.endReplay(); Harness.IO = oldIO; @@ -32,9 +32,6 @@ module RWC { let baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2]; let currentDirectory: string; let useCustomLibraryFile: boolean; - - const defaultLibraryFile = Harness.getDefaultLibraryFile(); - after(() => { // Mocha holds onto the closure environment of the describe callback even after the test is done. // Therefore we have to clean out large objects after the test is done. @@ -67,7 +64,7 @@ module RWC { opts.options.noEmitOnError = false; }); - runWithIOLog(ioLog, () => { + runWithIOLog(ioLog, oldIO => { harnessCompiler.reset(); // Load the files @@ -77,7 +74,6 @@ module RWC { // Add files to compilation let isInInputList = (resolvedPath: string) => (inputFile: { unitName: string; content: string; }) => inputFile.unitName === resolvedPath; - let prependDefaultLib = false; for (let fileRead of ioLog.filesRead) { // Check if the file is already added into the set of input files. const resolvedPath = ts.normalizeSlashes(Harness.IO.resolvePath(fileRead.path)); @@ -101,15 +97,11 @@ module RWC { } else { // set the flag to put default library to the beginning of the list - prependDefaultLib = true; + inputFiles.unshift(Harness.getDefaultLibraryFile(oldIO)); } } } } - - if (prependDefaultLib) { - inputFiles.unshift(defaultLibraryFile); - } // do not use lib since we already read it in above opts.options.noLib = true;