mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
error rewriting spec
This commit is contained in:
parent
8e2a4daa4a
commit
d42bbff853
@ -107,5 +107,6 @@ end
|
||||
return {
|
||||
rewrite_traceback = rewrite_traceback,
|
||||
truncate_traceback = truncate_traceback,
|
||||
user_error = user_error
|
||||
user_error = user_error,
|
||||
reverse_line_number = reverse_line_number
|
||||
}
|
||||
|
@ -84,5 +84,5 @@ rewrite_traceback = (text, err) ->
|
||||
}, "\n"
|
||||
|
||||
|
||||
{ :rewrite_traceback, :truncate_traceback, :user_error }
|
||||
{ :rewrite_traceback, :truncate_traceback, :user_error, :reverse_line_number }
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
|
||||
hello_world = false
|
||||
|
||||
print = ->
|
||||
|
||||
if hello_world
|
||||
print "sackman"
|
||||
x = 5 + 5
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
print = ->
|
||||
|
||||
if false
|
||||
true
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
print = ->
|
||||
|
||||
if (->
|
||||
print "hello world"
|
||||
print "who is this")
|
||||
|
30
spec/error_rewriting_spec.moon
Normal file
30
spec/error_rewriting_spec.moon
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user