Cakefile: build:full exits unsuccessfully when tests or builds fail;
test failures now print full stack trace
This commit is contained in:
parent
860c5030d2
commit
d2d02bf91d
48
Cakefile
48
Cakefile
|
@ -28,10 +28,12 @@ sources = [
|
|||
]
|
||||
|
||||
# Run a CoffeeScript through our node/coffee interpreter.
|
||||
run = (args) ->
|
||||
run = (args, cb) ->
|
||||
proc = spawn 'bin/coffee', args
|
||||
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
|
||||
proc.on 'exit', (status) -> process.exit(1) if status != 0
|
||||
proc.on 'exit', (status) ->
|
||||
process.exit(1) if status != 0
|
||||
cb() if typeof cb is 'function'
|
||||
|
||||
# Log a message with a color.
|
||||
log = (message, color, explanation) ->
|
||||
|
@ -59,17 +61,16 @@ task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options)
|
|||
)
|
||||
|
||||
|
||||
task 'build', 'build the CoffeeScript language from source', ->
|
||||
task 'build', 'build the CoffeeScript language from source', build = (cb) ->
|
||||
files = fs.readdirSync 'src'
|
||||
files = ('src/' + file for file in files when file.match(/\.coffee$/))
|
||||
run ['-c', '-o', 'lib'].concat(files)
|
||||
run ['-c', '-o', 'lib'].concat(files), cb
|
||||
|
||||
|
||||
task 'build:full', 'rebuild the source twice, and run the tests', ->
|
||||
exec 'bin/cake build && bin/cake build && bin/cake test', (err, stdout, stderr) ->
|
||||
console.log stdout.trim() if stdout
|
||||
console.log stderr.trim() if stderr
|
||||
throw err if err
|
||||
build ->
|
||||
build ->
|
||||
process.exit 1 unless runTests CoffeeScript
|
||||
|
||||
|
||||
task 'build:parser', 'rebuild the Jison parser (run build first)', ->
|
||||
|
@ -175,7 +176,7 @@ runTests = (CoffeeScript) ->
|
|||
catch e
|
||||
e.description = description if description?
|
||||
e.source = fn.toString() if fn.toString?
|
||||
failures.push file: currentFile, error: e
|
||||
failures.push filename: currentFile, error: e
|
||||
|
||||
# A recursive functional equivalence helper; uses egal for testing equivalence.
|
||||
# See http://wiki.ecmascript.org/doku.php?id=harmony:egal
|
||||
|
@ -201,27 +202,28 @@ runTests = (CoffeeScript) ->
|
|||
return log(message, green) unless failures.length
|
||||
log "failed #{failures.length} and #{message}", red
|
||||
for fail in failures
|
||||
{error, file} = fail
|
||||
jsFile = file.replace(/\.coffee$/,'.js')
|
||||
{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
|
||||
log "\n #{error.toString()}", red
|
||||
console.log ''
|
||||
log " #{error.description}", red if error.description
|
||||
log " #{jsFile}: line #{line or 'unknown'}, column #{col or 'unknown'}", red
|
||||
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.
|
||||
fs.readdir 'test', (err, files) ->
|
||||
files.forEach (file) ->
|
||||
return unless file.match(/\.coffee$/i)
|
||||
filename = path.join 'test', file
|
||||
fs.readFile filename, (err, code) ->
|
||||
currentFile = filename
|
||||
try
|
||||
CoffeeScript.run code.toString(), {filename}
|
||||
catch e
|
||||
failures.push file: currentFile, error: e
|
||||
files = fs.readdirSync 'test'
|
||||
for file in files when file.match /\.coffee$/i
|
||||
currentFile = filename = path.join 'test', file
|
||||
code = fs.readFileSync filename
|
||||
try
|
||||
CoffeeScript.run code.toString(), {filename}
|
||||
catch error
|
||||
failures.push {filename, error}
|
||||
return !failures.length
|
||||
|
||||
|
||||
task 'test', 'run the CoffeeScript language test suite', ->
|
||||
|
|
Loading…
Reference in New Issue