2010-10-11 18:22:01 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
|
|
|
<title>CoffeeScript Test Suite</title>
|
2016-11-29 21:13:12 -05:00
|
|
|
<script src="browser-compiler/coffee-script.js"></script>
|
2016-11-30 01:20:38 -05:00
|
|
|
<script src="https://cdn.jsdelivr.net/underscorejs/1.8.3/underscore-min.js"></script>
|
2010-10-11 18:22:01 -04:00
|
|
|
<style>
|
2016-11-29 21:13:12 -05:00
|
|
|
body, pre {
|
|
|
|
font-family: Consolas, Menlo, Monaco, monospace;
|
|
|
|
}
|
2010-10-11 18:22:01 -04:00
|
|
|
body {
|
2016-11-29 21:13:12 -05:00
|
|
|
margin: 1em;
|
2010-10-11 18:22:01 -04:00
|
|
|
}
|
|
|
|
h1 {
|
2016-11-29 21:13:12 -05:00
|
|
|
font-size: 1.3em;
|
|
|
|
}
|
|
|
|
div {
|
|
|
|
margin: 0.6em;
|
|
|
|
}
|
|
|
|
.good {
|
|
|
|
color: #22b24c
|
2010-10-11 18:22:01 -04:00
|
|
|
}
|
2016-11-29 21:13:12 -05:00
|
|
|
.bad {
|
|
|
|
color: #eb6864
|
2010-10-11 18:22:01 -04:00
|
|
|
}
|
2016-11-30 00:37:54 -05:00
|
|
|
.subtle {
|
|
|
|
font-size: 0.7em;
|
|
|
|
color: #999999
|
|
|
|
}
|
2010-10-11 18:22:01 -04:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
2016-11-29 21:13:12 -05:00
|
|
|
<h1>CoffeeScript Test Suite</h1>
|
|
|
|
|
|
|
|
<pre id="stdout"></pre>
|
|
|
|
|
|
|
|
<script type="text/coffeescript">
|
2016-11-30 00:37:54 -05:00
|
|
|
@testingBrowser = yes
|
2016-11-30 03:34:07 -05:00
|
|
|
@global = window
|
2016-11-29 21:13:12 -05:00
|
|
|
stdout = document.getElementById 'stdout'
|
|
|
|
start = new Date
|
|
|
|
success = total = done = failed = 0
|
2010-10-11 18:22:01 -04:00
|
|
|
|
2016-11-30 00:37:54 -05:00
|
|
|
say = (msg, className) ->
|
2016-11-29 21:13:12 -05:00
|
|
|
div = document.createElement 'div'
|
2016-11-30 00:37:54 -05:00
|
|
|
div.className = className if className?
|
2016-11-29 21:13:12 -05:00
|
|
|
div.appendChild document.createTextNode msg
|
|
|
|
stdout.appendChild div
|
|
|
|
msg
|
2010-10-11 18:22:01 -04:00
|
|
|
|
2016-11-29 21:27:34 -05:00
|
|
|
@test = (description, fn) ->
|
2016-11-30 03:34:07 -05:00
|
|
|
++total
|
|
|
|
try
|
|
|
|
fn.call(fn)
|
|
|
|
++success
|
|
|
|
catch exception
|
|
|
|
say "#{description}:", 'bad'
|
|
|
|
say fn.toString(), 'subtle' if fn.toString?
|
|
|
|
say exception, 'bad'
|
|
|
|
console.error exception
|
2010-10-11 18:22:01 -04:00
|
|
|
|
2016-11-30 01:20:38 -05:00
|
|
|
@ok = (good, msg = 'Error') ->
|
2016-11-30 03:34:07 -05:00
|
|
|
throw Error msg unless good
|
2010-10-11 18:22:01 -04:00
|
|
|
|
2016-11-30 01:20:38 -05:00
|
|
|
# Polyfill Node assert's fail
|
|
|
|
@fail = ->
|
|
|
|
ok no
|
|
|
|
|
|
|
|
# Polyfill Node assert's deepEqual with Underscore's isEqual
|
|
|
|
@deepEqual = (a, b) ->
|
|
|
|
ok _.isEqual(a, b), "Expected #{JSON.stringify a} to deep equal #{JSON.stringify b}"
|
|
|
|
|
2016-11-30 00:19:11 -05:00
|
|
|
<%= testHelpers %>
|
2010-10-11 18:22:01 -04:00
|
|
|
|
2016-11-29 21:13:12 -05:00
|
|
|
@doesNotThrow = (fn) ->
|
|
|
|
fn()
|
2016-11-30 01:20:38 -05:00
|
|
|
ok yes
|
2010-10-11 18:22:01 -04:00
|
|
|
|
2016-11-29 21:13:12 -05:00
|
|
|
@throws = (fun, err, msg) ->
|
|
|
|
try
|
|
|
|
fun()
|
|
|
|
catch e
|
|
|
|
if err
|
2016-11-30 01:20:38 -05:00
|
|
|
if typeof err is 'function' and e instanceof err # Handle comparing exceptions
|
|
|
|
ok yes
|
2016-12-11 02:25:20 -05:00
|
|
|
else if e.toString().indexOf('[stdin]') is 0 # Handle comparing error messages
|
|
|
|
ok err e
|
2016-11-30 01:20:38 -05:00
|
|
|
else
|
|
|
|
eq e, err
|
2010-12-13 06:28:17 -05:00
|
|
|
else
|
2016-11-29 21:13:12 -05:00
|
|
|
ok yes
|
|
|
|
return
|
|
|
|
ok no
|
|
|
|
|
2016-11-30 01:20:38 -05:00
|
|
|
|
2016-11-29 21:13:12 -05:00
|
|
|
# Run the tests
|
|
|
|
for test in document.getElementsByClassName 'test'
|
|
|
|
say '\u2714 ' + test.id
|
2016-11-30 03:34:07 -05:00
|
|
|
options = {}
|
|
|
|
options.literate = yes if test.type is 'text/x-literate-coffeescript'
|
|
|
|
CoffeeScript.run test.innerHTML, options
|
2016-11-29 21:13:12 -05:00
|
|
|
|
|
|
|
# Finish up
|
|
|
|
yay = success is total and not failed
|
|
|
|
sec = (new Date - start) / 1000
|
|
|
|
msg = "passed #{success} tests in #{ sec.toFixed 2 } seconds"
|
|
|
|
msg = "failed #{ total - success } tests and #{msg}" unless yay
|
2016-11-30 00:37:54 -05:00
|
|
|
say msg, (if yay then 'good' else 'bad')
|
2016-11-29 21:13:12 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<%= tests %>
|
2010-10-11 18:22:01 -04:00
|
|
|
|
|
|
|
</body>
|
2010-12-13 06:28:17 -05:00
|
|
|
</html>
|