diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/all.lua | 2 | ||||
-rw-r--r-- | testes/api.lua | 14 | ||||
-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, 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 | ||
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..dece98f5 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
@@ -1046,10 +1046,12 @@ assert(a == nil and c == 2) -- 2 == run-time error | |||
1046 | a, b, c = T.doremote(L1, "return a+") | 1046 | a, b, c = T.doremote(L1, "return a+") |
1047 | assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error | 1047 | assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error |
1048 | 1048 | ||
1049 | T.loadlib(L1) | 1049 | T.loadlib(L1, 2) -- load only 'package' |
1050 | a, b, c = T.doremote(L1, [[ | 1050 | a, 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 | ||
1065 | L1 = T.newstate() | 1067 | L1 = T.newstate() |
1066 | T.loadlib(L1) | 1068 | T.loadlib(L1, 0) |
1067 | T.doremote(L1, "a = {}") | 1069 | T.doremote(L1, "a = {}") |
1068 | T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1; | 1070 | T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1; |
1069 | settable -3]]) | 1071 | settable -3]]) |
@@ -1446,10 +1448,10 @@ end | |||
1446 | 1448 | ||
1447 | do -- garbage collection with no extra memory | 1449 | do -- 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 | |||
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 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) | |||
134 | checkout("x\n") | 134 | checkout("x\n") |
135 | 135 | ||
136 | -- test LUA_PATH_version | 136 | -- test LUA_PATH_version |
137 | RUN('env LUA_INIT= LUA_PATH_5_4=y LUA_PATH=x lua %s > %s', prog, out) | 137 | RUN('env LUA_INIT= LUA_PATH_5_5=y LUA_PATH=x lua %s > %s', prog, out) |
138 | checkout("y\n") | 138 | checkout("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) | |||
143 | checkout("xuxu\n") | 143 | checkout("xuxu\n") |
144 | 144 | ||
145 | -- test LUA_CPATH_version | 145 | -- test LUA_CPATH_version |
146 | RUN('env LUA_INIT= LUA_CPATH_5_4=yacc LUA_CPATH=x lua %s > %s', prog, out) | 146 | RUN('env LUA_INIT= LUA_CPATH_5_5=yacc LUA_CPATH=x lua %s > %s', prog, out) |
147 | checkout("yacc\n") | 147 | checkout("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 |
155 | prepfile("print(X)") | 155 | prepfile("print(X)") |
156 | RUN('env LUA_INIT_5_4="X=10" LUA_INIT="X=3" lua %s > %s', prog, out) | 156 | RUN('env LUA_INIT_5_5="X=10" LUA_INIT="X=3" lua %s > %s', prog, out) |
157 | checkout("10\n") | 157 | checkout("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 | |||
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 |