Skip to content

Commit d99ae0e

Browse files
committed
Refactor the way test.html runs tests to be similar to how Cakefile runs them; most importantly, tests fail when the test function throws an exception, not when ok does (which happens intentionally a few times in the classes tests); this also produces a more accurate count of tests run
1 parent cf3a272 commit d99ae0e

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

documentation/test.html

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ <h1>CoffeeScript Test Suite</h1>
3737
<pre id="stdout"></pre>
3838

3939
<script type="text/coffeescript">
40-
@global = window
4140
@testingBrowser = yes
42-
41+
@global = window
4342
stdout = document.getElementById 'stdout'
44-
desc = ''
45-
fnStr = ''
4643
start = new Date
4744
success = total = done = failed = 0
4845

@@ -54,13 +51,18 @@ <h1>CoffeeScript Test Suite</h1>
5451
msg
5552

5653
@test = (description, fn) ->
57-
desc = description
58-
fnStr = fn.toString() if fn.toString?
59-
fn()
54+
++total
55+
try
56+
fn.call(fn)
57+
++success
58+
catch exception
59+
say "#{description}:", 'bad'
60+
say fn.toString(), 'subtle' if fn.toString?
61+
say exception, 'bad'
62+
console.error exception
6063

6164
@ok = (good, msg = 'Error') ->
62-
++total
63-
if good then ++success else throw Error msg
65+
throw Error msg unless good
6466

6567
# Polyfill Node assert's fail
6668
@fail = ->
@@ -94,16 +96,9 @@ <h1>CoffeeScript Test Suite</h1>
9496
# Run the tests
9597
for test in document.getElementsByClassName 'test'
9698
say '\u2714 ' + test.id
97-
try
98-
options = {}
99-
options.literate = yes if test.type is 'text/x-literate-coffeescript'
100-
CoffeeScript.run test.innerHTML, options
101-
catch exception
102-
# debugger
103-
say "#{desc}:", 'bad'
104-
say fnStr, 'subtle'
105-
say exception, 'bad'
106-
console.error exception
99+
options = {}
100+
options.literate = yes if test.type is 'text/x-literate-coffeescript'
101+
CoffeeScript.run test.innerHTML, options
107102

108103
# Finish up
109104
yay = success is total and not failed

0 commit comments

Comments
 (0)