Changeset 8261

Show
Ignore:
Timestamp:
04/24/07 04:19:59 (19 months ago)
Author:
alex
Message:

tests.* -> doh.*. A big (but separate) checkin is coming for Core tests to make them conform. Refs #2795

Location:
util/trunk/doh
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • util/trunk/doh/runner.html

    r8259 r8261  
    66        <!-- 
    77                // TODO: need to provide UI controls for turning audio on and off 
    8                 // TODO: implement global scrollbarl 
     8                // TODO: implement global progress bar 
    99                // 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 easily 
    1110        --> 
    1211        <head> 
    1312                <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> 
    1638                <script type="text/javascript"> 
    1739                        try{ 
    18                                 dojo.require("tests.runner"); 
     40                                dojo.require("doh.runner"); 
    1941                        }catch(e){ 
    2042                                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>"); 
    2243                                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>"); 
    2347                        } 
    2448                </script> 
    2549                <style type="text/css"> 
    26                         @import "../resources/dojo.css"; 
     50                        @import "http://svn.dojotoolkit.org/dojo/dojo/trunk/resources/dojo.css"; 
    2751                        /* 
    2852                        body { 
     
    187211                        <tr valign="top" height="30"> 
    188212                                <td width="30%" class="header"> 
    189                                         <span id="toggleButtons" onclick="tests.togglePaused();"> 
     213                                        <span id="toggleButtons" onclick="doh.togglePaused();"> 
    190214                                                <button id="play">&#052;</button> 
    191215                                                <button id="pause" style="display: none;">&#059;</button> 
  • util/trunk/doh/runner.js

    r8258 r8261  
    1 // FIXME: need to add async tests 
     1// FIXME: need to add async doh 
    22// FIXME: need to handle URL wrapping and test registration/running from URLs 
    33 
    44// package system gunk.  
    55try{ 
    6         dojo.provide("tests.runner"); 
     6        dojo.provide("doh.runner"); 
    77}catch(e){ 
    8         if(!this["tests"]){ 
    9                 tests = {}; 
     8        if(!this["doh"]){ 
     9                doh = {}; 
    1010        } 
    1111} 
     
    1515// 
    1616 
    17 tests.selfTest = false; 
    18  
    19 tests.hitch = function(/*Object*/thisObject, /*Function|String*/method /*, ...*/){ 
     17doh.selfTest = false; 
     18 
     19doh.hitch = function(/*Object*/thisObject, /*Function|String*/method /*, ...*/){ 
    2020        var args = []; 
    2121        for(var x=2; x<arguments.length; x++){ 
     
    3232} 
    3333 
    34 tests._mixin = function(/*Object*/ obj, /*Object*/ props){ 
     34doh._mixin = function(/*Object*/ obj, /*Object*/ props){ 
    3535        // summary: 
    3636        //              Adds all properties and methods of props to obj. This addition is 
     
    5959} 
    6060 
    61 tests.mixin = function(/*Object*/obj, /*Object...*/props){ 
     61doh.mixin = function(/*Object*/obj, /*Object...*/props){ 
    6262        // summary:     Adds all properties and methods of props to obj.  
    6363        for(var i=1, l=arguments.length; i<l; i++){ 
    64                 tests._mixin(obj, arguments[i]); 
     64                doh._mixin(obj, arguments[i]); 
    6565        } 
    6666        return obj; // Object 
    6767} 
    6868 
    69 tests.extend = function(/*Object*/ constructor, /*Object...*/ props){ 
     69doh.extend = function(/*Object*/ constructor, /*Object...*/ props){ 
    7070        // summary: 
    7171        //              Adds all properties and methods of props to constructor's 
     
    7373        //              constructor. 
    7474        for(var i=1, l=arguments.length; i<l; i++){ 
    75                 tests._mixin(constructor.prototype, arguments[i]); 
     75                doh._mixin(constructor.prototype, arguments[i]); 
    7676        } 
    7777        return constructor; // Object 
     
    7979 
    8080 
    81 tests._line = "------------------------------------------------------------"; 
     81doh._line = "------------------------------------------------------------"; 
    8282 
    8383/* 
    84 tests._delegate = function(obj, props){ 
     84doh._delegate = function(obj, props){ 
    8585        // boodman-crockford delegation 
    8686        function TMP(){}; 
     
    9494*/ 
    9595 
    96 tests.debug = function(){ 
     96doh.debug = function(){ 
    9797        // summary: 
    9898        //              takes any number of arguments and sends them to whatever debugging 
     
    102102} 
    103103 
    104 tests._AssertFailure = function(msg){ 
     104doh._AssertFailure = function(msg){ 
    105105        // idea for this as way of dis-ambiguating error types is from JUM.  
    106106        // The JUM is dead! Long live the JUM! 
    107107 
    108         if(!(this instanceof tests._AssertFailure)){ 
    109                 return new tests._AssertFailure(msg); 
     108        if(!(this instanceof doh._AssertFailure)){ 
     109                return new doh._AssertFailure(msg); 
    110110        } 
    111111        this.message = new String(msg||""); 
    112112        return this; 
    113113} 
    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){ 
     114doh._AssertFailure.prototype = new Error(); 
     115doh._AssertFailure.prototype.constructor = doh._AssertFailure; 
     116doh._AssertFailure.prototype.name = "doh._AssertFailure"; 
     117 
     118doh.Deferred = function(canceller){ 
    119119        this.chain = []; 
    120120        this.id = this._nextId(); 
     
    126126}; 
    127127 
    128 tests.extend(tests.Deferred, { 
     128doh.extend(doh.Deferred, { 
    129129        getTestCallback: function(cb, scope){ 
    130130                var _this = this; 
     
    149149                        } 
    150150                }else if((a[0])&&(a[1])){ 
    151                         return tests.hitch(a[0], a[1]); 
     151                        return doh.hitch(a[0], a[1]); 
    152152                } 
    153153                return null; 
     
    155155 
    156156        makeCalled: function() { 
    157                 var deferred = new tests.Deferred(); 
     157                var deferred = new doh.Deferred(); 
    158158                deferred.callback(); 
    159159                return deferred; 
     
    176176                        } 
    177177                }else if(       (this.fired == 0)&& 
    178                                         (this.results[0] instanceof tests.Deferred)){ 
     178                                        (this.results[0] instanceof doh.Deferred)){ 
    179179                        this.results[0].cancel(); 
    180180                } 
     
    230230                var enclosed = this.getFunctionFromArgs(cb, cbfn); 
    231231                if(arguments.length > 2){ 
    232                         enclosed = tests.hitch(null, enclosed, arguments, 2); 
     232                        enclosed = doh.hitch(null, enclosed, arguments, 2); 
    233233                } 
    234234                return this.addCallbacks(enclosed, enclosed); 
     
    238238                var enclosed = this.getFunctionFromArgs(cb, cbfn); 
    239239                if(arguments.length > 2){ 
    240                         enclosed = tests.hitch(null, enclosed, arguments, 2); 
     240                        enclosed = doh.hitch(null, enclosed, arguments, 2); 
    241241                } 
    242242                return this.addCallbacks(enclosed, null); 
     
    246246                var enclosed = this.getFunctionFromArgs(cb, cbfn); 
    247247                if(arguments.length > 2){ 
    248                         enclosed = tests.hitch(null, enclosed, arguments, 2); 
     248                        enclosed = doh.hitch(null, enclosed, arguments, 2); 
    249249                } 
    250250                return this.addCallbacks(null, enclosed); 
     
    275275                                res = f(res); 
    276276                                fired = ((res instanceof Error) ? 1 : 0); 
    277                                 if(res instanceof tests.Deferred){ 
     277                                if(res instanceof doh.Deferred){ 
    278278                                        cb = function(res){ 
    279279                                                self._continue(res); 
     
    298298// 
    299299 
    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(){ 
     300doh._testCount = 0; 
     301doh._groupCount = 0; 
     302doh._errorCount = 0; 
     303doh._failureCount = 0; 
     304doh._currentGroup = null; 
     305doh._currentTest = null; 
     306doh._paused = true; 
     307 
     308doh._init = function(){ 
    309309        this._currentGroup = null; 
    310310        this._currentTest = null; 
    311311        this._errorCount = 0; 
    312312        this._failureCount = 0; 
    313         this.debug(this._testCount, "tests to 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 = []; 
     317doh._groups = {}; 
    318318 
    319319// 
     
    321321// 
    322322 
    323 tests.registerTestNs = function(/*String*/ group, /*Object*/ ns){ 
     323doh.registerTestNs = function(/*String*/ group, /*Object*/ ns){ 
    324324        // summary: 
    325325        //              adds the passed namespace object to the list of objects to be 
    326326        //              searched for test groups. Only "public" functions (not prefixed 
    327         //              with "_") will be added as tests to be run. If you'd like to use 
     327        //              with "_") will be added as doh to be run. If you'd like to use 
    328328        //              fixtures (setUp(), tearDown(), and runTest()), please use 
    329         //              registerTest() or registerTests(). 
     329        //              registerTest() or registerdoh(). 
    330330        for(var x in ns){ 
    331331                if(     (x.charAt(0) == "_") && 
     
    336336} 
    337337 
    338 tests._testRegistered = function(group, fixture){ 
     338doh._testRegistered = function(group, fixture){ 
    339339        // slot to be filled in 
    340340} 
    341341 
    342 tests._groupStarted = function(group){ 
     342doh._groupStarted = function(group){ 
    343343        // slot to be filled in 
    344344} 
    345345 
    346 tests._groupFinished = function(group, success){ 
     346doh._groupFinished = function(group, success){ 
    347347        // slot to be filled in 
    348348} 
    349349 
    350 tests._testStarted = function(group, fixture){ 
     350doh._dohtarted = function(group, fixture){ 
    351351        // slot to be filled in 
    352352} 
    353353 
    354 tests._testFinished = function(group, fixture, success){ 
     354doh._testFinished = function(group, fixture, success){ 
    355355        // slot to be filled in 
    356356} 
    357357 
    358 tests.registerGroup = function( /*String*/ group,  
    359                                                                 /*Array||Function||Object*/ tests,  
     358doh.registerGroup = function(   /*String*/ group,  
     359                                                                /*Array||Function||Object*/ doh,  
    360360                                                                /*Function*/ setUp,  
    361361                                                                /*Function*/ tearDown){ 
    362362        // summary: 
    363         //              registers an entire group of tests at once and provides a setUp and 
     363        //              registers an entire group of doh at once and provides a setUp and 
    364364        //              tearDown facility for groups. If you call this method with only 
    365365        //              setUp and tearDown parameters, they will replace previously 
     
    368368        // group: 
    369369        //              string name of the group 
    370         // tests: 
     370        // doh: 
    371371        //              either a function or an object or an array of functions/objects. If 
    372372        //              an object, it must contain at *least* a "runTest" method, and may 
     
    377377        // setUp: a function for initializing the test group 
    378378        // tearDown: a function for initializing the test group 
    379         if(tests){ 
    380                 this.register(group, tests); 
     379        if(doh){ 
     380                this.register(group, doh); 
    381381        } 
    382382        if(setUp){ 
     
    388388} 
    389389 
    390 tests._getTestObj = function(group, test){ 
     390doh._getTestObj = function(group, test){ 
    391391        var tObj = test; 
    392392        if(typeof test == "string"){ 
     
    411411                                        tObj.name = ts.split(fStr)[1].split("(", 1)[0]; 
    412412                                } 
    413                                 // tests.debug(tObj.runTest.toSource()); 
     413                                // doh.debug(tObj.runTest.toSource()); 
    414414                        }catch(e){ 
    415415                        } 
     
    420420} 
    421421 
    422 tests.registerTest = function(/*String*/ group, /*Function||Object*/ test){ 
     422doh.registerTest = function(/*String*/ group, /*Function||Object*/ test){ 
    423423        // summary: 
    424424        //              add the provided test function or fixture object to the specified 
     
    444444} 
    445445 
    446 tests.registerTests = function(/*String*/ group, /*Array*/ testArr){ 
    447         // summary: 
    448         //              registers a group of tests, treating each element of testArr as 
     446doh.registerdoh = function(/*String*/ group, /*Array*/ testArr){ 
     447        // summary: 
     448        //              registers a group of doh, treating each element of testArr as 
    449449        //              though it were being (along with group) passed to the registerTest 
    450450        //              method. 
     
    455455 
    456456// FIXME: move implementation to _browserRunner? 
    457 tests.registerUrl = function(   /*String*/ group,  
     457doh.registerUrl = function(     /*String*/ group,  
    458458                                                                /*String*/ url,  
    459459                                                                /*Integer*/ timeout){ 
     
    463463} 
    464464 
    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 registerTests, registerTest, and 
     465doh.registerString = function(group, str){ 
     466} 
     467 
     468// FIXME: remove the doh.add alias SRTL. 
     469doh.register = doh.add = function(groupOrNs, testOrNull){ 
     470        // summary: 
     471        //              "magical" variant of registerdoh, registerTest, and 
    472472        //              registerTestNs. Will accept the calling arguments of any of these 
    473473        //              methods and will correctly guess the right one to register with. 
     
    481481        } 
    482482        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); 
    484484                return; 
    485485        } 
     
    493493                return; 
    494494        } 
    495         if(     tests._isArray(testOrNull) ){ 
    496                 this.registerTests(groupOrNs, testOrNull); 
     495        if(     doh._isArray(testOrNull) ){ 
     496                this.registerdoh(groupOrNs, testOrNull); 
    497497                return; 
    498498        } 
     
    504504// 
    505505 
    506 tests.t = tests.assertTrue = function(/*Object*/ condition){ 
     506doh.t = doh.assertTrue = function(/*Object*/ condition){ 
    507507        // summary: 
    508508        //              is the passed item "truthy"? 
    509509        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 
     514doh.f = doh.assertFalse = function(/*Object*/ condition){ 
    515515        // summary: 
    516516        //              is the passed item "falsey"? 
    517517        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 
     522doh.is = doh.assertEqual = function(/*Object*/ expected, /*Object*/ actual){ 
    523523        // summary: 
    524524        //              are the passed expected and actual objects/values deeply 
     
    541541                return true; 
    542542        } 
    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 
     546doh._arrayEq = function(expected, actual){ 
    547547        if(expected.length != actual.length){ return false; } 
    548548        // FIXME: we're not handling circular refs. Do we care? 
    549549        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; } 
    551551        } 
    552552        return true; 
    553553} 
    554554 
    555 tests._objPropEq = function(expected, actual){ 
     555doh._objPropEq = function(expected, actual){ 
    556556        for(var x in expected){ 
    557                 if(!tests.assertEqual(expected[x], actual[x])){ 
     557                if(!doh.assertEqual(expected[x], actual[x])){ 
    558558                        return false; 
    559559                } 
     
    562562} 
    563563 
    564 tests._isArray = function(arr){ 
     564doh._isArray = function(arr){ 
    565565        return ((arr instanceof Array)||(typeof arr == "array") ); 
    566566} 
     
    570570// 
    571571 
    572 tests._setupGroupForRun = function(/*String*/ groupName, /*Integer*/ idx){ 
     572doh._setupGroupForRun = function(/*String*/ groupName, /*Integer*/ idx){ 
    573573        var tg = this._groups[groupName]; 
    574574        this.debug(this._line); 
     
    576576} 
    577577 
    578 tests._handleFailure = function(groupName, fixture, e){ 
     578doh._handleFailure = function(groupName, fixture, e){ 
    579579        // this.debug("FAILED test:", fixture.name); 
    580580        // mostly borrowed from JUM 
     
    607607} 
    608608 
    609 tests._runFixture = function(groupName, fixture){ 
     609doh._runFixture = function(groupName, fixture){ 
    610610        var tg = this._groups[groupName]; 
    611         this._testStarted(groupName, fixture); 
     611        this._dohtarted(groupName, fixture); 
    612612        var threw = false; 
    613613        var err = null; 
    614614        // run it, catching exceptions and reporting them 
    615615        try{ 
    616                 // let tests reference "this.group.thinger..." which can be set by 
     616                // let doh reference "this.group.thinger..." which can be set by 
    617617                // another test or group-level setUp function 
    618618                fixture.group = tg;  
     
    624624                        // gonna wait for an async result. It's up to the test code to trap 
    625625                        // errors and give us an errback or callback. 
    626                         if(ret instanceof tests.Deferred){ 
     626                        if(ret instanceof doh.Deferred){ 
    627627 
    628628                                tg.inFlight++; 
     
    631631 
    632632                                ret.addErrback(function(err){ 
    633                                         tests._handleFailure(groupName, fixture, err); 
     633                                        doh._handleFailure(groupName, fixture, err); 
    634634                                }); 
    635635 
    636636                                var retEnd = function(){ 
    637                                         if(fixture["tearDown"]){ fixture.tearDown(tests); } 
     637                                        if(fixture["tearDown"]){ fixture.tearDown(doh); } 
    638638                                        tg.inFlight--; 
    639639                                        if((!tg.inFlight)&&(tg.iterated)){ 
    640                                                 tests._groupFinished(groupName, (!tg.failures)); 
     640                                                doh._groupFinished(groupName, (!tg.failures)); 
    641641                                        } 
    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(); 
    645645                                        } 
    646646                                } 
     
    656656                                }); 
    657657                                if(ret.fired < 0){ 
    658                                         tests.pause(); 
     658