diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/calls.lua | 14 | ||||
-rw-r--r-- | testes/db.lua | 2 | ||||
-rw-r--r-- | testes/errors.lua | 8 | ||||
-rw-r--r-- | testes/main.lua | 50 |
4 files changed, 53 insertions, 21 deletions
diff --git a/testes/calls.lua b/testes/calls.lua index 9a5eed0b..559ca935 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
@@ -342,6 +342,20 @@ do -- another bug (in 5.4.0) | |||
342 | end | 342 | end |
343 | 343 | ||
344 | 344 | ||
345 | do -- another bug (since 5.2) | ||
346 | -- corrupted binary dump: list of upvalue names is larger than number | ||
347 | -- of upvalues, overflowing the array of upvalues. | ||
348 | local code = | ||
349 | "\x1b\x4c\x75\x61\x55\x00\x19\x93\x0d\x0a\x1a\x0a\x04\x08\x08\x78\x56\z | ||
350 | \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x28\x77\x40\x00\x86\x40\z | ||
351 | \x74\x65\x6d\x70\x81\x81\x01\x00\x02\x82\x48\x00\x02\x00\xc7\x00\x01\z | ||
352 | \x00\x80\x80\x80\x82\x00\x00\x80\x81\x82\x78\x80\x82\x81\x86\x40\x74\z | ||
353 | \x65\x6d\x70" | ||
354 | |||
355 | assert(load(code)) -- segfaults in previous versions | ||
356 | end | ||
357 | |||
358 | |||
345 | x = string.dump(load("x = 1; return x")) | 359 | x = string.dump(load("x = 1; return x")) |
346 | a = assert(load(read1(x), nil, "b")) | 360 | a = assert(load(read1(x), nil, "b")) |
347 | assert(a() == 1 and _G.x == 1) | 361 | assert(a() == 1 and _G.x == 1) |
diff --git a/testes/db.lua b/testes/db.lua index 02b96aca..67b58934 100644 --- a/testes/db.lua +++ b/testes/db.lua | |||
@@ -928,7 +928,7 @@ do | |||
928 | local cl = countlines(rest) | 928 | local cl = countlines(rest) |
929 | -- at most 10 lines in first part, 11 in second, plus '...' | 929 | -- at most 10 lines in first part, 11 in second, plus '...' |
930 | assert(cl <= 10 + 11 + 1) | 930 | assert(cl <= 10 + 11 + 1) |
931 | local brk = string.find(rest, "%.%.%.") | 931 | local brk = string.find(rest, "%.%.%.\t%(skip") |
932 | if brk then -- does message have '...'? | 932 | if brk then -- does message have '...'? |
933 | local rest1 = string.sub(rest, 1, brk) | 933 | local rest1 = string.sub(rest, 1, brk) |
934 | local rest2 = string.sub(rest, brk, #rest) | 934 | local rest2 = string.sub(rest, brk, #rest) |
diff --git a/testes/errors.lua b/testes/errors.lua index cf0ab526..bf6f389d 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
@@ -444,6 +444,14 @@ if not b then | |||
444 | end | 444 | end |
445 | end]], 5) | 445 | end]], 5) |
446 | 446 | ||
447 | |||
448 | -- bug in 5.4.0 | ||
449 | lineerror([[ | ||
450 | local a = 0 | ||
451 | local b = 1 | ||
452 | local c = b % a | ||
453 | ]], 3) | ||
454 | |||
447 | do | 455 | do |
448 | -- Force a negative estimate for base line. Error in instruction 2 | 456 | -- Force a negative estimate for base line. Error in instruction 2 |
449 | -- (after VARARGPREP, GETGLOBAL), with first absolute line information | 457 | -- (after VARARGPREP, GETGLOBAL), with first absolute line information |
diff --git a/testes/main.lua b/testes/main.lua index 40cbe548..dde72a74 100644 --- a/testes/main.lua +++ b/testes/main.lua | |||
@@ -27,17 +27,19 @@ do | |||
27 | end | 27 | end |
28 | print("progname: "..progname) | 28 | print("progname: "..progname) |
29 | 29 | ||
30 | local prepfile = function (s, p) | 30 | |
31 | p = p or prog | 31 | local prepfile = function (s, mod, p) |
32 | io.output(p) | 32 | mod = mod and "wb" or "w" -- mod true means binary files |
33 | io.write(s) | 33 | p = p or prog -- file to write the program |
34 | assert(io.close()) | 34 | local f = io.open(p, mod) |
35 | f:write(s) | ||
36 | assert(f:close()) | ||
35 | end | 37 | end |
36 | 38 | ||
37 | local function getoutput () | 39 | local function getoutput () |
38 | io.input(out) | 40 | local f = io.open(out) |
39 | local t = io.read("a") | 41 | local t = f:read("a") |
40 | io.input():close() | 42 | f:close() |
41 | assert(os.remove(out)) | 43 | assert(os.remove(out)) |
42 | return t | 44 | return t |
43 | end | 45 | end |
@@ -65,10 +67,11 @@ local function RUN (p, ...) | |||
65 | assert(os.execute(s)) | 67 | assert(os.execute(s)) |
66 | end | 68 | end |
67 | 69 | ||
70 | |||
68 | local function NoRun (msg, p, ...) | 71 | local function NoRun (msg, p, ...) |
69 | p = string.gsub(p, "lua", '"'..progname..'"', 1) | 72 | p = string.gsub(p, "lua", '"'..progname..'"', 1) |
70 | local s = string.format(p, ...) | 73 | local s = string.format(p, ...) |
71 | s = string.format("%s 2> %s", s, out) -- will send error to 'out' | 74 | s = string.format("%s >%s 2>&1", s, out) -- send output and error to 'out' |
72 | assert(not os.execute(s)) | 75 | assert(not os.execute(s)) |
73 | assert(string.find(getoutput(), msg, 1, true)) -- check error message | 76 | assert(string.find(getoutput(), msg, 1, true)) -- check error message |
74 | end | 77 | end |
@@ -108,17 +111,17 @@ RUN('lua %s > %s', prog, out) | |||
108 | checkout("3\n") | 111 | checkout("3\n") |
109 | 112 | ||
110 | -- bad BOMs | 113 | -- bad BOMs |
111 | prepfile("\xEF") | 114 | prepfile("\xEF", true) |
112 | NoRun("unexpected symbol", 'lua %s > %s', prog, out) | 115 | NoRun("unexpected symbol", 'lua %s', prog) |
113 | 116 | ||
114 | prepfile("\xEF\xBB") | 117 | prepfile("\xEF\xBB", true) |
115 | NoRun("unexpected symbol", 'lua %s > %s', prog, out) | 118 | NoRun("unexpected symbol", 'lua %s', prog) |
116 | 119 | ||
117 | prepfile("\xEFprint(3)") | 120 | prepfile("\xEFprint(3)", true) |
118 | NoRun("unexpected symbol", 'lua %s > %s', prog, out) | 121 | NoRun("unexpected symbol", 'lua %s', prog) |
119 | 122 | ||
120 | prepfile("\xEF\xBBprint(3)") | 123 | prepfile("\xEF\xBBprint(3)", true) |
121 | NoRun("unexpected symbol", 'lua %s > %s', prog, out) | 124 | NoRun("unexpected symbol", 'lua %s', prog) |
122 | 125 | ||
123 | 126 | ||
124 | -- test option '-' | 127 | -- test option '-' |
@@ -213,7 +216,7 @@ convert("a;b;;c") | |||
213 | 216 | ||
214 | -- test -l over multiple libraries | 217 | -- test -l over multiple libraries |
215 | prepfile("print(1); a=2; return {x=15}") | 218 | prepfile("print(1); a=2; return {x=15}") |
216 | prepfile(("print(a); print(_G['%s'].x)"):format(prog), otherprog) | 219 | prepfile(("print(a); print(_G['%s'].x)"):format(prog), false, otherprog) |
217 | RUN('env LUA_PATH="?;;" lua -l %s -l%s -lstring -l io %s > %s', prog, otherprog, otherprog, out) | 220 | RUN('env LUA_PATH="?;;" lua -l %s -l%s -lstring -l io %s > %s', prog, otherprog, otherprog, out) |
218 | checkout("1\n2\n15\n2\n15\n") | 221 | checkout("1\n2\n15\n2\n15\n") |
219 | 222 | ||
@@ -222,6 +225,13 @@ prepfile("print(str.upper'alo alo', m.max(10, 20))") | |||
222 | RUN("lua -l 'str=string' '-lm=math' -e 'print(m.sin(0))' %s > %s", prog, out) | 225 | RUN("lua -l 'str=string' '-lm=math' -e 'print(m.sin(0))' %s > %s", prog, out) |
223 | checkout("0.0\nALO ALO\t20\n") | 226 | checkout("0.0\nALO ALO\t20\n") |
224 | 227 | ||
228 | |||
229 | -- test module names with version sufix ("libs/lib2-v2") | ||
230 | RUN("env LUA_CPATH='./libs/?.so' lua -l lib2-v2 -e 'print(lib2.id())' > %s", | ||
231 | out) | ||
232 | checkout("true\n") | ||
233 | |||
234 | |||
225 | -- test 'arg' table | 235 | -- test 'arg' table |
226 | local a = [[ | 236 | local a = [[ |
227 | assert(#arg == 3 and arg[1] == 'a' and | 237 | assert(#arg == 3 and arg[1] == 'a' and |
@@ -237,7 +247,7 @@ RUN('lua "-e " -- %s a b c', prog) -- "-e " runs an empty command | |||
237 | 247 | ||
238 | -- test 'arg' availability in libraries | 248 | -- test 'arg' availability in libraries |
239 | prepfile"assert(arg)" | 249 | prepfile"assert(arg)" |
240 | prepfile("assert(arg)", otherprog) | 250 | prepfile("assert(arg)", false, otherprog) |
241 | RUN('env LUA_PATH="?;;" lua -l%s - < %s', prog, otherprog) | 251 | RUN('env LUA_PATH="?;;" lua -l%s - < %s', prog, otherprog) |
242 | 252 | ||
243 | -- test messing up the 'arg' table | 253 | -- test messing up the 'arg' table |
@@ -413,7 +423,7 @@ prepfile[[#comment in 1st line without \n at the end]] | |||
413 | RUN('lua %s', prog) | 423 | RUN('lua %s', prog) |
414 | 424 | ||
415 | -- first-line comment with binary file | 425 | -- first-line comment with binary file |
416 | prepfile("#comment\n" .. string.dump(load("print(3)"))) | 426 | prepfile("#comment\n" .. string.dump(load("print(3)")), true) |
417 | RUN('lua %s > %s', prog, out) | 427 | RUN('lua %s > %s', prog, out) |
418 | checkout('3\n') | 428 | checkout('3\n') |
419 | 429 | ||