| 502 | | } |
| | 502 | }; |
| | 503 | |
| | 504 | doh.registerDocTests = function(module){ |
| | 505 | // no-op for when Dojo isn't loaded into the page |
| | 506 | this.debug("registerDocTests() requires dojo to be loaded into the environment. Skipping doctest set for module:", module); |
| | 507 | }; |
| | 508 | (function(){ |
| | 509 | if(typeof dojo != "undefined"){ |
| | 510 | dojo.require("dojox.testing.DocTest"); |
| | 511 | doh.registerDocTests = function(module){ |
| | 512 | // summary: |
| | 513 | // Get all the doctests from the given module and register each of them |
| | 514 | // as a single test case here. |
| | 515 | // |
| | 516 | |
| | 517 | var docTest = new dojox.testing.DocTest(); |
| | 518 | var docTests = docTest.getTests(module); |
| | 519 | var len = docTests.length; |
| | 520 | var tests = []; |
| | 521 | for (var i=0; i<len; i++){ |
| | 522 | var test = docTests[i]; |
| | 523 | // Extract comment on first line and add to test name. |
| | 524 | var comment = ""; |
| | 525 | if (test.commands.length && test.commands[0].indexOf("//")!=-1) { |
| | 526 | var parts = test.commands[0].split("//"); |
| | 527 | comment = ", "+parts[parts.length-1]; // Get all after the last //, so we dont get trapped by http:// or alikes :-). |
| | 528 | } |
| | 529 | tests.push({ |
| | 530 | runTest:function(test){return function(t){ |
| | 531 | var r = docTest.runTest(test.commands, test.expectedResult); |
| | 532 | t.assertTrue(r.success); |
| | 533 | }}(test), |
| | 534 | name:"Line "+test.line+comment |
| | 535 | } |
| | 536 | ); |
| | 537 | } |
| | 538 | this.register("DocTests: "+module, tests); |
| | 539 | } |
| | 540 | } |
| | 541 | })(); |