diff --git a/init.lua b/init.lua index 02ca077..63af32a 100644 --- a/init.lua +++ b/init.lua @@ -371,49 +371,53 @@ function M.run_tests(_ctx) captured_entries = entries end - -- Form-1 path - local container12a = fresh_container{ - { template = "craft_display_test.rock", count = 1 }, - } - local widget12a = display.create(container12a) - display.register_action(widget12a, "Craft", function(rid, ctx_inner) - widget12a._captured = { rid = rid, ctx_inner = ctx_inner } - end) - display._invoke_context_menu(widget12a, "alias_r12", 0, 0) local f1_ok = false - if captured_entries and #captured_entries == 1 then - captured_entries[1].callback({ close_menu = function() end }) - local cap = widget12a._captured - f1_ok = cap ~= nil - and cap.rid == "alias_r12" - and cap.ctx_inner.locale == container12a - and cap.ctx_inner.container == container12a - end - - -- Form-2 path - captured_entries = nil - local c12b_src1 = fresh_container{ - { template = "craft_display_test.rock", count = 1 }, - } - local c12b_src2 = fresh_container{} - local locale_table12 = { sources = { c12b_src1, c12b_src2 }, sink = c12b_src2 } - local widget12b = display.create(function() return locale_table12 end) - display.register_action(widget12b, "Craft", function(rid, ctx_inner) - widget12b._captured = { rid = rid, ctx_inner = ctx_inner } - end) - display._invoke_context_menu(widget12b, "alias_r12", 0, 0) local f2_ok = false - if captured_entries and #captured_entries == 1 then - captured_entries[1].callback({ close_menu = function() end }) - local cap = widget12b._captured - f2_ok = cap ~= nil - and cap.rid == "alias_r12" - and cap.ctx_inner.locale == locale_table12 - and cap.ctx_inner.container == c12b_src2 -- sink alias - end + local body_ok, body_err = pcall(function() + -- Form-1 path + local container12a = fresh_container{ + { template = "craft_display_test.rock", count = 1 }, + } + local widget12a = display.create(container12a) + display.register_action(widget12a, "Craft", function(rid, ctx_inner) + widget12a._captured = { rid = rid, ctx_inner = ctx_inner } + end) + display._invoke_context_menu(widget12a, "alias_r12", 0, 0) + if captured_entries and #captured_entries == 1 then + captured_entries[1].callback({ close_menu = function() end }) + local cap = widget12a._captured + f1_ok = cap ~= nil + and cap.rid == "alias_r12" + and cap.ctx_inner.locale == container12a + and cap.ctx_inner.container == container12a + end + + -- Form-2 path + captured_entries = nil + local c12b_src1 = fresh_container{ + { template = "craft_display_test.rock", count = 1 }, + } + local c12b_src2 = fresh_container{} + local locale_table12 = { sources = { c12b_src1, c12b_src2 }, sink = c12b_src2 } + local widget12b = display.create(function() return locale_table12 end) + display.register_action(widget12b, "Craft", function(rid, ctx_inner) + widget12b._captured = { rid = rid, ctx_inner = ctx_inner } + end) + display._invoke_context_menu(widget12b, "alias_r12", 0, 0) + if captured_entries and #captured_entries == 1 then + captured_entries[1].callback({ close_menu = function() end }) + local cap = widget12b._captured + f2_ok = cap ~= nil + and cap.rid == "alias_r12" + and cap.ctx_inner.locale == locale_table12 + and cap.ctx_inner.container == c12b_src2 -- sink alias + end + end) panel.show_context_menu = saved_show + if not body_ok then error(body_err, 0) end + T.assert(f1_ok and f2_ok, "12. ctx_inner carries locale + container alias: Form-1 (handle == " .. "locale == container); Form-2 (locale==table, container==sink)")