diff --git a/test/misc/goto.lua b/test/lang/goto.lua similarity index 66% rename from test/misc/goto.lua rename to test/lang/goto.lua index 8553a8aa90..1563a234ae 100644 --- a/test/misc/goto.lua +++ b/test/lang/goto.lua @@ -1,15 +1,15 @@ +local loadstring = loadstring or load --- Basic goto and label semantics. -do - local function expect(src, msg) - local ok, err = loadstring(src) - if msg then - assert(not ok and string.find(err, msg)) - else - assert(ok) - end +local function expect(src, msg) + local ok, err = loadstring(src) + if msg then + assert(not ok and string.find(err, msg), err) + else + assert(ok, err) end - +end + +do --- Basic goto and label semantics. -- Error: duplicate label. expect("::a:: ::a::", "'a'") expect("::a:: ::b:: do ::b:: end ::a::", "'a'") @@ -27,17 +27,18 @@ do expect("do local v,w; goto a; end; local x; ::a:: local y", "'x'") expect("repeat goto a; local x; ::a:: until x", "'x'") - if os.getenv("LUA52") then - expect("goto = 1", "") - else - expect("goto = 1") - end - ::a:: do goto a; ::a:: end -- Forward jump, not an infinite loop. end --- Trailing label is considered to be out of scope. -do +do --- Goto is not a keyword. -compat5.2 !lex !private_G + goto = 1 +end + +do --- Goto is a keyword. +compat5.2 + expect("goto = 1", "") +end + +do --- Trailing label is considered to be out of scope. local x = 11 do goto a @@ -48,24 +49,22 @@ do ::b:: end assert(x == 11) - if os.getenv("LUA52") then - assert(loadstring([[ - local x = 11 - do - goto a - goto a - local y = 22 - x = y - ::a:: ;; - ::b:: ;; - end - return x - ]])() == 11) +end + +do --- Trailing labels and empty statements are considered to be out of scope. +compat5.2 !lex + local x = 11 + do + goto a + goto a + local y = 22 + x = y + ::a:: ;; + ::b:: ;; end + assert(x == 11) end --- Simple loop with cross-jumping. -do +do --- Simple loop with cross-jumping. local x = 1 while true do goto b @@ -78,8 +77,7 @@ do assert(x == 100) end --- Backwards goto must close upval. -do +do --- Backwards goto must close upval. local t = {} local i = 1 ::a:: @@ -92,8 +90,7 @@ do assert(t[2]() == 2) end --- Break must close upval, even if closure is parsed after break. -do +do --- Break must close upval, even if closure is parsed after break. local foo repeat local x @@ -106,8 +103,7 @@ do assert(foo() == true) end --- Label prevents joining to KNIL. -do +do --- Label prevents joining to KNIL. -lua==5.2 local k = 0 local x ::foo:: @@ -118,8 +114,7 @@ do if k < 2 then goto foo end end --- Break resolved from the right scope. -do +do --- Break resolved from the right scope. local function p(lvl) lvl = lvl or 1 while true do @@ -134,8 +129,7 @@ do end end --- Do not join twice with UCLO. -do +do --- Do not join twice with UCLO. while true do do local x @@ -153,4 +147,3 @@ do end ::foo:: end - diff --git a/test/lang/index b/test/lang/index index 743c5bce9e..1cdf404ee6 100644 --- a/test/lang/index +++ b/test/lang/index @@ -10,3 +10,4 @@ upvalue coroutine.lua tail_recursion.lua gc.lua +goto.lua +goto diff --git a/test/test.lua b/test/test.lua index bf16c2745a..e31660185d 100644 --- a/test/test.lua +++ b/test/test.lua @@ -18,6 +18,9 @@ local function default_tags() if loadstring"return 0xep+9" then tags.hexfloat = true end + if loadstring"goto x ::x::" then + tags["goto"] = true + end -- Libraries for _, lib in ipairs{"bit", "ffi", "jit.profile", "table.new"} do