Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async/await semantics (diamod arrows as demonstration) #3813

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 42 additions & 18 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ task 'build:full', 'rebuild the source twice, and run the tests', ->
for mod of require.cache when csDir is mod[0 ... csDir.length]
delete require.cache[mod]

unless runTests require csPath
process.exit 1
runTests (require csPath), (success) ->
unless success
process.exit 1


task 'build:parser', 'rebuild the Jison parser (run build first)', ->
Expand Down Expand Up @@ -215,31 +216,43 @@ task 'bench', 'quick benchmark of compilation time', ->


# Run the CoffeeScript test suite.
runTests = (CoffeeScript) ->
runTests = (CoffeeScript, cb) ->
CoffeeScript.register()
startTime = Date.now()
currentFile = null
passedTests = 0
failures = []
promises = []

global[name] = func for name, func of require 'assert'

# Convenience aliases.
global.CoffeeScript = CoffeeScript
global.Repl = require './lib/coffee-script/repl'

# Simple chek if value is Promise-like (thenable)
isPromise = (p) -> typeof p?.then is 'function'

# Our test helper function for delimiting different test cases.
global.test = (description, fn) ->
try
fn.test = {description, currentFile}
fn.call(fn)
++passedTests
catch e
failures.push
filename: currentFile
error: e
description: description if description?
source: fn.toString() if fn.toString?
do (currentFile) ->
resolve = ->
++passedTests
reject = (e) ->
failures.push
filename: currentFile
error: e
description: description if description?
source: fn.toString() if fn.toString?
try
fn.test = {description, currentFile}
res = fn.call(fn)
if isPromise res
promises.push res.then resolve, reject
else
resolve()
catch e
reject e

# See http://wiki.ecmascript.org/doku.php?id=harmony:egal
egal = (a, b) ->
Expand Down Expand Up @@ -277,10 +290,15 @@ runTests = (CoffeeScript) ->
# Run every test in the `test` folder, recording failures.
files = fs.readdirSync 'test'

# Ignore generators test file if generators are not available
generatorsAreAvailable = '--harmony' in process.execArgv or
'--harmony-generators' in process.execArgv
files.splice files.indexOf('generators.coffee'), 1 if not generatorsAreAvailable
try
# Test if generators are available (throws if they aren't)
eval "(function*(){})"

# Extend the list of tests for generator-dependent features
generatorTests = fs.readdirSync path.join 'test', 'generators'
[].push.apply files, generatorTests.map (file) ->
path.join 'generators', file


for file in files when helpers.isCoffee file
literate = helpers.isLiterate file
Expand All @@ -290,7 +308,13 @@ runTests = (CoffeeScript) ->
CoffeeScript.run code.toString(), {filename, literate}
catch error
failures.push {filename, error}
return !failures.length

done = -> cb? !failures.length

if global.Promise?
global.Promise.all(promises).then done, done
else
done()


task 'test', 'run the CoffeeScript language test suite', ->
Expand Down
20 changes: 18 additions & 2 deletions lib/coffee-script/grammar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/coffee-script/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 31 additions & 7 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading