diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-26 17:45:26 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-26 17:45:56 +0800 |
| commit | e02321107277a63e7dcb12ab163c9942ac101b87 (patch) | |
| tree | f38c6f2fbf4ee35df4938933dbc1e645733356f4 /spec/outputs/test/try_catch_spec.lua | |
| parent | 5d5b657f606b5939062983b1f90c3359d542672e (diff) | |
| download | yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.gz yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.bz2 yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.zip | |
Updated tests.
Diffstat (limited to 'spec/outputs/test/try_catch_spec.lua')
| -rw-r--r-- | spec/outputs/test/try_catch_spec.lua | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/spec/outputs/test/try_catch_spec.lua b/spec/outputs/test/try_catch_spec.lua index 2bcfc16..4183610 100644 --- a/spec/outputs/test/try_catch_spec.lua +++ b/spec/outputs/test/try_catch_spec.lua | |||
| @@ -1,14 +1,20 @@ | |||
| 1 | local _anon_func_0 = function(error) | ||
| 2 | return error("boom") | ||
| 3 | end | ||
| 4 | local _anon_func_1 = function(e, error) | ||
| 5 | return error("wrap:" .. e:match("^.-:%d+:%s*(.*)$")) | ||
| 6 | end | ||
| 1 | return describe("try/catch", function() | 7 | return describe("try/catch", function() |
| 2 | return it("catch and rethrow", function() | 8 | return it("catch and rethrow", function() |
| 9 | local pcall <const> = pcall | ||
| 10 | local error <const> = error | ||
| 11 | local xpcall <const> = xpcall | ||
| 12 | local assert <const> = assert | ||
| 3 | local ok, success, err = pcall(function() | 13 | local ok, success, err = pcall(function() |
| 4 | return xpcall(function() | 14 | return xpcall(_anon_func_0, function(e) |
| 5 | return error("boom") | 15 | local _, result = pcall(_anon_func_1, e, error) |
| 6 | end, function(e) | ||
| 7 | local _, result = pcall(function() | ||
| 8 | return error("wrap:" .. e:match("^.-:%d+:%s*(.*)$")) | ||
| 9 | end) | ||
| 10 | return result | 16 | return result |
| 11 | end) | 17 | end, error) |
| 12 | end) | 18 | end) |
| 13 | assert.same(ok, true) | 19 | assert.same(ok, true) |
| 14 | assert.same(success, false) | 20 | assert.same(success, false) |
