@@ -28,10 +28,12 @@ sources = [
2828]
2929
3030# Run a CoffeeScript through our node/coffee interpreter.
31- run = (args ) ->
31+ run = (args , cb ) ->
3232 proc = spawn ' bin/coffee' , args
3333 proc .stderr .on ' data' , (buffer ) -> console .log buffer .toString ()
34- proc .on ' exit' , (status ) -> process .exit (1 ) if status != 0
34+ proc .on ' exit' , (status ) ->
35+ process .exit (1 ) if status != 0
36+ cb () if typeof cb is ' function'
3537
3638# Log a message with a color.
3739log = (message , color , explanation ) ->
@@ -59,17 +61,16 @@ task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options)
5961 )
6062
6163
62- task ' build' , ' build the CoffeeScript language from source' , ->
64+ task ' build' , ' build the CoffeeScript language from source' , build = ( cb ) ->
6365 files = fs .readdirSync ' src'
6466 files = (' src/' + file for file in files when file .match (/ \. coffee$ / ))
65- run [' -c' , ' -o' , ' lib' ].concat (files)
67+ run [' -c' , ' -o' , ' lib' ].concat (files), cb
6668
6769
6870task ' build:full' , ' rebuild the source twice, and run the tests' , ->
69- exec ' bin/cake build && bin/cake build && bin/cake test' , (err , stdout , stderr ) ->
70- console .log stdout .trim () if stdout
71- console .log stderr .trim () if stderr
72- throw err if err
71+ build ->
72+ build ->
73+ process .exit 1 unless runTests CoffeeScript
7374
7475
7576task ' build:parser' , ' rebuild the Jison parser (run build first)' , ->
@@ -175,7 +176,7 @@ runTests = (CoffeeScript) ->
175176 catch e
176177 e .description = description if description?
177178 e .source = fn .toString () if fn .toString ?
178- failures .push file : currentFile, error : e
179+ failures .push filename : currentFile, error : e
179180
180181 # A recursive functional equivalence helper; uses egal for testing equivalence.
181182 # See http://wiki.ecmascript.org/doku.php?id=harmony:egal
@@ -201,27 +202,28 @@ runTests = (CoffeeScript) ->
201202 return log (message, green) unless failures .length
202203 log " failed #{ failures .length } and #{ message} " , red
203204 for fail in failures
204- {error , file } = fail
205- jsFile = file .replace (/ \. coffee$ / ,' .js' )
205+ {error , filename } = fail
206+ jsFilename = filename .replace (/ \. coffee$ / ,' .js' )
206207 match = error .stack ? .match (new RegExp (fail .file + " :(\\ d+):(\\ d+)" ))
207208 match = error .stack ? .match (/ on line (\d + ):/ ) unless match
208209 [match , line , col ] = match if match
209- log " \n #{ error . toString () } " , red
210+ console . log ' '
210211 log " #{ error .description } " , red if error .description
211- log " #{ jsFile} : line #{ line or ' unknown' } , column #{ col or ' unknown' } " , red
212+ log " #{ error .stack } " , red
213+ log " #{ jsFilename} : line #{ line ? ' unknown' } , column #{ col ? ' unknown' } " , red
212214 console .log " #{ error .source } " if error .source
215+ return
213216
214217 # Run every test in the `test` folder, recording failures.
215- fs .readdir ' test' , (err , files ) ->
216- files .forEach (file) ->
217- return unless file .match (/ \. coffee$ / i )
218- filename = path .join ' test' , file
219- fs .readFile filename, (err , code ) ->
220- currentFile = filename
221- try
222- CoffeeScript .run code .toString (), {filename}
223- catch e
224- failures .push file : currentFile, error : e
218+ files = fs .readdirSync ' test'
219+ for file in files when file .match / \. coffee$ / i
220+ currentFile = filename = path .join ' test' , file
221+ code = fs .readFileSync filename
222+ try
223+ CoffeeScript .run code .toString (), {filename}
224+ catch error
225+ failures .push {filename, error}
226+ return ! failures .length
225227
226228
227229task ' test' , ' run the CoffeeScript language test suite' , ->
0 commit comments