error rewriting spec

This commit is contained in:
leaf corcoran 2013-06-08 00:33:02 -07:00
parent 8e2a4daa4a
commit d42bbff853
6 changed files with 38 additions and 2 deletions

View File

@ -107,5 +107,6 @@ end
return { return {
rewrite_traceback = rewrite_traceback, rewrite_traceback = rewrite_traceback,
truncate_traceback = truncate_traceback, truncate_traceback = truncate_traceback,
user_error = user_error user_error = user_error,
reverse_line_number = reverse_line_number
} }

View File

@ -84,5 +84,5 @@ rewrite_traceback = (text, err) ->
}, "\n" }, "\n"
{ :rewrite_traceback, :truncate_traceback, :user_error } { :rewrite_traceback, :truncate_traceback, :user_error, :reverse_line_number }

View File

@ -1,6 +1,8 @@
hello_world = false hello_world = false
print = ->
if hello_world if hello_world
print "sackman" print "sackman"
x = 5 + 5 x = 5 + 5

View File

@ -1,4 +1,5 @@
print = ->
if false if false
true true

View File

@ -1,4 +1,6 @@
print = ->
if (-> if (->
print "hello world" print "hello world"
print "who is this") print "who is this")

View File

@ -0,0 +1,30 @@
moonscript = require "moonscript.base"
errors = require "moonscript.errors"
util = require "moonscript.util"
get_rewritten_line_no = (fname) ->
fname = "spec/error_inputs/#{fname}.moon"
chunk = moonscript.loadfile fname
success, err = pcall chunk
error "`#{fname}` is supposed to have runtime error!" if success
source = tonumber err\match "]:(%d+)"
line_table = require("moonscript.line_tables")[fname]
errors.reverse_line_number fname, line_table, source, {}
-- TODO: check entire stack trace
describe "error rewriting", ->
tests = {
"first": 24
"second": 16
"third": 11
}
for name, expected_no in pairs tests
it "should rewrite line number", ->
assert.same get_rewritten_line_no(name), expected_no