Skip to content

Commit

Permalink
Improvements in the traceback test samples
Browse files Browse the repository at this point in the history
  • Loading branch information
singul4ri7y committed Jun 7, 2024
1 parent ed41c08 commit 07b975f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
12 changes: 7 additions & 5 deletions spec/traceback/depth_recursion/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

local pallene = require 'spec.traceback.depth_recursion.depth_recursion'

function lua_fn(depth)
function _G.lua_fn(depth)
if depth == 0 then
error "Depth reached 0!"
end

pallene.pallene_fn(lua_fn, depth - 1)
pallene.pallene_fn(_G.lua_fn, depth - 1)
end

local function wrapper()
lua_fn(10)
-- Should be local.
-- Making it global so that it is visible in the traceback.
function _G.wrapper()
_G.lua_fn(10)
end

xpcall(wrapper, pallene_tracer_debug_traceback)
xpcall(_G.wrapper, _G.pallene_tracer_debug_traceback)
18 changes: 10 additions & 8 deletions spec/traceback/module_lua/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
local another_module = require 'spec.traceback.module_lua.another_module'
local pallene = require 'spec.traceback.module_lua.module_lua'

function lua_1()
pallene.pallene_1(lua_2)
function _G.lua_1()
pallene.pallene_1(_G.lua_2)
end

function lua_2()
pallene.pallene_2(lua_3, 33, 79)
function _G.lua_2()
pallene.pallene_2(_G.lua_3, 33, 79)
end

function lua_3(sum)
function _G.lua_3(sum)
print("The summation is: ", sum)

error "Any normal error from Lua!"
end

local function wrapper()
another_module.call_lua_callback(lua_1)
-- Should be local.
-- Making it global so that it is visible in the traceback.
function _G.wrapper()
another_module.call_lua_callback(_G.lua_1)
end

xpcall(wrapper, pallene_tracer_debug_traceback)
xpcall(_G.wrapper, _G.pallene_tracer_debug_traceback)
14 changes: 8 additions & 6 deletions spec/traceback/module_pallene/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
local pallene = require 'spec.traceback.module_pallene.module_pallene'
local pallene_alt = require 'spec.traceback.module_pallene.module_pallene_alt'

function lua_2()
function _G.lua_2()
error "There's an error in everyday life. Shame!"
end

function lua_1()
pallene_alt.alternate_everyday_fn(lua_2)
function _G.lua_1()
pallene_alt.alternate_everyday_fn(_G.lua_2)
end

local function wrapper()
pallene.normal_everyday_fn(lua_1)
-- Should be local.
-- Making it global so that it is visible in the traceback.
function _G.wrapper()
pallene.normal_everyday_fn(_G.lua_1)
end

xpcall(wrapper, pallene_tracer_debug_traceback)
xpcall(_G.wrapper, _G.pallene_tracer_debug_traceback)
6 changes: 4 additions & 2 deletions spec/traceback/rect/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

local rect = require 'spec.traceback.rect.rect'

local function wrapper()
-- Should be local.
-- Making it global so that it is visible in the traceback.
function _G.wrapper()
print(rect.area { width = "Huh, gotcha!", height = 16.0 })
end

xpcall(wrapper, pallene_tracer_debug_traceback)
xpcall(_G.wrapper, _G.pallene_tracer_debug_traceback)
24 changes: 12 additions & 12 deletions spec/traceback_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ local function assert_test(test, expected_traceback)
assert(ok, err)

-- Compile the second Pallene file if exists.
local plnfile = util.shell_quote("spec/traceback/"..test.."/"..test.."_alt.pln")
local ok, err = util.execute("test -f "..plnfile)
local alt_plnfile = util.shell_quote("spec/traceback/"..test.."/"..test.."_alt.pln")
local ok, _ = util.execute("test -f "..alt_plnfile)
if ok then
local ok, err = util.execute("pallenec "..plnfile.." --use-traceback")
local ok, err = util.execute("pallenec "..alt_plnfile.." --use-traceback")
assert(ok, err)
end

Expand All @@ -26,13 +26,13 @@ end

it("Rectangle", function()
assert_test("rect", [[
Runtime error: spec/traceback/rect/main.lua:9: file spec/traceback/rect/rect.pln: line 10: wrong type for downcasted value, expected float but found string
Runtime error: spec/traceback/rect/main.lua:11: file spec/traceback/rect/rect.pln: line 10: wrong type for downcasted value, expected float but found string
Stack traceback:
spec/traceback/rect/rect.pln:10: in function 'universal_calc_area'
spec/traceback/rect/rect.pln:13: in function 'area'
spec/traceback/rect/main.lua:9: in function '<?>'
spec/traceback/rect/main.lua:11: in function 'wrapper'
C: in function 'xpcall'
spec/traceback/rect/main.lua:12: in <main>
spec/traceback/rect/main.lua:14: in <main>
C: in function '<?>'
]])
end)
Expand All @@ -48,9 +48,9 @@ Stack traceback:
spec/traceback/module_lua/module_lua.pln:8: in function 'pallene_1'
spec/traceback/module_lua/main.lua:10: in function 'callback'
./spec/traceback/module_lua/another_module.lua:7: in function 'call_lua_callback'
spec/traceback/module_lua/main.lua:24: in function '<?>'
spec/traceback/module_lua/main.lua:26: in function 'wrapper'
C: in function 'xpcall'
spec/traceback/module_lua/main.lua:27: in <main>
spec/traceback/module_lua/main.lua:29: in <main>
C: in function '<?>'
]])
end)
Expand All @@ -64,9 +64,9 @@ Stack traceback:
spec/traceback/module_pallene/module_pallene_alt.pln:8: in function 'alternate_everyday_fn'
spec/traceback/module_pallene/main.lua:14: in function 'lua_1'
spec/traceback/module_pallene/module_pallene.pln:8: in function 'normal_everyday_fn'
spec/traceback/module_pallene/main.lua:18: in function '<?>'
spec/traceback/module_pallene/main.lua:20: in function 'wrapper'
C: in function 'xpcall'
spec/traceback/module_pallene/main.lua:21: in <main>
spec/traceback/module_pallene/main.lua:23: in <main>
C: in function '<?>'
]])
end)
Expand All @@ -87,9 +87,9 @@ Stack traceback:
spec/traceback/depth_recursion/main.lua:13: in function 'lua_fn'
spec/traceback/depth_recursion/depth_recursion.pln:8: in function 'pallene_fn'
spec/traceback/depth_recursion/main.lua:13: in function 'lua_fn'
spec/traceback/depth_recursion/main.lua:17: in function '<?>'
spec/traceback/depth_recursion/main.lua:19: in function 'wrapper'
C: in function 'xpcall'
spec/traceback/depth_recursion/main.lua:20: in <main>
spec/traceback/depth_recursion/main.lua:22: in <main>
C: in function '<?>'
]])
end)
Expand Down

0 comments on commit 07b975f

Please sign in to comment.