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 23:11:48 +0200
changeset 26255 2ddcf171ca754ed66b21790336923fecfb5d819d
parent 26254 871f45f364a5158f28f3f5e74ef46c7fae2a23aa
child 26256 92ed133830cfefdf4719a71bc31eb932ae1200c6
push id1893
push usersgautherie.bz@free.fr
push dateFri, 21 Aug 2009 21:15:30 +0000
reviewersrcampbell
bugs494397
milestone1.9.1.3pre
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);
   }
 }