Skip to content

Commit

Permalink
Ensure test failures get fully outputted.
Browse files Browse the repository at this point in the history
Node's console.log() is non-blocking, so I was seeing test failure output get
cut off since it was happening on process exit. No more!
  • Loading branch information
aseemk committed Aug 12, 2011
1 parent 42f2bd9 commit 41b8b32
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions Cakefile
Expand Up @@ -195,26 +195,6 @@ runTests = (CoffeeScript) ->

global.arrayEq = (a, b, msg) -> ok arrayEqual(a,b), msg

# When all the tests have run, collect and print errors.
# If a stacktrace is available, output the compiled function source.
process.on 'exit', ->
time = ((Date.now() - startTime) / 1000).toFixed(2)
message = "passed #{passedTests} tests in #{time} seconds#{reset}"
return log(message, green) unless failures.length
log "failed #{failures.length} and #{message}", red
for fail in failures
{error, filename} = fail
jsFilename = filename.replace(/\.coffee$/,'.js')
match = error.stack?.match(new RegExp(fail.file+":(\\d+):(\\d+)"))
match = error.stack?.match(/on line (\d+):/) unless match
[match, line, col] = match if match
console.log ''
log " #{error.description}", red if error.description
log " #{error.stack}", red
log " #{jsFilename}: line #{line ? 'unknown'}, column #{col ? 'unknown'}", red
console.log " #{error.source}" if error.source
return

# Run every test in the `test` folder, recording failures.
files = fs.readdirSync 'test'
for file in files when file.match /\.coffee$/i
Expand All @@ -224,6 +204,28 @@ runTests = (CoffeeScript) ->
CoffeeScript.run code.toString(), {filename}
catch error
failures.push {filename, error}

# When all the tests have run, collect and print errors.
# If a stacktrace is available, output the compiled function source.
time = ((Date.now() - startTime) / 1000).toFixed(2)
message = "passed #{passedTests} tests in #{time} seconds#{reset}"
return log(message, green) unless failures.length
log "failed #{failures.length} and #{message}", red
for fail in failures
{error, filename} = fail
jsFilename = filename.replace(/\.coffee$/,'.js')
match = error.stack?.match(new RegExp(fail.file+":(\\d+):(\\d+)"))
match = error.stack?.match(/on line (\d+):/) unless match
[match, line, col] = match if match
console.log ''
log " #{error.description}", red if error.description
log " #{error.stack}", red
log " #{jsFilename}: line #{line ? 'unknown'}, column #{col ? 'unknown'}", red
console.log " #{error.source}" if error.source

# ensure process waits for console.log to drain before exiting
process.stdout.on 'drain', ->

return !failures.length


Expand Down

0 comments on commit 41b8b32

Please sign in to comment.