Changeset 8261
- Timestamp:
- 04/24/07 04:19:59 (19 months ago)
- Location:
- util/trunk/doh
- Files:
-
- 4 modified
-
runner.html (modified) (2 diffs)
-
runner.js (modified) (48 diffs)
-
_browserRunner.js (modified) (19 diffs)
-
_rhinoRunner.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
util/trunk/doh/runner.html
r8259 r8261 6 6 <!-- 7 7 // TODO: need to provide UI controls for turning audio on and off 8 // TODO: implement global scrollbarl8 // TODO: implement global progress bar 9 9 // TODO: ensure that test groups are "folded up" by default but can be opened on a click 10 // TODO: provide way to extract this system from the rest of Dojo easily11 10 --> 12 11 <head> 13 12 <title>The Dojo Unit Test Harness, $Rev$</title> 14 <script type="text/javascript" src="../dojo.js" 15 djConfig="isDebug: true"></script> 13 <script type="text/javascript"> 14 var dojoUrl = "../../dojo/dojo.js"; 15 var testUrl = ""; 16 var testModule = ""; 17 18 // parse out our test URL and our Dojo URL from the query string 19 var qstr = window.location.search.substr(1); 20 if(qstr.length){ 21 var qparts = qstr.split("&"); 22 for(var x=0; x<qparts.length; x++){ 23 var tp = qparts[x].split("="); 24 if(tp[0] == "dojoUrl"){ 25 dojoUrl = tp[1]; 26 } 27 if(tp[0] == "testUrl"){ 28 testUrl = tp[1]; 29 } 30 if(tp[0] == "testModule"){ 31 testModule = tp[1]; 32 } 33 } 34 } 35 36 document.write("<scr"+"ipt type='text/javascript' djConfig='isDebug: true' src='"+dojoUrl+"'></scr"+"ipt>"); 37 </script> 16 38 <script type="text/javascript"> 17 39 try{ 18 dojo.require(" tests.runner");40 dojo.require("doh.runner"); 19 41 }catch(e){ 20 42 document.write("<scr"+"ipt type='text/javascript' src='runner.js'></scr"+"ipt>"); 21 // document.write("<scr"+"ipt type='text/javascript'>tests.selfTest = true;</scr"+"ipt>");22 43 document.write("<scr"+"ipt type='text/javascript' src='_browserRunner.js'></scr"+"ipt>"); 44 } 45 if(testUrl.length){ 46 document.write("<scr"+"ipt type='text/javascript' src='"+testUrl+".js'></scr"+"ipt>"); 23 47 } 24 48 </script> 25 49 <style type="text/css"> 26 @import " ../resources/dojo.css";50 @import "http://svn.dojotoolkit.org/dojo/dojo/trunk/resources/dojo.css"; 27 51 /* 28 52 body { … … 187 211 <tr valign="top" height="30"> 188 212 <td width="30%" class="header"> 189 <span id="toggleButtons" onclick=" tests.togglePaused();">213 <span id="toggleButtons" onclick="doh.togglePaused();"> 190 214 <button id="play">4</button> 191 215 <button id="pause" style="display: none;">;</button> -
util/trunk/doh/runner.js
r8258 r8261 1 // FIXME: need to add async tests1 // FIXME: need to add async doh 2 2 // FIXME: need to handle URL wrapping and test registration/running from URLs 3 3 4 4 // package system gunk. 5 5 try{ 6 dojo.provide(" tests.runner");6 dojo.provide("doh.runner"); 7 7 }catch(e){ 8 if(!this[" tests"]){9 tests= {};8 if(!this["doh"]){ 9 doh = {}; 10 10 } 11 11 } … … 15 15 // 16 16 17 tests.selfTest = false;18 19 tests.hitch = function(/*Object*/thisObject, /*Function|String*/method /*, ...*/){17 doh.selfTest = false; 18 19 doh.hitch = function(/*Object*/thisObject, /*Function|String*/method /*, ...*/){ 20 20 var args = []; 21 21 for(var x=2; x<arguments.length; x++){ … … 32 32 } 33 33 34 tests._mixin = function(/*Object*/ obj, /*Object*/ props){34 doh._mixin = function(/*Object*/ obj, /*Object*/ props){ 35 35 // summary: 36 36 // Adds all properties and methods of props to obj. This addition is … … 59 59 } 60 60 61 tests.mixin = function(/*Object*/obj, /*Object...*/props){61 doh.mixin = function(/*Object*/obj, /*Object...*/props){ 62 62 // summary: Adds all properties and methods of props to obj. 63 63 for(var i=1, l=arguments.length; i<l; i++){ 64 tests._mixin(obj, arguments[i]);64 doh._mixin(obj, arguments[i]); 65 65 } 66 66 return obj; // Object 67 67 } 68 68 69 tests.extend = function(/*Object*/ constructor, /*Object...*/ props){69 doh.extend = function(/*Object*/ constructor, /*Object...*/ props){ 70 70 // summary: 71 71 // Adds all properties and methods of props to constructor's … … 73 73 // constructor. 74 74 for(var i=1, l=arguments.length; i<l; i++){ 75 tests._mixin(constructor.prototype, arguments[i]);75 doh._mixin(constructor.prototype, arguments[i]); 76 76 } 77 77 return constructor; // Object … … 79 79 80 80 81 tests._line = "------------------------------------------------------------";81 doh._line = "------------------------------------------------------------"; 82 82 83 83 /* 84 tests._delegate = function(obj, props){84 doh._delegate = function(obj, props){ 85 85 // boodman-crockford delegation 86 86 function TMP(){}; … … 94 94 */ 95 95 96 tests.debug = function(){96 doh.debug = function(){ 97 97 // summary: 98 98 // takes any number of arguments and sends them to whatever debugging … … 102 102 } 103 103 104 tests._AssertFailure = function(msg){104 doh._AssertFailure = function(msg){ 105 105 // idea for this as way of dis-ambiguating error types is from JUM. 106 106 // The JUM is dead! Long live the JUM! 107 107 108 if(!(this instanceof tests._AssertFailure)){109 return new tests._AssertFailure(msg);108 if(!(this instanceof doh._AssertFailure)){ 109 return new doh._AssertFailure(msg); 110 110 } 111 111 this.message = new String(msg||""); 112 112 return this; 113 113 } 114 tests._AssertFailure.prototype = new Error();115 tests._AssertFailure.prototype.constructor = tests._AssertFailure;116 tests._AssertFailure.prototype.name = "tests._AssertFailure";117 118 tests.Deferred = function(canceller){114 doh._AssertFailure.prototype = new Error(); 115 doh._AssertFailure.prototype.constructor = doh._AssertFailure; 116 doh._AssertFailure.prototype.name = "doh._AssertFailure"; 117 118 doh.Deferred = function(canceller){ 119 119 this.chain = []; 120 120 this.id = this._nextId(); … … 126 126 }; 127 127 128 tests.extend(tests.Deferred, {128 doh.extend(doh.Deferred, { 129 129 getTestCallback: function(cb, scope){ 130 130 var _this = this; … … 149 149 } 150 150 }else if((a[0])&&(a[1])){ 151 return tests.hitch(a[0], a[1]);151 return doh.hitch(a[0], a[1]); 152 152 } 153 153 return null; … … 155 155 156 156 makeCalled: function() { 157 var deferred = new tests.Deferred();157 var deferred = new doh.Deferred(); 158 158 deferred.callback(); 159 159 return deferred; … … 176 176 } 177 177 }else if( (this.fired == 0)&& 178 (this.results[0] instanceof tests.Deferred)){178 (this.results[0] instanceof doh.Deferred)){ 179 179 this.results[0].cancel(); 180 180 } … … 230 230 var enclosed = this.getFunctionFromArgs(cb, cbfn); 231 231 if(arguments.length > 2){ 232 enclosed = tests.hitch(null, enclosed, arguments, 2);232 enclosed = doh.hitch(null, enclosed, arguments, 2); 233 233 } 234 234 return this.addCallbacks(enclosed, enclosed); … … 238 238 var enclosed = this.getFunctionFromArgs(cb, cbfn); 239 239 if(arguments.length > 2){ 240 enclosed = tests.hitch(null, enclosed, arguments, 2);240 enclosed = doh.hitch(null, enclosed, arguments, 2); 241 241 } 242 242 return this.addCallbacks(enclosed, null); … … 246 246 var enclosed = this.getFunctionFromArgs(cb, cbfn); 247 247 if(arguments.length > 2){ 248 enclosed = tests.hitch(null, enclosed, arguments, 2);248 enclosed = doh.hitch(null, enclosed, arguments, 2); 249 249 } 250 250 return this.addCallbacks(null, enclosed); … … 275 275 res = f(res); 276 276 fired = ((res instanceof Error) ? 1 : 0); 277 if(res instanceof tests.Deferred){277 if(res instanceof doh.Deferred){ 278 278 cb = function(res){ 279 279 self._continue(res); … … 298 298 // 299 299 300 tests._testCount = 0;301 tests._groupCount = 0;302 tests._errorCount = 0;303 tests._failureCount = 0;304 tests._currentGroup = null;305 tests._currentTest = null;306 tests._paused = true;307 308 tests._init = function(){300 doh._testCount = 0; 301 doh._groupCount = 0; 302 doh._errorCount = 0; 303 doh._failureCount = 0; 304 doh._currentGroup = null; 305 doh._currentTest = null; 306 doh._paused = true; 307 308 doh._init = function(){ 309 309 this._currentGroup = null; 310 310 this._currentTest = null; 311 311 this._errorCount = 0; 312 312 this._failureCount = 0; 313 this.debug(this._testCount, " teststo run in", this._groupCount, "groups");314 } 315 316 // tests._urls = [];317 tests._groups = {};313 this.debug(this._testCount, "doh to run in", this._groupCount, "groups"); 314 } 315 316 // doh._urls = []; 317 doh._groups = {}; 318 318 319 319 // … … 321 321 // 322 322 323 tests.registerTestNs = function(/*String*/ group, /*Object*/ ns){323 doh.registerTestNs = function(/*String*/ group, /*Object*/ ns){ 324 324 // summary: 325 325 // adds the passed namespace object to the list of objects to be 326 326 // searched for test groups. Only "public" functions (not prefixed 327 // with "_") will be added as teststo be run. If you'd like to use327 // with "_") will be added as doh to be run. If you'd like to use 328 328 // fixtures (setUp(), tearDown(), and runTest()), please use 329 // registerTest() or register Tests().329 // registerTest() or registerdoh(). 330 330 for(var x in ns){ 331 331 if( (x.charAt(0) == "_") && … … 336 336 } 337 337 338 tests._testRegistered = function(group, fixture){338 doh._testRegistered = function(group, fixture){ 339 339 // slot to be filled in 340 340 } 341 341 342 tests._groupStarted = function(group){342 doh._groupStarted = function(group){ 343 343 // slot to be filled in 344 344 } 345 345 346 tests._groupFinished = function(group, success){346 doh._groupFinished = function(group, success){ 347 347 // slot to be filled in 348 348 } 349 349 350 tests._testStarted = function(group, fixture){350 doh._dohtarted = function(group, fixture){ 351 351 // slot to be filled in 352 352 } 353 353 354 tests._testFinished = function(group, fixture, success){354 doh._testFinished = function(group, fixture, success){ 355 355 // slot to be filled in 356 356 } 357 357 358 tests.registerGroup = function( /*String*/ group,359 /*Array||Function||Object*/ tests,358 doh.registerGroup = function( /*String*/ group, 359 /*Array||Function||Object*/ doh, 360 360 /*Function*/ setUp, 361 361 /*Function*/ tearDown){ 362 362 // summary: 363 // registers an entire group of testsat once and provides a setUp and363 // registers an entire group of doh at once and provides a setUp and 364 364 // tearDown facility for groups. If you call this method with only 365 365 // setUp and tearDown parameters, they will replace previously … … 368 368 // group: 369 369 // string name of the group 370 // tests:370 // doh: 371 371 // either a function or an object or an array of functions/objects. If 372 372 // an object, it must contain at *least* a "runTest" method, and may … … 377 377 // setUp: a function for initializing the test group 378 378 // tearDown: a function for initializing the test group 379 if( tests){380 this.register(group, tests);379 if(doh){ 380 this.register(group, doh); 381 381 } 382 382 if(setUp){ … … 388 388 } 389 389 390 tests._getTestObj = function(group, test){390 doh._getTestObj = function(group, test){ 391 391 var tObj = test; 392 392 if(typeof test == "string"){ … … 411 411 tObj.name = ts.split(fStr)[1].split("(", 1)[0]; 412 412 } 413 // tests.debug(tObj.runTest.toSource());413 // doh.debug(tObj.runTest.toSource()); 414 414 }catch(e){ 415 415 } … … 420 420 } 421 421 422 tests.registerTest = function(/*String*/ group, /*Function||Object*/ test){422 doh.registerTest = function(/*String*/ group, /*Function||Object*/ test){ 423 423 // summary: 424 424 // add the provided test function or fixture object to the specified … … 444 444 } 445 445 446 tests.registerTests= function(/*String*/ group, /*Array*/ testArr){447 // summary: 448 // registers a group of tests, treating each element of testArr as446 doh.registerdoh = function(/*String*/ group, /*Array*/ testArr){ 447 // summary: 448 // registers a group of doh, treating each element of testArr as 449 449 // though it were being (along with group) passed to the registerTest 450 450 // method. … … 455 455 456 456 // FIXME: move implementation to _browserRunner? 457 tests.registerUrl = function( /*String*/ group,457 doh.registerUrl = function( /*String*/ group, 458 458 /*String*/ url, 459 459 /*Integer*/ timeout){ … … 463 463 } 464 464 465 tests.registerString = function(group, str){466 } 467 468 // FIXME: remove the tests.add alias SRTL.469 tests.register = tests.add = function(groupOrNs, testOrNull){470 // summary: 471 // "magical" variant of register Tests, registerTest, and465 doh.registerString = function(group, str){ 466 } 467 468 // FIXME: remove the doh.add alias SRTL. 469 doh.register = doh.add = function(groupOrNs, testOrNull){ 470 // summary: 471 // "magical" variant of registerdoh, registerTest, and 472 472 // registerTestNs. Will accept the calling arguments of any of these 473 473 // methods and will correctly guess the right one to register with. … … 481 481 } 482 482 if(arguments.length == 1){ 483 this.debug("invalid args passed to tests.register():", groupOrNs, ",", testOrNull);483 this.debug("invalid args passed to doh.register():", groupOrNs, ",", testOrNull); 484 484 return; 485 485 } … … 493 493 return; 494 494 } 495 if( tests._isArray(testOrNull) ){496 this.register Tests(groupOrNs, testOrNull);495 if( doh._isArray(testOrNull) ){ 496 this.registerdoh(groupOrNs, testOrNull); 497 497 return; 498 498 } … … 504 504 // 505 505 506 tests.t = tests.assertTrue = function(/*Object*/ condition){506 doh.t = doh.assertTrue = function(/*Object*/ condition){ 507 507 // summary: 508 508 // is the passed item "truthy"? 509 509 if(!eval(condition)){ 510 throw tests._AssertFailure("assertTrue('" + condition + "') failed");511 } 512 } 513 514 tests.f = tests.assertFalse = function(/*Object*/ condition){510 throw doh._AssertFailure("assertTrue('" + condition + "') failed"); 511 } 512 } 513 514 doh.f = doh.assertFalse = function(/*Object*/ condition){ 515 515 // summary: 516 516 // is the passed item "falsey"? 517 517 if(eval(condition)){ 518 throw tests._AssertFailure("assertFalse('" + condition + "') failed");519 } 520 } 521 522 tests.is = tests.assertEqual = function(/*Object*/ expected, /*Object*/ actual){518 throw doh._AssertFailure("assertFalse('" + condition + "') failed"); 519 } 520 } 521 522 doh.is = doh.assertEqual = function(/*Object*/ expected, /*Object*/ actual){ 523 523 // summary: 524 524 // are the passed expected and actual objects/values deeply … … 541 541 return true; 542 542 } 543 throw new tests._AssertFailure("assertEqual() failed: expected |"+expected+"| but got |"+actual+"|");544 } 545 546 tests._arrayEq = function(expected, actual){543 throw new doh._AssertFailure("assertEqual() failed: expected |"+expected+"| but got |"+actual+"|"); 544 } 545 546 doh._arrayEq = function(expected, actual){ 547 547 if(expected.length != actual.length){ return false; } 548 548 // FIXME: we're not handling circular refs. Do we care? 549 549 for(var x=0; x<expected.length; x++){ 550 if(! tests.assertEqual(expected[x], actual[x])){ return false; }550 if(!doh.assertEqual(expected[x], actual[x])){ return false; } 551 551 } 552 552 return true; 553 553 } 554 554 555 tests._objPropEq = function(expected, actual){555 doh._objPropEq = function(expected, actual){ 556 556 for(var x in expected){ 557 if(! tests.assertEqual(expected[x], actual[x])){557 if(!doh.assertEqual(expected[x], actual[x])){ 558 558 return false; 559 559 } … … 562 562 } 563 563 564 tests._isArray = function(arr){564 doh._isArray = function(arr){ 565 565 return ((arr instanceof Array)||(typeof arr == "array") ); 566 566 } … … 570 570 // 571 571 572 tests._setupGroupForRun = function(/*String*/ groupName, /*Integer*/ idx){572 doh._setupGroupForRun = function(/*String*/ groupName, /*Integer*/ idx){ 573 573 var tg = this._groups[groupName]; 574 574 this.debug(this._line); … … 576 576 } 577 577 578 tests._handleFailure = function(groupName, fixture, e){578 doh._handleFailure = function(groupName, fixture, e){ 579 579 // this.debug("FAILED test:", fixture.name); 580 580 // mostly borrowed from JUM … … 607 607 } 608 608 609 tests._runFixture = function(groupName, fixture){609 doh._runFixture = function(groupName, fixture){ 610 610 var tg = this._groups[groupName]; 611 this._ testStarted(groupName, fixture);611 this._dohtarted(groupName, fixture); 612 612 var threw = false; 613 613 var err = null; 614 614 // run it, catching exceptions and reporting them 615 615 try{ 616 // let testsreference "this.group.thinger..." which can be set by616 // let doh reference "this.group.thinger..." which can be set by 617 617 // another test or group-level setUp function 618 618 fixture.group = tg; … … 624 624 // gonna wait for an async result. It's up to the test code to trap 625 625 // errors and give us an errback or callback. 626 if(ret instanceof tests.Deferred){626 if(ret instanceof doh.Deferred){ 627 627 628 628 tg.inFlight++; … … 631 631 632 632 ret.addErrback(function(err){ 633 tests._handleFailure(groupName, fixture, err);633 doh._handleFailure(groupName, fixture, err); 634 634 }); 635 635 636 636 var retEnd = function(){ 637 if(fixture["tearDown"]){ fixture.tearDown( tests); }637 if(fixture["tearDown"]){ fixture.tearDown(doh); } 638 638 tg.inFlight--; 639 639 if((!tg.inFlight)&&(tg.iterated)){ 640 tests._groupFinished(groupName, (!tg.failures));640 doh._groupFinished(groupName, (!tg.failures)); 641 641 } 642 tests._testFinished(groupName, fixture, ret.results[0]);643 if( tests._paused){644 tests.run();642 doh._testFinished(groupName, fixture, ret.results[0]); 643 if(doh._paused){ 644 doh.run(); 645 645 } 646 646 } … … 656 656 }); 657 657 if(ret.fired < 0){ 658 tests.pause();658