Bug 1346234 - Part 18: Use template strings to concatenate error messages. r=sfink

--HG--
extra : rebase_source : 3275a41cbdbd5c6723cb3d5f5fbef4a9613b6377
This commit is contained in:
André Bargull 2017-10-31 08:02:57 -07:00
parent d95f79b00a
commit 7b6aa6cce9

View File

@ -128,8 +128,7 @@
if (typeof assertEq !== "function") {
assertEq = function assertEq(actual, expected, message) {
if (!SameValue(actual, expected)) {
throw new TypeError('Assertion failed: got "' + actual + '", ' +
'expected "' + expected + '"' +
throw new TypeError(`Assertion failed: got "${actual}", expected "${expected}"` +
(message ? ": " + message : ""));
}
};
@ -145,7 +144,7 @@
for (; i < len; i++)
assertEq(actual[i], expected[i], "mismatch at element " + i);
} catch (e) {
throw new Error("Exception thrown at index " + i + ": " + e);
throw new Error(`Exception thrown at index ${i}: ${e}`);
}
}
global.assertEqArray = assertEqArray;
@ -158,7 +157,7 @@
ok = true;
}
if (!ok)
throw new Error("Assertion failed: " + f + " did not throw as expected");
throw new Error(`Assertion failed: ${f} did not throw as expected`);
}
global.assertThrows = assertThrows;
@ -169,15 +168,11 @@
} catch (exc) {
if (exc instanceof ctor)
return;
fullmsg =
"Assertion failed: expected exception " + ctor.name + ", got " + exc;
fullmsg = `Assertion failed: expected exception ${ctor.name}, got ${exc}`;
}
if (fullmsg === undefined) {
fullmsg =
"Assertion failed: expected exception " + ctor.name + ", " +
"no exception thrown";
}
if (fullmsg === undefined)
fullmsg = `Assertion failed: expected exception ${ctor.name}, no exception thrown`;
if (msg !== undefined)
fullmsg += " - " + msg;
@ -433,14 +428,14 @@
// let reftest handle error reporting, otherwise
// output a summary line.
if (!runningInBrowser) {
dump('\njstest: ' + this.path + ' ' +
'bug: ' + this.bugnumber + ' ' +
'result: ' + (this.passed ? 'PASSED' : 'FAILED') + ' ' +
'type: ' + this.type + ' ' +
'description: ' + toPrinted(this.description) + ' ' +
// 'expected: ' + toPrinted(this.expect) + ' ' +
// 'actual: ' + toPrinted(this.actual) + ' ' +
'reason: ' + toPrinted(this.reason) + '\n');
dump(`\njstest: ${this.path} ` +
`bug: ${this.bugnumber} ` +
`result: ${this.passed ? 'PASSED' : 'FAILED'} ` +
`type: ${this.type} ` +
`description: ${toPrinted(this.description)} ` +
// `expected: ${toPrinted(this.expect)} ` +
// `actual: ${toPrinted(this.actual)} ` +
`reason: ${toPrinted(this.reason)}\n`);
}
};
@ -475,6 +470,19 @@
return true;
}
function reportTestCaseResult(description, expected, actual, output) {
var testcase = new TestCase("unknown-test-name", description, expected, actual, output);
// if running under reftest, let it handle result reporting.
if (!runningInBrowser) {
if (testcase.passed) {
print(PASSED + description);
} else {
reportFailure(description + " : " + output);
}
}
}
function getTestCases() {
return testCasesArray;
}
@ -543,28 +551,15 @@
var output = "";
if (typeof description === "undefined")
description = '';
description = "";
if (expected_t !== actual_t) {
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + " ";
}
if (expected_t !== actual_t)
output += `Type mismatch, expected type ${expected_t}, actual type ${actual_t} `;
if (expected != actual) {
output += "Expected value '" + toPrinted(expected) +
"', Actual value '" + toPrinted(actual) + "' ";
}
if (expected != actual)
output += `Expected value '${toPrinted(expected)}', Actual value '${toPrinted(actual)}' `;
var testcase = new TestCase("unknown-test-name", description, expected, actual, output);
// if running under reftest, let it handle result reporting.
if (!runningInBrowser) {
if (testcase.passed) {
print(PASSED + description);
} else {
reportFailure(description + " : " + output);
}
}
reportTestCaseResult(description, expected, actual, output);
}
global.reportCompare = reportCompare;
@ -580,29 +575,18 @@
var output = "";
if (typeof description === "undefined")
description = '';
description = "";
if (expected_t !== actual_t) {
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + " ";
}
if (expected_t !== actual_t)
output += `Type mismatch, expected type ${expected_t}, actual type ${actual_t} `;
var matches = ReflectApply(RegExpPrototypeExec, expectedRegExp, [actual]) !== null;
if (!matches) {
output += "Expected match to '" + toPrinted(expectedRegExp) +
"', Actual value '" + toPrinted(actual) + "' ";
output +=
`Expected match to '${toPrinted(expectedRegExp)}', Actual value '${toPrinted(actual)}' `;
}
var testcase = new TestCase("unknown-test-name", description, true, matches, output);
// if running under reftest, let it handle result reporting.
if (!runningInBrowser) {
if (testcase.passed) {
print(PASSED + description);
} else {
reportFailure(description + " : " + output);
}
}
reportTestCaseResult(description, true, matches, output);
}
global.reportMatch = reportMatch;