1 jls.loader.provide('jls.jsunit.TestSuite');
  2 
  3 jls.loader.require('jls.lang.AssertionError');
  4 jls.loader.require('jls.jsunit.TestCase');
  5 jls.loader.require('jls.jsunit.TestResult');
  6 
  7 jls.jsunit.TestSuite = jls.lang.Class.create(
  8 {
  9     initialize : function() {
 10         this._testCases = [];
 11     },
 12     addTest : function(test) {
 13         this._testCases.push(test);
 14         return this;
 15     },
 16     testCount : function() {
 17         return this._testCases.length;
 18     },
 19     addTestSuite : function(tcClass) {
 20         if (typeof tcClass == 'string') {
 21             var classname = tcClass;
 22             try {
 23                 tcClass = jls.loader.require(classname);
 24             }
 25             catch (e) {
 26                 // TODO Remove
 27                 jls.lang.System.err.println('Cannot load "' + classname + '" due to:');
 28                 jls.lang.Exception.wrap(e).printStackTrace(jls.lang.System.err);
 29                 jls.lang.Runtime.exit(1);
 30             }
 31         }
 32         if (typeof tcClass != 'function') {
 33             throw new jls.lang.Exception('Invalid test case class');
 34         }
 35         for (var name in tcClass.prototype) {
 36             //jls.lang.System.out.println('-> ' + name);
 37             if (! (name.startsWith('test') && (typeof tcClass.prototype[name] == 'function'))) {
 38                 continue;
 39             }
 40             this.addTest(new tcClass(name));
 41         }
 42         return this;
 43     },
 44     run : function(tr) {
 45         for (var i = 0; i < this._testCases.length; i++) {
 46             //jls.logger.info('running: ' + jls.loader.getClassname(this._testCases[i]) + '(' + this._testCases[i].getName() + ')');
 47             tr.run(this._testCases[i]);
 48         }
 49     }
 50 });
 51 
 52