Changeset 9116
- Timestamp:
- 06/13/08 16:11:41 (3 months ago)
- Files:
-
- sandbox/aida/demo-app/app/controllers/testing_controller.js (modified) (1 diff)
- sandbox/aida/modules/testing/unittest.js (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/aida/demo-app/app/controllers/testing_controller.js
r9115 r9116 7 7 8 8 this.index_action = function () { 9 testing.selftest.run(); 10 render("testing"); 9 var tr = testing.selftest.run() 10 tr.write(shell); 11 render("testing:" + tr); 11 12 } 12 13 sandbox/aida/modules/testing/unittest.js
r9115 r9116 1 1 importModule("core.string"); 2 importFromModule("helma.shell", "*");3 2 4 3 var __shared__ = true; … … 115 114 116 115 /** 117 * Creates a new ShellWriter instance116 * Creates a new Writer instance 118 117 * @class Instances of this class provide functionality for displaying 119 118 * a test result inside a shell … … 121 120 * @constructor 122 121 */ 123 var ShellWriter = function() { 122 var Writer = function(writer) { 123 124 function print() { 125 if (writer) writer.writeln.apply(writer, arguments); 126 else { 127 writeln.apply(this, arguments); 128 } 129 } 124 130 125 131 /** … … 145 151 */ 146 152 var writeTestResult = function(result) { 147 writeln("Executing", result.test.constructor.name, "'" + result.test.name + "'", "...");153 print("Executing", result.test.constructor.name, "'" + result.test.name + "'", "..."); 148 154 result.log.forEach(function(logItem) { 149 155 if (logItem instanceof TestResult) { 150 writeln("-------------------------------------------------------------------------------");156 print("-------------------------------------------------------------------------------"); 151 157 writeTestResult(logItem); 152 158 } else { … … 165 171 var writeExecutionResult = function(result) { 166 172 if (result.wasSuccessful() === true) { 167 writeln("PASSED:", result.name, "(" + result.time, "ms)");173 print("PASSED:", result.name, "(" + result.time, "ms)"); 168 174 } else { 169 175 if (result.exception instanceof FailureException) { 170 writeln("FAILED:", result.name);176 print("FAILED:", result.name); 171 177 } else { 172 writeln("ERROR:", result.name);178 print("ERROR:", result.name); 173 179 } 174 180 if (result.exception.comment != null) { 175 writeln(" ", result.exception.comment);176 } 177 writeln(" ", result.exception.message);181 print(" ", result.exception.comment); 182 } 183 print(" ", result.exception.message); 178 184 if (result.exception.stackTrace != null) { 179 185 result.exception.stackTrace.forEach(function(line) { 180 writeln(" ", line);186 print(" ", line); 181 187 }); 182 188 } … … 190 196 */ 191 197 this.write = function(result) { 192 writeln("===============================================================================");198 print("==============================================================================="); 193 199 if (result != null) { 194 200 writeTestResult(result); 195 writeln("===============================================================================");196 writeln("Ran", result.testsRun,201 print("==============================================================================="); 202 print("Ran", result.testsRun, 197 203 pluralize("test", "tests", result.testsRun), 198 204 "in", result.time, "ms", … … 200 206 result.errors, pluralize("error", "errors", result.errors) + ")"); 201 207 } else { 202 writeln("No tests found");208 print("No tests found"); 203 209 } 204 210 return; … … 209 215 210 216 /** @ignore */ 211 ShellWriter.prototype.toString = function() {212 return "[ ShellWriter]";217 Writer.prototype.toString = function() { 218 return "[Writer]"; 213 219 }; 214 220 … … 294 300 return; 295 301 }; 302 303 /** 304 * Prints this TestResult. 305 * Takes an optional writer object (res, shell, ...) which has to provide a 306 * writeln() method. Otherwise it will write to the shell. 307 * If you call this method outside the shell environment you have to provide a writer. 308 * 309 * @example 310 * importModule("helma.shell", "shell"); 311 * importModule("testing.selftest"); 312 * testing.selftest.run().write(shell); 313 * 314 * @param {object} writer Writer object, which provides a writeln method. 315 * @return {TestResult} TestResult for chaining purpose 316 */ 317 this.write = function(writer) { 318 (new Writer(writer)).write(this); 319 return this; 320 } 296 321 297 322 return this; … … 528 553 } 529 554 } 530 (new ShellWriter()).write(testResult);555 // (new Writer()).write(testResult); 531 556 // cleanup 532 557 unloadTestModule(); … … 603 628 this.TestCase.prototype.run = function(methodName) { 604 629 var testResult = new TestResult(this); 605 (new ShellWriter()).write(this.execute(testResult, methodName));606 return ;630 // (new Writer()).write(this.execute(testResult, methodName)); 631 return testResult; 607 632 }; 608 633 … … 741 766 this.TestSuite.prototype.run = function() { 742 767 var testResult = new TestResult(this); 743 (new ShellWriter()).write(this.execute(testResult));744 return ;768 // (new Writer()).write(this.execute(testResult)); 769 return testResult; 745 770 }; 746 771