aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/all.lua2
-rw-r--r--testes/api.lua14
-rw-r--r--testes/attrib.lua2
-rw-r--r--testes/calls.lua27
-rw-r--r--testes/closure.lua19
-rw-r--r--testes/coroutine.lua2
-rw-r--r--testes/files.lua4
-rw-r--r--testes/main.lua6
-rw-r--r--testes/nextvar.lua14
9 files changed, 58 insertions, 32 deletions
diff --git a/testes/all.lua b/testes/all.lua
index 5df0ff9b..3c1ff5c7 100644
--- a/testes/all.lua
+++ b/testes/all.lua
@@ -3,7 +3,7 @@
3-- See Copyright Notice at the end of this file 3-- See Copyright Notice at the end of this file
4 4
5 5
6local version = "Lua 5.4" 6local version = "Lua 5.5"
7if _VERSION ~= version then 7if _VERSION ~= version then
8 io.stderr:write("This test suite is for ", version, 8 io.stderr:write("This test suite is for ", version,
9 ", not for ", _VERSION, "\nExiting tests") 9 ", not for ", _VERSION, "\nExiting tests")
diff --git a/testes/api.lua b/testes/api.lua
index 752ff18f..dece98f5 100644
--- a/testes/api.lua
+++ b/testes/api.lua
@@ -1046,10 +1046,12 @@ assert(a == nil and c == 2) -- 2 == run-time error
1046a, b, c = T.doremote(L1, "return a+") 1046a, b, c = T.doremote(L1, "return a+")
1047assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error 1047assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error
1048 1048
1049T.loadlib(L1) 1049T.loadlib(L1, 2) -- load only 'package'
1050a, b, c = T.doremote(L1, [[ 1050a, b, c = T.doremote(L1, [[
1051 string = require'string' 1051 string = require'string'
1052 a = require'_G'; assert(a == _G and require("_G") == a) 1052 local initialG = _G -- not loaded yet
1053 local a = require'_G'; assert(a == _G and require("_G") == a)
1054 assert(initialG == nil and io == nil) -- now we have 'assert'
1053 io = require'io'; assert(type(io.read) == "function") 1055 io = require'io'; assert(type(io.read) == "function")
1054 assert(require("io") == io) 1056 assert(require("io") == io)
1055 a = require'table'; assert(type(a.insert) == "function") 1057 a = require'table'; assert(type(a.insert) == "function")
@@ -1063,7 +1065,7 @@ T.closestate(L1);
1063 1065
1064 1066
1065L1 = T.newstate() 1067L1 = T.newstate()
1066T.loadlib(L1) 1068T.loadlib(L1, 0)
1067T.doremote(L1, "a = {}") 1069T.doremote(L1, "a = {}")
1068T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1; 1070T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1;
1069 settable -3]]) 1071 settable -3]])
@@ -1446,10 +1448,10 @@ end
1446 1448
1447do -- garbage collection with no extra memory 1449do -- garbage collection with no extra memory
1448 local L = T.newstate() 1450 local L = T.newstate()
1449 T.loadlib(L) 1451 T.loadlib(L, 1 | 2) -- load _G and 'package'
1450 local res = (T.doremote(L, [[ 1452 local res = (T.doremote(L, [[
1451 _ENV = require"_G" 1453 _ENV = _G
1452 local T = require"T" 1454 assert(string == nil)
1453 local a = {} 1455 local a = {}
1454 for i = 1, 1000 do a[i] = 'i' .. i end -- grow string table 1456 for i = 1, 1000 do a[i] = 'i' .. i end -- grow string table
1455 local stsize, stuse = T.querystr() 1457 local stsize, stuse = T.querystr()
diff --git a/testes/attrib.lua b/testes/attrib.lua
index 458488a8..9054e0b6 100644
--- a/testes/attrib.lua
+++ b/testes/attrib.lua
@@ -236,7 +236,7 @@ package.path = oldpath
236local fname = "file_does_not_exist2" 236local fname = "file_does_not_exist2"
237local m, err = pcall(require, fname) 237local m, err = pcall(require, fname)
238for t in string.gmatch(package.path..";"..package.cpath, "[^;]+") do 238for t in string.gmatch(package.path..";"..package.cpath, "[^;]+") do
239 t = string.gsub(t, "?", fname) 239 local t = string.gsub(t, "?", fname)
240 assert(string.find(err, t, 1, true)) 240 assert(string.find(err, t, 1, true))
241end 241end
242 242
diff --git a/testes/calls.lua b/testes/calls.lua
index a1938584..9a5eed0b 100644
--- a/testes/calls.lua
+++ b/testes/calls.lua
@@ -454,7 +454,7 @@ print("testing binary chunks")
454do 454do
455 local header = string.pack("c4BBc6BBB", 455 local header = string.pack("c4BBc6BBB",
456 "\27Lua", -- signature 456 "\27Lua", -- signature
457 0x54, -- version 5.4 (0x54) 457 0x55, -- version 5.5 (0x55)
458 0, -- format 458 0, -- format
459 "\x19\x93\r\n\x1a\n", -- data 459 "\x19\x93\r\n\x1a\n", -- data
460 4, -- size of instruction 460 4, -- size of instruction
@@ -493,5 +493,30 @@ do
493 end 493 end
494end 494end
495 495
496
497do -- check reuse of strings in dumps
498 local str = "|" .. string.rep("X", 50) .. "|"
499 local foo = load(string.format([[
500 local str <const> = "%s"
501 return {
502 function () return str end,
503 function () return str end,
504 function () return str end
505 }
506 ]], str))
507 -- count occurrences of 'str' inside the dump
508 local dump = string.dump(foo)
509 local _, count = string.gsub(dump, str, {})
510 -- there should be only two occurrences:
511 -- one inside the source, other the string itself.
512 assert(count == 2)
513
514 if T then -- check reuse of strings in undump
515 local funcs = load(dump)()
516 assert(string.format("%p", T.listk(funcs[1])[1]) ==
517 string.format("%p", T.listk(funcs[3])[1]))
518 end
519end
520
496print('OK') 521print('OK')
497return deep 522return deep
diff --git a/testes/closure.lua b/testes/closure.lua
index ea038e82..de1b54ec 100644
--- a/testes/closure.lua
+++ b/testes/closure.lua
@@ -60,32 +60,29 @@ end
60-- testing closures with 'for' control variable 60-- testing closures with 'for' control variable
61a = {} 61a = {}
62for i=1,10 do 62for i=1,10 do
63 a[i] = {set = function(x) i=x end, get = function () return i end} 63 a[i] = function () return i end
64 if i == 3 then break end 64 if i == 3 then break end
65end 65end
66assert(a[4] == undef) 66assert(a[4] == undef)
67a[1].set(10) 67assert(a[2]() == 2)
68assert(a[2].get() == 2) 68assert(a[3]() == 3)
69a[2].set('a')
70assert(a[3].get() == 3)
71assert(a[2].get() == 'a')
72 69
73a = {} 70a = {}
74local t = {"a", "b"} 71local t = {"a", "b"}
75for i = 1, #t do 72for i = 1, #t do
76 local k = t[i] 73 local k = t[i]
77 a[i] = {set = function(x, y) i=x; k=y end, 74 a[i] = {set = function(x) k=x end,
78 get = function () return i, k end} 75 get = function () return i, k end}
79 if i == 2 then break end 76 if i == 2 then break end
80end 77end
81a[1].set(10, 20) 78a[1].set(10)
82local r,s = a[2].get() 79local r,s = a[2].get()
83assert(r == 2 and s == 'b') 80assert(r == 2 and s == 'b')
84r,s = a[1].get() 81r,s = a[1].get()
85assert(r == 10 and s == 20) 82assert(r == 1 and s == 10)
86a[2].set('a', 'b') 83a[2].set('a')
87r,s = a[2].get() 84r,s = a[2].get()
88assert(r == "a" and s == "b") 85assert(r == 2 and s == "a")
89 86
90 87
91-- testing closures with 'for' control variable x break 88-- testing closures with 'for' control variable x break
diff --git a/testes/coroutine.lua b/testes/coroutine.lua
index de7e46fb..990da8c4 100644
--- a/testes/coroutine.lua
+++ b/testes/coroutine.lua
@@ -703,7 +703,7 @@ else
703 703
704 T.testC(state, "settop 0") 704 T.testC(state, "settop 0")
705 705
706 T.loadlib(state) 706 T.loadlib(state, 1 | 2) -- load _G and 'package'
707 707
708 assert(T.doremote(state, [[ 708 assert(T.doremote(state, [[
709 coroutine = require'coroutine'; 709 coroutine = require'coroutine';
diff --git a/testes/files.lua b/testes/files.lua
index be00bf3f..149e9c76 100644
--- a/testes/files.lua
+++ b/testes/files.lua
@@ -427,12 +427,12 @@ do -- testing closing file in line iteration
427 -- get the to-be-closed variable from a loop 427 -- get the to-be-closed variable from a loop
428 local function gettoclose (lv) 428 local function gettoclose (lv)
429 lv = lv + 1 429 lv = lv + 1
430 local stvar = 0 -- to-be-closed is 4th state variable in the loop 430 local stvar = 0 -- to-be-closed is 3th state variable in the loop
431 for i = 1, 1000 do 431 for i = 1, 1000 do
432 local n, v = debug.getlocal(lv, i) 432 local n, v = debug.getlocal(lv, i)
433 if n == "(for state)" then 433 if n == "(for state)" then
434 stvar = stvar + 1 434 stvar = stvar + 1
435 if stvar == 4 then return v end 435 if stvar == 3 then return v end
436 end 436 end
437 end 437 end
438 end 438 end
diff --git a/testes/main.lua b/testes/main.lua
index f59badcf..40cbe548 100644
--- a/testes/main.lua
+++ b/testes/main.lua
@@ -134,7 +134,7 @@ RUN('env LUA_INIT= LUA_PATH=x lua %s > %s', prog, out)
134checkout("x\n") 134checkout("x\n")
135 135
136-- test LUA_PATH_version 136-- test LUA_PATH_version
137RUN('env LUA_INIT= LUA_PATH_5_4=y LUA_PATH=x lua %s > %s', prog, out) 137RUN('env LUA_INIT= LUA_PATH_5_5=y LUA_PATH=x lua %s > %s', prog, out)
138checkout("y\n") 138checkout("y\n")
139 139
140-- test LUA_CPATH 140-- test LUA_CPATH
@@ -143,7 +143,7 @@ RUN('env LUA_INIT= LUA_CPATH=xuxu lua %s > %s', prog, out)
143checkout("xuxu\n") 143checkout("xuxu\n")
144 144
145-- test LUA_CPATH_version 145-- test LUA_CPATH_version
146RUN('env LUA_INIT= LUA_CPATH_5_4=yacc LUA_CPATH=x lua %s > %s', prog, out) 146RUN('env LUA_INIT= LUA_CPATH_5_5=yacc LUA_CPATH=x lua %s > %s', prog, out)
147checkout("yacc\n") 147checkout("yacc\n")
148 148
149-- test LUA_INIT (and its access to 'arg' table) 149-- test LUA_INIT (and its access to 'arg' table)
@@ -153,7 +153,7 @@ checkout("3.2\n")
153 153
154-- test LUA_INIT_version 154-- test LUA_INIT_version
155prepfile("print(X)") 155prepfile("print(X)")
156RUN('env LUA_INIT_5_4="X=10" LUA_INIT="X=3" lua %s > %s', prog, out) 156RUN('env LUA_INIT_5_5="X=10" LUA_INIT="X=3" lua %s > %s', prog, out)
157checkout("10\n") 157checkout("10\n")
158 158
159-- test LUA_INIT for files 159-- test LUA_INIT for files
diff --git a/testes/nextvar.lua b/testes/nextvar.lua
index 02b7dea2..5d8796f7 100644
--- a/testes/nextvar.lua
+++ b/testes/nextvar.lua
@@ -210,9 +210,9 @@ assert(T.querytab(a) == 64) -- array part has 64 elements
210a[32] = true; a[48] = true; -- binary search will find these ones 210a[32] = true; a[48] = true; -- binary search will find these ones
211a[51] = true -- binary search will miss this one 211a[51] = true -- binary search will miss this one
212assert(#a == 48) -- this will set the limit 212assert(#a == 48) -- this will set the limit
213assert(select(4, T.querytab(a)) == 48) -- this is the limit now 213assert(select(3, T.querytab(a)) == 48) -- this is the limit now
214a[50] = true -- this will set a new limit 214a[50] = true -- this will set a new limit
215assert(select(4, T.querytab(a)) == 50) -- this is the limit now 215assert(select(3, T.querytab(a)) == 50) -- this is the limit now
216-- but the size is larger (and still inside the array part) 216-- but the size is larger (and still inside the array part)
217assert(#a == 51) 217assert(#a == 51)
218 218
@@ -609,10 +609,12 @@ do
609 a = 0; for i=1.0, 0.99999, -1 do a=a+1 end; assert(a==1) 609 a = 0; for i=1.0, 0.99999, -1 do a=a+1 end; assert(a==1)
610end 610end
611 611
612do -- changing the control variable 612do -- attempt to change the control variable
613 local a 613 local st, msg = load "for i = 1, 10 do i = 10 end"
614 a = 0; for i = 1, 10 do a = a + 1; i = "x" end; assert(a == 10) 614 assert(not st and string.find(msg, "assign to const variable 'i'"))
615 a = 0; for i = 10.0, 1, -1 do a = a + 1; i = "x" end; assert(a == 10) 615
616 local st, msg = load "for v, k in pairs{} do v = 10 end"
617 assert(not st and string.find(msg, "assign to const variable 'v'"))
616end 618end
617 619
618-- conversion 620-- conversion