diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/all.lua | 2 | ||||
-rw-r--r-- | testes/api.lua | 65 | ||||
-rw-r--r-- | testes/attrib.lua | 2 | ||||
-rw-r--r-- | testes/calls.lua | 27 | ||||
-rw-r--r-- | testes/closure.lua | 19 | ||||
-rw-r--r-- | testes/coroutine.lua | 2 | ||||
-rw-r--r-- | testes/files.lua | 4 | ||||
-rw-r--r-- | testes/main.lua | 6 | ||||
-rw-r--r-- | testes/nextvar.lua | 14 |
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 | ||
6 | local version = "Lua 5.4" | 6 | local version = "Lua 5.5" |
7 | if _VERSION ~= version then | 7 | if _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'+' |
459 | end | 459 | end |
460 | 460 | ||
461 | |||
462 | |||
461 | local lim = _soft and 500 or 12000 | 463 | local lim = _soft and 500 or 12000 |
462 | local prog = {"checkstack " .. (lim * 2 + 100) .. "msg", "newtable"} | 464 | local prog = {"checkstack " .. (lim * 2 + 100) .. "msg", "newtable"} |
463 | for i = 1,lim do | 465 | for i = 1,lim do |
@@ -481,10 +483,20 @@ for i = 1,lim do assert(t[i] == i*10); t[i] = undef end | |||
481 | assert(next(t) == nil) | 483 | assert(next(t) == nil) |
482 | prog, g, t = nil | 484 | prog, g, t = nil |
483 | 485 | ||
486 | do -- 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 | ||
493 | end | ||
494 | |||
495 | |||
484 | -- testing errors | 496 | -- testing errors |
485 | 497 | ||
486 | a = T.testC([[ | 498 | a = 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)) |
500 | end | 512 | end |
501 | check3(":1:", T.testC("loadstring 2; return *", "x=")) | 513 | check3(":1:", T.testC("loadstring 2 name t; return *", "x=")) |
502 | check3("%.", T.testC("loadfile 2; return *", ".")) | 514 | check3("%.", T.testC("loadfile 2; return *", ".")) |
503 | check3("xxxx", T.testC("loadfile 2; return *", "xxxx")) | 515 | check3("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)) |
510 | end | 522 | end |
511 | 523 | ||
524 | |||
525 | do | ||
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 | ||
550 | end | ||
551 | |||
552 | |||
512 | if not _soft then | 553 | if 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 | |||
1046 | a, b, c = T.doremote(L1, "return a+") | 1087 | a, b, c = T.doremote(L1, "return a+") |
1047 | assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error | 1088 | assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error |
1048 | 1089 | ||
1049 | T.loadlib(L1) | 1090 | T.loadlib(L1, 2) -- load only 'package' |
1050 | a, b, c = T.doremote(L1, [[ | 1091 | a, 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 | ||
1065 | L1 = T.newstate() | 1108 | L1 = T.newstate() |
1066 | T.loadlib(L1) | 1109 | T.loadlib(L1, 0) |
1067 | T.doremote(L1, "a = {}") | 1110 | T.doremote(L1, "a = {}") |
1068 | T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1; | 1111 | T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1; |
1069 | settable -3]]) | 1112 | settable -3]]) |
@@ -1446,10 +1489,10 @@ end | |||
1446 | 1489 | ||
1447 | do -- garbage collection with no extra memory | 1490 | do -- 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 | |||
236 | local fname = "file_does_not_exist2" | 236 | local fname = "file_does_not_exist2" |
237 | local m, err = pcall(require, fname) | 237 | local m, err = pcall(require, fname) |
238 | for t in string.gmatch(package.path..";"..package.cpath, "[^;]+") do | 238 | for 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)) |
241 | end | 241 | end |
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") | |||
454 | do | 454 | do |
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 |
494 | end | 494 | end |
495 | 495 | ||
496 | |||
497 | do -- 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 | ||
519 | end | ||
520 | |||
496 | print('OK') | 521 | print('OK') |
497 | return deep | 522 | return 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 |
61 | a = {} | 61 | a = {} |
62 | for i=1,10 do | 62 | for 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 |
65 | end | 65 | end |
66 | assert(a[4] == undef) | 66 | assert(a[4] == undef) |
67 | a[1].set(10) | 67 | assert(a[2]() == 2) |
68 | assert(a[2].get() == 2) | 68 | assert(a[3]() == 3) |
69 | a[2].set('a') | ||
70 | assert(a[3].get() == 3) | ||
71 | assert(a[2].get() == 'a') | ||
72 | 69 | ||
73 | a = {} | 70 | a = {} |
74 | local t = {"a", "b"} | 71 | local t = {"a", "b"} |
75 | for i = 1, #t do | 72 | for 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 |
80 | end | 77 | end |
81 | a[1].set(10, 20) | 78 | a[1].set(10) |
82 | local r,s = a[2].get() | 79 | local r,s = a[2].get() |
83 | assert(r == 2 and s == 'b') | 80 | assert(r == 2 and s == 'b') |
84 | r,s = a[1].get() | 81 | r,s = a[1].get() |
85 | assert(r == 10 and s == 20) | 82 | assert(r == 1 and s == 10) |
86 | a[2].set('a', 'b') | 83 | a[2].set('a') |
87 | r,s = a[2].get() | 84 | r,s = a[2].get() |
88 | assert(r == "a" and s == "b") | 85 | assert(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) | |||
137 | checkout("x\n") | 137 | checkout("x\n") |
138 | 138 | ||
139 | -- test LUA_PATH_version | 139 | -- test LUA_PATH_version |
140 | RUN('env LUA_INIT= LUA_PATH_5_4=y LUA_PATH=x lua %s > %s', prog, out) | 140 | RUN('env LUA_INIT= LUA_PATH_5_5=y LUA_PATH=x lua %s > %s', prog, out) |
141 | checkout("y\n") | 141 | checkout("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) | |||
146 | checkout("xuxu\n") | 146 | checkout("xuxu\n") |
147 | 147 | ||
148 | -- test LUA_CPATH_version | 148 | -- test LUA_CPATH_version |
149 | RUN('env LUA_INIT= LUA_CPATH_5_4=yacc LUA_CPATH=x lua %s > %s', prog, out) | 149 | RUN('env LUA_INIT= LUA_CPATH_5_5=yacc LUA_CPATH=x lua %s > %s', prog, out) |
150 | checkout("yacc\n") | 150 | checkout("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 |
158 | prepfile("print(X)") | 158 | prepfile("print(X)") |
159 | RUN('env LUA_INIT_5_4="X=10" LUA_INIT="X=3" lua %s > %s', prog, out) | 159 | RUN('env LUA_INIT_5_5="X=10" LUA_INIT="X=3" lua %s > %s', prog, out) |
160 | checkout("10\n") | 160 | checkout("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 | |||
210 | a[32] = true; a[48] = true; -- binary search will find these ones | 210 | a[32] = true; a[48] = true; -- binary search will find these ones |
211 | a[51] = true -- binary search will miss this one | 211 | a[51] = true -- binary search will miss this one |
212 | assert(#a == 48) -- this will set the limit | 212 | assert(#a == 48) -- this will set the limit |
213 | assert(select(4, T.querytab(a)) == 48) -- this is the limit now | 213 | assert(select(3, T.querytab(a)) == 48) -- this is the limit now |
214 | a[50] = true -- this will set a new limit | 214 | a[50] = true -- this will set a new limit |
215 | assert(select(4, T.querytab(a)) == 50) -- this is the limit now | 215 | assert(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) |
217 | assert(#a == 51) | 217 | assert(#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) |
610 | end | 610 | end |
611 | 611 | ||
612 | do -- changing the control variable | 612 | do -- 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'")) | ||
616 | end | 618 | end |
617 | 619 | ||
618 | -- conversion | 620 | -- conversion |