Fix unicode comparision and counting error for test262
This commit is contained in:
parent
778c91ef47
commit
c727efd323
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
declare var require: any;
|
declare var require: any;
|
||||||
declare var process: any;
|
declare var process: any;
|
||||||
|
declare var Buffer: any;
|
||||||
|
|
||||||
// this will work in the browser via browserify
|
// this will work in the browser via browserify
|
||||||
var _chai: typeof chai = require('chai');
|
var _chai: typeof chai = require('chai');
|
||||||
|
@ -1207,7 +1208,6 @@ module Harness {
|
||||||
|
|
||||||
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: HarnessDiagnostic[]) {
|
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: HarnessDiagnostic[]) {
|
||||||
diagnostics.sort(compareDiagnostics);
|
diagnostics.sort(compareDiagnostics);
|
||||||
|
|
||||||
var outputLines: string[] = [];
|
var outputLines: string[] = [];
|
||||||
// Count up all the errors we find so we don't miss any
|
// Count up all the errors we find so we don't miss any
|
||||||
var totalErrorsReported = 0;
|
var totalErrorsReported = 0;
|
||||||
|
@ -1298,8 +1298,13 @@ module Harness {
|
||||||
return diagnostic.filename && isLibraryFile(diagnostic.filename);
|
return diagnostic.filename && isLibraryFile(diagnostic.filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var test262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => {
|
||||||
|
// Count an error generated from tests262-harness folder.This should only apply for test262
|
||||||
|
return diagnostic.filename && diagnostic.filename.indexOf("test262-harness") >= 0;
|
||||||
|
});
|
||||||
|
|
||||||
// Verify we didn't miss any errors in total
|
// Verify we didn't miss any errors in total
|
||||||
assert.equal(totalErrorsReported + numLibraryDiagnostics, diagnostics.length, 'total number of errors');
|
assert.equal(totalErrorsReported + numLibraryDiagnostics + test262HarnessDiagnostics, diagnostics.length, 'total number of errors');
|
||||||
|
|
||||||
return minimalDiagnosticsToString(diagnostics) +
|
return minimalDiagnosticsToString(diagnostics) +
|
||||||
ts.sys.newLine + ts.sys.newLine + outputLines.join('\r\n');
|
ts.sys.newLine + ts.sys.newLine + outputLines.join('\r\n');
|
||||||
|
@ -1642,7 +1647,8 @@ module Harness {
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeComparison(expected: string, actual: string, relativeFilename: string, actualFilename: string, descriptionForDescribe: string) {
|
function writeComparison(expected: string, actual: string, relativeFilename: string, actualFilename: string, descriptionForDescribe: string) {
|
||||||
if (expected != actual) {
|
var encoded_actual = (new Buffer(actual)).toString('utf8')
|
||||||
|
if (expected != encoded_actual) {
|
||||||
// Overwrite & issue error
|
// Overwrite & issue error
|
||||||
var errMsg = 'The baseline file ' + relativeFilename + ' has changed';
|
var errMsg = 'The baseline file ' + relativeFilename + ' has changed';
|
||||||
throw new Error(errMsg);
|
throw new Error(errMsg);
|
||||||
|
|
|
@ -4,8 +4,12 @@ module TypeScript.WebTsc {
|
||||||
|
|
||||||
declare var RealActiveXObject: { new (s: string): any };
|
declare var RealActiveXObject: { new (s: string): any };
|
||||||
|
|
||||||
function getWScriptSystem(): System {
|
function getWScriptSystem() {
|
||||||
var fso = new RealActiveXObject("Scripting.FileSystemObject");
|
var fso = new RealActiveXObject("Scripting.FileSystemObject");
|
||||||
|
|
||||||
|
var fileStream = new ActiveXObject("ADODB.Stream");
|
||||||
|
fileStream.Type = 2 /*text*/;
|
||||||
|
|
||||||
var args: string[] = [];
|
var args: string[] = [];
|
||||||
for (var i = 0; i < WScript.Arguments.length; i++) {
|
for (var i = 0; i < WScript.Arguments.length; i++) {
|
||||||
args[i] = WScript.Arguments.Item(i);
|
args[i] = WScript.Arguments.Item(i);
|
||||||
|
@ -19,17 +23,35 @@ module TypeScript.WebTsc {
|
||||||
writeErr(s: string): void {
|
writeErr(s: string): void {
|
||||||
WScript.StdErr.Write(s);
|
WScript.StdErr.Write(s);
|
||||||
},
|
},
|
||||||
readFile(fileName: string): string {
|
readFile(fileName: string, encoding?: string): string {
|
||||||
|
if (!fso.FileExists(fileName)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
fileStream.Open();
|
||||||
try {
|
try {
|
||||||
var f = fso.OpenTextFile(fileName, 1);
|
if (encoding) {
|
||||||
var s: string = f.ReadAll();
|
fileStream.Charset = encoding;
|
||||||
// TODO: Properly handle byte order marks
|
fileStream.LoadFromFile(fileName);
|
||||||
if (s.length >= 3 && s.charCodeAt(0) === 0xEF && s.charCodeAt(1) === 0xBB && s.charCodeAt(2) === 0xBF) s = s.slice(3);
|
}
|
||||||
f.Close();
|
else {
|
||||||
|
// Load file and read the first two bytes into a string with no interpretation
|
||||||
|
fileStream.Charset = "x-ansi";
|
||||||
|
fileStream.LoadFromFile(fileName);
|
||||||
|
var bom = fileStream.ReadText(2) || "";
|
||||||
|
// Position must be at 0 before encoding can be changed
|
||||||
|
fileStream.Position = 0;
|
||||||
|
// [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8
|
||||||
|
fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
|
||||||
|
}
|
||||||
|
// ReadText method always strips byte order mark from resulting string
|
||||||
|
return fileStream.ReadText();
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
fileStream.Close();
|
||||||
}
|
}
|
||||||
return s;
|
|
||||||
},
|
},
|
||||||
writeFile(fileName: string, data: string): boolean {
|
writeFile(fileName: string, data: string): boolean {
|
||||||
var f = fso.CreateTextFile(fileName, true);
|
var f = fso.CreateTextFile(fileName, true);
|
||||||
|
|
Loading…
Reference in a new issue