Bug 494397 - SimpleTest.js |window.onerror| calls |SimpleTest.finish()| while test is still running; (Bv2) Update interactive report, Use 'diag' parameter from |window.onerror|; r=rcampbell
authorSerge Gautherie <sgautherie.bz@free.fr>
Fri, 21 Aug 2009 20:41:44 +0200
changeset 31740 5d7e05797de097f50081b21f45532492354bfdf4
parent 31739 d3a69e6a1a5a991db548464f7f64378717125395
child 31741 f8f1a9113a1c99cfb55fd49fb2720dd2655e31b2
push id8697
push usersgautherie.bz@free.fr
push dateFri, 21 Aug 2009 18:48:59 +0000
treeherdermozilla-central@f8f1a9113a1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrcampbell
bugs494397
milestone1.9.3a1pre
Bug 494397 - SimpleTest.js |window.onerror| calls |SimpleTest.finish()| while test is still running; (Bv2) Update interactive report, Use 'diag' parameter from |window.onerror|; r=rcampbell
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -29,17 +29,17 @@ if (parentRunner) {
 
 SimpleTest._tests = [];
 SimpleTest._stopOnLoad = true;
 
 /**
  * Something like assert.
 **/
 SimpleTest.ok = function (condition, name, diag) {
-    var test = {'result': !!condition, 'name': name, 'diag': diag || ""};
+    var test = {'result': !!condition, 'name': name, 'diag': diag};
     if (SimpleTest._logEnabled)
         SimpleTest._logResult(test, "TEST-PASS", "TEST-UNEXPECTED-FAIL");
     SimpleTest._tests.push(test);
 };
 
 /**
  * Roughly equivalent to ok(a==b, name)
 **/
@@ -51,31 +51,29 @@ SimpleTest.is = function (a, b, name) {
 SimpleTest.isnot = function (a, b, name) {
     var repr = MochiKit.Base.repr;
     SimpleTest.ok(a != b, name, "Didn't expect " + repr(a) + ", but got it.");
 };
 
 //  --------------- Test.Builder/Test.More todo() -----------------
 
 SimpleTest.todo = function(condition, name, diag) {
-  var test = {'result': !!condition, 'name': name, 'diag': diag || "", todo: true};
+  var test = {'result': !!condition, 'name': name, 'diag': diag, todo: true};
   if (SimpleTest._logEnabled)
       SimpleTest._logResult(test, "TEST-UNEXPECTED-PASS", "TEST-KNOWN-FAIL");
   SimpleTest._tests.push(test);
 };
 
 SimpleTest._logResult = function(test, passString, failString) {
   var msg = test.result ? passString : failString;
   msg += " | ";
   if (parentRunner.currentTestURL)
     msg += parentRunner.currentTestURL;
   msg += " | " + test.name;
-  var diag = "";
-  if (test.diag)
-    diag = " - " + test.diag;
+  var diag = test.diag ? " - " + test.diag : "";
   if (test.result) {
       if (test.todo)
           parentRunner.logger.error(msg + diag);
       else
           parentRunner.logger.log(msg);
   } else {
       if (test.todo)
           parentRunner.logger.log(msg);
@@ -111,28 +109,29 @@ SimpleTest.report = function () {
     // Report tests which did not actually check anything.
     if (SimpleTest._tests.length == 0)
       // ToDo: Do s/todo/ok/ when all the tests are fixed. (Bug 483407)
       SimpleTest.todo(false, "[SimpleTest.report()] No checks actually run.");
 
     var results = MochiKit.Base.map(
         function (test) {
             var cls, msg;
+            var diag = test.diag ? " - " + test.diag : "";
             if (test.todo && !test.result) {
                 todo++;
                 cls = "test_todo";
-                msg = "todo - " + test.name + " " + test.diag;
+                msg = "todo | " + test.name + diag;
             } else if (test.result && !test.todo) {
                 passed++;
                 cls = "test_ok";
-                msg = "ok - " + test.name;
+                msg = "passed | " + test.name;
             } else {
                 failed++;
                 cls = "test_not_ok";
-                msg = "not ok - " + test.name + " " + test.diag;
+                msg = "failed | " + test.name + diag;
             }
             return DIV({"class": cls}, msg);
         },
         SimpleTest._tests
     );
 
     var summary_class = failed != 0 ? 'some_fail' :
                           passed == 0 ? 'todo_only' : 'all_pass';
@@ -463,25 +462,25 @@ var isnot = SimpleTest.isnot;
 var todo = SimpleTest.todo;
 var todo_is = SimpleTest.todo_is;
 var todo_isnot = SimpleTest.todo_isnot;
 var isDeeply = SimpleTest.isDeeply;
 
 const oldOnError = window.onerror;
 window.onerror = function (ev) {
   // Log the error.
-  ok(false, "[SimpleTest/SimpleTest.js, window.onerror] An error occurred: [ " + ev + " ]");
+  ok(false, "[SimpleTest/SimpleTest.js, window.onerror] An error occurred", ev);
 
   // Call previous handler.
   if (oldOnError) {
     try {
       oldOnError(ev);
     } catch (e) {
       // Log the exception.
-      ok(false, "[SimpleTest/SimpleTest.js, window.onerror] Exception thrown by oldOnError(): [ " + e + " ]");
+      ok(false, "[SimpleTest/SimpleTest.js, window.onerror] Exception thrown by oldOnError()", e);
     }
   }
 
   if (!SimpleTest._stopOnLoad) {
     // Need to finish() manually here, yet let the test actually end first.
     SimpleTest.executeSoon(SimpleTest.finish);
   }
 }