From: Dan Vanderkam Date: Mon, 8 Aug 2011 11:25:00 +0000 (-0400) Subject: Simplify running tests from auto_tests/misc/local.html. Now a one-step process with... X-Git-Tag: v1.0.0~429 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;ds=inline;h=3914c8e1ef072aa9f77f4774d4501c4e0fe45bcc;p=dygraphs.git Simplify running tests from auto_tests/misc/local.html. Now a one-step process with full auto-complete. --- diff --git a/auto_tests/misc/fake-jstestdriver.js b/auto_tests/misc/fake-jstestdriver.js index 702f3d4..6ccd081 100644 --- a/auto_tests/misc/fake-jstestdriver.js +++ b/auto_tests/misc/fake-jstestdriver.js @@ -36,8 +36,9 @@ var jstd = { } }; +var testCaseList = []; + function TestCase(name) { - jstd.sucker("Not really creating TestCase(" + name + ")"); this.name = name; this.toString = function() { return "Fake test case " + name; @@ -95,5 +96,36 @@ function TestCase(name) { } console.log(prettyPrintEntity_(tests)); }; + + testCaseList.push(testCase); return testCase; }; + +// Note: this creates a bunch of global variables intentionally. +function addGlobalTestSymbols() { + globalTestDb = {}; // maps test name -> test function wrapper + + var num_tests = 0; + for (var i = 0; i < testCaseList.length; i++) { + var tc_class = testCaseList[i]; + for (var name in tc_class.prototype) { + if (name.indexOf('test') == 0 && typeof(tc_class.prototype[name]) == 'function') { + if (globalTestDb.hasOwnProperty(name)) { + console.log('Duplicated test name: ' + name); + } else { + globalTestDb[name] = function(name, tc_class) { + return function() { + var tc = new tc_class; + console.log(name); + return tc.runTest(name); + }; + }(name, tc_class); + eval(name + " = globalTestDb['" + name + "'];"); + num_tests += 1; + } + } + } + } + console.log('Loaded ' + num_tests + ' tests in ' + + testCaseList.length + ' test cases'); +} diff --git a/auto_tests/misc/local.html b/auto_tests/misc/local.html index 0d653c1..4727f08 100644 --- a/auto_tests/misc/local.html +++ b/auto_tests/misc/local.html @@ -66,12 +66,10 @@
- This file is really nothing more than all the tests coalesced into a single +

This file is really nothing more than all the tests coalesced into a single HTML file. To run a test, open a Javascript console and execute, for - instance,
- tc = new SimpleDrawingTestCase() ;
- tc.runTest("testDrawSimpleRangePlusOne")
(execution method #1, by string)
- tc.runTest(tc.testDrawSimpleRangePlusOne) (execution method #2, by function reference) + instance,

+ testDrawSimpleRangePlusOne()

Alternatively you can use query args: