runtest/testrunner.js doesnt clearly report test results with uncaught exceptions

runtest/testrunner.js doesnt clearly report test results with uncaught exceptions

<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Hi Dev Team,<DIV>I'm using the same test harness to add unit tests to my project and I noticed that if a particular test fails to do an uncaught exception I might not get a very clear signal in my unit test results.  For example the current test function is:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>function test(name, fn){</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>expected = -1;</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>numTests = 0;</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>reset();</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>fn();</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>if ( expected != -1 && expected != numTests )</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>log( false, "Wrong number of tests run. " + numTests + " ran, expected " + expected );</DIV><DIV>}</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>test("Application Context", function() {</DIV><DIV>    expect(3);</DIV><DIV>    ok( true, "assertion 1" );</DIV><DIV>    ok( true, "assertion 2" );</DIV><DIV>    ok( true, "assertion 3" );</DIV><DIV>    ok( true, "assertion 4" );</DIV><DIV>    ok( true, "assertion 5" );</DIV><DIV>    ok( true, "assertion 6" );</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>    throw new Error("gotcha");</DIV><DIV>   </DIV><DIV>    ok( true, "assertion 7" );</DIV><DIV>    ok( true, "assertion 8" );</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>});</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>So if 3/4 of the assertions in the test are run and pass and then a particular assertion throws an error, I'll see something like </DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>[java] 6 Passed, 0 Failed</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>and I wont necessarily know that some tests were never executed, and the expected number of tests is never checked.  So using:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>function test(name, fn){</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>expected = -1;</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>numTests = 0;</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>reset();</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>try{</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>    fn();</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>}catch(e){</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>    log(false, "!! Caught unexpected exception in test: " + e);</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>}</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>if ( expected != -1 && expected != numTests )</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>log( false, "Wrong number of tests run. " + numTests + " ran, expected " + expected );</DIV><DIV>}</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>     [java] FAIL (106) [test.test] !! Caught unexpected exception in test: Error: gotcha</DIV><DIV>     [java] FAIL (107) [test.test] Wrong number of tests run. 7 ran, expected 8</DIV><DIV>     [java] 6 Passed, 2 Failed</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Which isn't perfect but since I have hundreds of unit tests I at least can count on someone who doesnt know how many to expect to get an failure message and be able to tell the build is broken.</DIV><DIV><BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>Chris Thatcher</DIV><DIV>(cell) 202 340 9685</DIV><DIV><A href="mailto:christopher.thatcher@comcast.net"> christopher.thatcher@comcast.net</A></DIV><DIV><A href="mailto:chth@loc.gov"> chth@loc.gov</A></DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR class="Apple-interchange-newline"></SPAN></SPAN></SPAN> </DIV><BR></DIV>