From 9d076ffecc3dc9cc3a8ef411fa8ee61d54b2c3bf Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Thu, 28 Apr 2011 12:17:56 -0400 Subject: [PATCH] Added runAllTests. Useful. --- auto_tests/misc/fake-jstestdriver.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/auto_tests/misc/fake-jstestdriver.js b/auto_tests/misc/fake-jstestdriver.js index 4849f99..9ca10cd 100644 --- a/auto_tests/misc/fake-jstestdriver.js +++ b/auto_tests/misc/fake-jstestdriver.js @@ -43,18 +43,32 @@ function TestCase(name) { return "Fake test case " + name; }; - var emptyFunction = function() { return this; }; - emptyFunction.prototype.setUp = function() { }; - emptyFunction.prototype.tearDown = function() { }; - emptyFunction.prototype.runTest = function(name) { + var testCase = function() { return this; }; + testCase.prototype.setUp = function() { }; + testCase.prototype.tearDown = function() { }; + testCase.prototype.runTest = function(name) { try { this.setUp(); var fn = this[name]; fn.apply(this, []); this.tearDown(); + return true; } catch (e) { console.log(e.stack); + return false; } }; - return emptyFunction; + testCase.prototype.runAllTests = function() { + // what's better than for ... in for non-array objects? + var tests = {}; + for (var name in this) { + if (name.indexOf('test') == 0 && typeof(this[name]) == 'function') { + console.log("Running " + name); + var result = this.runTest(name); + tests[name] = result; + } + } + console.log(prettyPrintEntity_(tests)); + }; + return testCase; }; -- 2.7.4