1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/error_messages.coffee
2013-03-21 03:11:31 -03:00

63 lines
No EOL
1.5 KiB
CoffeeScript

# Error Formating
# ---------------
# Ensure that errors of different kinds (lexer, parser and compiler) are shown
# in a consistent way.
{prettyErrorMessage} = CoffeeScript.helpers
assertErrorFormat = (code, expectedErrorFormat) ->
throws (-> CoffeeScript.run code), (err) ->
message = prettyErrorMessage err, 'test.coffee', code
eq expectedErrorFormat, message
yes
test "lexer errors formating", ->
assertErrorFormat '''
normalObject = {}
insideOutObject = }{
''',
'''
test.coffee:2:19: error: unmatched }
insideOutObject = }{
^
'''
test "parser error formating", ->
assertErrorFormat '''
foo in bar or in baz
''',
'''
test.coffee:1:15: error: unexpected RELATION
foo in bar or in baz
^^
'''
test "compiler error formatting", ->
assertErrorFormat '''
evil = (foo, eval, bar) ->
''',
'''
test.coffee:1:14: error: parameter name "eval" is not allowed
evil = (foo, eval, bar) ->
^^^^
'''
fs = require 'fs'
test "#2849: compilation error in a require()d file", ->
# Create a temporary file to require().
ok not fs.existsSync 'test/syntax-error.coffee'
fs.writeFileSync 'test/syntax-error.coffee', 'foo in bar or in baz'
try
assertErrorFormat '''
require './test/syntax-error'
''',
"""
#{__dirname}/syntax-error.coffee:1:15: error: unexpected RELATION
foo in bar or in baz
^^
"""
finally
fs.unlink 'test/syntax-error.coffee'