Skip to content

Commit

Permalink
Add tests for try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Sep 10, 2023
1 parent ccf0cbf commit 1d6d1ad
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions testes/pluto/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,44 @@ do
assert(release_bytecode:find("Script running in release mode") ~= nil)
end

print "Testing try/catch."
do
-- Test case: Try does not return
local function test(x)
local ret
try
if x then
error("error", 0)
end
ret = true
catch e then
ret = false
end
return ret
end
assert(test(false) == true)
assert(test(true) == false)
end
do
-- Test case: Try does return
local function test(x)
try
if x then
error("error", 0)
end
return true, "ok"
catch e then
return false, e
end
end
local b, s = test(false)
assert(b == true)
assert(s == "ok")
b, s = test(true)
assert(b == false)
assert(s == "error")
end

print "Testing compatibility."
do
local a = "Hi"
Expand Down

0 comments on commit 1d6d1ad

Please sign in to comment.