mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
pass IO when getting default library instead of reading it to prevent
memory leaks, do not count errors in library files twice
This commit is contained in:
parent
af2a49992f
commit
8df7cbb515
@ -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)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
/// <reference path="..\compiler\commandLineParser.ts"/>
|
||||
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user