Bug 967564: report operand, even when a custom message is specified. r=gps
authorMike de Boer <mdeboer@mozilla.com>
Mon, 10 Feb 2014 13:12:40 +0100
changeset 167879 62dd35d5057894bfc98a7db8dbb018ebe6d49f08
parent 167878 7dc432174b8aae4006a9735afb7804c3a59f4cba
child 167880 dc07278bb6f84dad9d4d458d4d16cbe4c6f04c0b
push id39593
push userryanvm@gmail.com
push dateMon, 10 Feb 2014 20:43:52 +0000
treeherdermozilla-inbound@9b2e849f5854 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs967564
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 967564: report operand, even when a custom message is specified. r=gps
testing/modules/Assert.jsm
testing/modules/tests/xpcshell/test_assert.js
--- a/testing/modules/Assert.jsm
+++ b/testing/modules/Assert.jsm
@@ -51,32 +51,36 @@ const kTruncateLength = 128;
 function truncate(text, newLength = kTruncateLength) {
   if (typeof text == "string") {
     return text.length < newLength ? text : text.slice(0, newLength);
   } else {
     return text;
   }
 }
 
-function getMessage(error) {
+function getMessage(error, prefix = "") {
   let actual, expected;
   // Wrap calls to JSON.stringify in try...catch blocks, as they may throw. If
   // so, fall back to toString().
   try {
     actual = JSON.stringify(error.actual, replacer);
   } catch (ex) {
     actual = Object.prototype.toString.call(error.actual);
   }
   try {
     expected = JSON.stringify(error.expected, replacer);
   } catch (ex) {
     expected = Object.prototype.toString.call(error.expected);
   }
-  return truncate(actual) + " " + (error.operator ? error.operator + " " : "") +
-         truncate(expected);
+  let message = prefix;
+  if (error.operator) {
+    message += (prefix ? " - " : "") + truncate(actual) + " " + error.operator +
+               " " + truncate(expected);
+  }
+  return message;
 }
 
 /**
  * 2. The AssertionError is defined in assert.
  *
  * Example:
  * new assert.AssertionError({
  *   message: message,
@@ -90,17 +94,17 @@ function getMessage(error) {
  * other keys to the AssertionError's constructor - they will be
  * ignored.
  */
 Assert.AssertionError = function(options) {
   this.name = "AssertionError";
   this.actual = options.actual;
   this.expected = options.expected;
   this.operator = options.operator;
-  this.message = options.message || getMessage(this);
+  this.message = getMessage(this, options.message);
   // The part of the stack that comes from this module is not interesting.
   let stack = Components.stack;
   do {
     stack = stack.caller;
   } while(stack.filename && stack.filename.contains("Assert.jsm"))
   this.stack = stack;
 };
 
--- a/testing/modules/tests/xpcshell/test_assert.js
+++ b/testing/modules/tests/xpcshell/test_assert.js
@@ -271,17 +271,17 @@ function run_test() {
     assert.equal(1, 2);
   } catch (e) {
     assert.equal(e.toString().split("\n")[0], "AssertionError: 1 == 2")
   }
 
   try {
     assert.equal(1, 2, "oh no");
   } catch (e) {
-    assert.equal(e.toString().split("\n")[0], "AssertionError: oh no")
+    assert.equal(e.toString().split("\n")[0], "AssertionError: oh no - 1 == 2")
   }
 
   // Export Assert.jsm methods to become globally accessible.
   export_assertions();
 
   // Test XPCShell-test integration:
   ok(true, "OK, this went well");
   deepEqual(/a/g, /a/g, "deep equal should work on RegExp");