Changeset 9116

Show
Ignore:
Timestamp:
06/13/08 16:11:41 (3 months ago)
Author:
matthias
Message:

* checked in adapted testing:

  • always return the testResult
  • testResult has a write() method
  • the write() method takes an optional writer object (which has to provide a writeln() method)
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/aida/demo-app/app/controllers/testing_controller.js

    r9115 r9116  
    77    
    88   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); 
    1112   } 
    1213    
  • sandbox/aida/modules/testing/unittest.js

    r9115 r9116  
    11importModule("core.string"); 
    2 importFromModule("helma.shell", "*"); 
    32 
    43var __shared__ = true; 
     
    115114    
    116115   /** 
    117     * Creates a new ShellWriter instance 
     116    * Creates a new Writer instance 
    118117    * @class Instances of this class provide functionality for displaying 
    119118    * a test result inside a shell 
     
    121120    * @constructor 
    122121    */ 
    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      }       
    124130       
    125131      /** 
     
    145151       */ 
    146152      var writeTestResult = function(result) { 
    147          writeln("Executing", result.test.constructor.name, "'" + result.test.name + "'", "..."); 
     153         print("Executing", result.test.constructor.name, "'" + result.test.name + "'", "..."); 
    148154         result.log.forEach(function(logItem) { 
    149155            if (logItem instanceof TestResult) { 
    150                writeln("-------------------------------------------------------------------------------"); 
     156               print("-------------------------------------------------------------------------------"); 
    151157               writeTestResult(logItem); 
    152158            } else { 
     
    165171      var writeExecutionResult = function(result) { 
    166172         if (result.wasSuccessful() === true) { 
    167             writeln("PASSED:", result.name, "(" + result.time, "ms)"); 
     173            print("PASSED:", result.name, "(" + result.time, "ms)"); 
    168174         } else { 
    169175            if (result.exception instanceof FailureException) { 
    170                writeln("FAILED:", result.name); 
     176               print("FAILED:", result.name); 
    171177            } else { 
    172                writeln("ERROR:", result.name); 
     178               print("ERROR:", result.name); 
    173179            } 
    174180            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); 
    178184            if (result.exception.stackTrace != null) { 
    179185               result.exception.stackTrace.forEach(function(line) { 
    180                   writeln("   ", line); 
     186                  print("   ", line); 
    181187               }); 
    182188            } 
     
    190196       */ 
    191197      this.write = function(result) { 
    192          writeln("==============================================================================="); 
     198         print("==============================================================================="); 
    193199         if (result != null) { 
    194200            writeTestResult(result); 
    195             writeln("==============================================================================="); 
    196             writeln("Ran", result.testsRun, 
     201            print("==============================================================================="); 
     202            print("Ran", result.testsRun, 
    197203                    pluralize("test", "tests", result.testsRun), 
    198204                    "in", result.time, "ms", 
     
    200206                    result.errors, pluralize("error", "errors", result.errors) + ")"); 
    201207         } else { 
    202             writeln("No tests found"); 
     208            print("No tests found"); 
    203209         } 
    204210         return; 
     
    209215    
    210216   /** @ignore */ 
    211    ShellWriter.prototype.toString = function() { 
    212       return "[ShellWriter]"; 
     217   Writer.prototype.toString = function() { 
     218      return "[Writer]"; 
    213219   }; 
    214220    
     
    294300         return; 
    295301      }; 
     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      } 
    296321       
    297322      return this; 
     
    528553         } 
    529554      } 
    530       (new ShellWriter()).write(testResult); 
     555      // (new Writer()).write(testResult); 
    531556      // cleanup 
    532557      unloadTestModule(); 
     
    603628   this.TestCase.prototype.run = function(methodName) { 
    604629      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
    607632   }; 
    608633    
     
    741766   this.TestSuite.prototype.run = function() { 
    742767      var testResult = new TestResult(this); 
    743       (new ShellWriter()).write(this.execute(testResult)); 
    744       return
     768      // (new Writer()).write(this.execute(testResult)); 
     769      return testResult
    745770   }; 
    746771