aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/all.lua2
-rw-r--r--testes/api.lua65
-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, 104 insertions, 37 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..181c1d53 100644
--- a/testes/api.lua
+++ b/testes/api.lua
@@ -407,7 +407,7 @@ do
407 concat 3]]) == "hi alo mundo") 407 concat 3]]) == "hi alo mundo")
408 408
409 -- "argerror" without frames 409 -- "argerror" without frames
410 assert(T.checkpanic("loadstring 4") == 410 assert(T.checkpanic("loadstring 4 name bt") ==
411 "bad argument #4 (string expected, got no value)") 411 "bad argument #4 (string expected, got no value)")
412 412
413 413
@@ -420,7 +420,7 @@ do
420 if not _soft then 420 if not _soft then
421 local msg = T.checkpanic[[ 421 local msg = T.checkpanic[[
422 pushstring "function f() f() end" 422 pushstring "function f() f() end"
423 loadstring -1; call 0 0 423 loadstring -1 name t; call 0 0
424 getglobal f; call 0 0 424 getglobal f; call 0 0
425 ]] 425 ]]
426 assert(string.find(msg, "stack overflow")) 426 assert(string.find(msg, "stack overflow"))
@@ -430,7 +430,7 @@ do
430 assert(T.checkpanic([[ 430 assert(T.checkpanic([[
431 pushstring "return {__close = function () Y = 'ho'; end}" 431 pushstring "return {__close = function () Y = 'ho'; end}"
432 newtable 432 newtable
433 loadstring -2 433 loadstring -2 name t
434 call 0 1 434 call 0 1
435 setmetatable -2 435 setmetatable -2
436 toclose -1 436 toclose -1
@@ -458,6 +458,8 @@ if not _soft then
458 print'+' 458 print'+'
459end 459end
460 460
461
462
461local lim = _soft and 500 or 12000 463local lim = _soft and 500 or 12000
462local prog = {"checkstack " .. (lim * 2 + 100) .. "msg", "newtable"} 464local prog = {"checkstack " .. (lim * 2 + 100) .. "msg", "newtable"}
463for i = 1,lim do 465for i = 1,lim do
@@ -481,10 +483,20 @@ for i = 1,lim do assert(t[i] == i*10); t[i] = undef end
481assert(next(t) == nil) 483assert(next(t) == nil)
482prog, g, t = nil 484prog, g, t = nil
483 485
486do -- shrink stack
487 local m1, m2 = 0, collectgarbage"count" * 1024
488 while m1 ~= m2 do -- repeat until stable
489 collectgarbage()
490 m1 = m2
491 m2 = collectgarbage"count" * 1024
492 end
493end
494
495
484-- testing errors 496-- testing errors
485 497
486a = T.testC([[ 498a = T.testC([[
487 loadstring 2; pcall 0 1 0; 499 loadstring 2 name t; pcall 0 1 0;
488 pushvalue 3; insert -2; pcall 1 1 0; 500 pushvalue 3; insert -2; pcall 1 1 0;
489 pcall 0 0 0; 501 pcall 0 0 0;
490 return 1 502 return 1
@@ -498,7 +510,7 @@ local function check3(p, ...)
498 assert(#arg == 3) 510 assert(#arg == 3)
499 assert(string.find(arg[3], p)) 511 assert(string.find(arg[3], p))
500end 512end
501check3(":1:", T.testC("loadstring 2; return *", "x=")) 513check3(":1:", T.testC("loadstring 2 name t; return *", "x="))
502check3("%.", T.testC("loadfile 2; return *", ".")) 514check3("%.", T.testC("loadfile 2; return *", "."))
503check3("xxxx", T.testC("loadfile 2; return *", "xxxx")) 515check3("xxxx", T.testC("loadfile 2; return *", "xxxx"))
504 516
@@ -509,6 +521,35 @@ local function checkerrnopro (code, msg)
509 assert(not stt and string.find(err, msg)) 521 assert(not stt and string.find(err, msg))
510end 522end
511 523
524
525do
526 print("testing load of binaries in fixed buffers")
527 local source = {}
528 local N = 1000
529 -- create a somewhat "large" source
530 for i = 1, N do source[i] = "X = X + 1; " end
531 source = table.concat(source)
532 -- give chunk an explicit name to avoid using source as name
533 source = load(source, "name1")
534 -- dump without debug information
535 source = string.dump(source, true)
536 -- each "X=X+1" generates 4 opcodes with 4 bytes each
537 assert(#source > N * 4 * 4)
538 collectgarbage(); collectgarbage()
539 local m1 = collectgarbage"count" * 1024
540 -- load dump using fixed buffer
541 local code = T.testC([[
542 loadstring 2 name B;
543 return 1
544 ]], source)
545 collectgarbage()
546 local m2 = collectgarbage"count" * 1024
547 -- load used fewer than 300 bytes
548 assert(m2 > m1 and m2 - m1 < 300)
549 X = 0; code(); assert(X == N); X = nil
550end
551
552
512if not _soft then 553if not _soft then
513 collectgarbage("stop") -- avoid __gc with full stack 554 collectgarbage("stop") -- avoid __gc with full stack
514 checkerrnopro("pushnum 3; call 0 0", "attempt to call") 555 checkerrnopro("pushnum 3; call 0 0", "attempt to call")
@@ -1046,10 +1087,12 @@ assert(a == nil and c == 2) -- 2 == run-time error
1046a, b, c = T.doremote(L1, "return a+") 1087a, b, c = T.doremote(L1, "return a+")
1047assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error 1088assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error
1048 1089
1049T.loadlib(L1) 1090T.loadlib(L1, 2) -- load only 'package'
1050a, b, c = T.doremote(L1, [[ 1091a, b, c = T.doremote(L1, [[
1051 string = require'string' 1092 string = require'string'
1052 a = require'_G'; assert(a == _G and require("_G") == a) 1093 local initialG = _G -- not loaded yet
1094 local a = require'_G'; assert(a == _G and require("_G") == a)
1095 assert(initialG == nil and io == nil) -- now we have 'assert'
1053 io = require'io'; assert(type(io.read) == "function") 1096 io = require'io'; assert(type(io.read) == "function")
1054 assert(require("io") == io) 1097 assert(require("io") == io)
1055 a = require'table'; assert(type(a.insert) == "function") 1098 a = require'table'; assert(type(a.insert) == "function")
@@ -1063,7 +1106,7 @@ T.closestate(L1);
1063 1106
1064 1107
1065L1 = T.newstate() 1108L1 = T.newstate()
1066T.loadlib(L1) 1109T.loadlib(L1, 0)
1067T.doremote(L1, "a = {}") 1110T.doremote(L1, "a = {}")
1068T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1; 1111T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1;
1069 settable -3]]) 1112 settable -3]])
@@ -1446,10 +1489,10 @@ end
1446 1489
1447do -- garbage collection with no extra memory 1490do -- garbage collection with no extra memory
1448 local L = T.newstate() 1491 local L = T.newstate()
1449 T.loadlib(L) 1492 T.loadlib(L, 1 | 2) -- load _G and 'package'
1450 local res = (T.doremote(L, [[ 1493 local res = (T.doremote(L, [[
1451 _ENV = require"_G" 1494 _ENV = _G
1452 local T = require"T" 1495 assert(string == nil)
1453 local a = {} 1496 local a = {}
1454 for i = 1, 1000 do a[i] = 'i' .. i end -- grow string table 1497 for i = 1, 1000 do a[i] = 'i' .. i end -- grow string table
1455 local stsize, stuse = T.querystr() 1498 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 1476006e..2582406f 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 11b14b44..dde72a74 100644
--- a/testes/main.lua
+++ b/testes/main.lua
@@ -137,7 +137,7 @@ RUN('env LUA_INIT= LUA_PATH=x lua %s > %s', prog, out)
137checkout("x\n") 137checkout("x\n")
138 138
139-- test LUA_PATH_version 139-- test LUA_PATH_version
140RUN('env LUA_INIT= LUA_PATH_5_4=y LUA_PATH=x lua %s > %s', prog, out) 140RUN('env LUA_INIT= LUA_PATH_5_5=y LUA_PATH=x lua %s > %s', prog, out)
141checkout("y\n") 141checkout("y\n")
142 142
143-- test LUA_CPATH 143-- test LUA_CPATH
@@ -146,7 +146,7 @@ RUN('env LUA_INIT= LUA_CPATH=xuxu lua %s > %s', prog, out)
146checkout("xuxu\n") 146checkout("xuxu\n")
147 147
148-- test LUA_CPATH_version 148-- test LUA_CPATH_version
149RUN('env LUA_INIT= LUA_CPATH_5_4=yacc LUA_CPATH=x lua %s > %s', prog, out) 149RUN('env LUA_INIT= LUA_CPATH_5_5=yacc LUA_CPATH=x lua %s > %s', prog, out)
150checkout("yacc\n") 150checkout("yacc\n")
151 151
152-- test LUA_INIT (and its access to 'arg' table) 152-- test LUA_INIT (and its access to 'arg' table)
@@ -156,7 +156,7 @@ checkout("3.2\n")
156 156
157-- test LUA_INIT_version 157-- test LUA_INIT_version
158prepfile("print(X)") 158prepfile("print(X)")
159RUN('env LUA_INIT_5_4="X=10" LUA_INIT="X=3" lua %s > %s', prog, out) 159RUN('env LUA_INIT_5_5="X=10" LUA_INIT="X=3" lua %s > %s', prog, out)
160checkout("10\n") 160checkout("10\n")
161 161
162-- test LUA_INIT for files 162-- 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