aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-15 10:20:13 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-15 10:20:13 -0300
commitc197885cb00b85251c35cffdc4057efaee2d7a88 (patch)
treec26a9a0be4ad37e85c51e59ece17b62809c7deb0
parent934e77a286aeb97ca02badf56956ccc78217e9d0 (diff)
downloadlua-c197885cb00b85251c35cffdc4057efaee2d7a88.tar.gz
lua-c197885cb00b85251c35cffdc4057efaee2d7a88.tar.bz2
lua-c197885cb00b85251c35cffdc4057efaee2d7a88.zip
Small improvements in tests
-rw-r--r--testes/db.lua2
-rw-r--r--testes/main.lua43
2 files changed, 24 insertions, 21 deletions
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/main.lua b/testes/main.lua
index f59badcf..3fa94e97 100644
--- a/testes/main.lua
+++ b/testes/main.lua
@@ -27,17 +27,19 @@ do
27end 27end
28print("progname: "..progname) 28print("progname: "..progname)
29 29
30local prepfile = function (s, p) 30
31 p = p or prog 31local 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())
35end 37end
36 38
37local function getoutput () 39local 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
43end 45end
@@ -65,10 +67,11 @@ local function RUN (p, ...)
65 assert(os.execute(s)) 67 assert(os.execute(s))
66end 68end
67 69
70
68local function NoRun (msg, p, ...) 71local 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
74end 77end
@@ -108,17 +111,17 @@ RUN('lua %s > %s', prog, out)
108checkout("3\n") 111checkout("3\n")
109 112
110-- bad BOMs 113-- bad BOMs
111prepfile("\xEF") 114prepfile("\xEF", true)
112NoRun("unexpected symbol", 'lua %s > %s', prog, out) 115NoRun("unexpected symbol", 'lua %s', prog)
113 116
114prepfile("\xEF\xBB") 117prepfile("\xEF\xBB", true)
115NoRun("unexpected symbol", 'lua %s > %s', prog, out) 118NoRun("unexpected symbol", 'lua %s', prog)
116 119
117prepfile("\xEFprint(3)") 120prepfile("\xEFprint(3)", true)
118NoRun("unexpected symbol", 'lua %s > %s', prog, out) 121NoRun("unexpected symbol", 'lua %s', prog)
119 122
120prepfile("\xEF\xBBprint(3)") 123prepfile("\xEF\xBBprint(3)", true)
121NoRun("unexpected symbol", 'lua %s > %s', prog, out) 124NoRun("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
215prepfile("print(1); a=2; return {x=15}") 218prepfile("print(1); a=2; return {x=15}")
216prepfile(("print(a); print(_G['%s'].x)"):format(prog), otherprog) 219prepfile(("print(a); print(_G['%s'].x)"):format(prog), false, otherprog)
217RUN('env LUA_PATH="?;;" lua -l %s -l%s -lstring -l io %s > %s', prog, otherprog, otherprog, out) 220RUN('env LUA_PATH="?;;" lua -l %s -l%s -lstring -l io %s > %s', prog, otherprog, otherprog, out)
218checkout("1\n2\n15\n2\n15\n") 221checkout("1\n2\n15\n2\n15\n")
219 222
@@ -237,7 +240,7 @@ RUN('lua "-e " -- %s a b c', prog) -- "-e " runs an empty command
237 240
238-- test 'arg' availability in libraries 241-- test 'arg' availability in libraries
239prepfile"assert(arg)" 242prepfile"assert(arg)"
240prepfile("assert(arg)", otherprog) 243prepfile("assert(arg)", false, otherprog)
241RUN('env LUA_PATH="?;;" lua -l%s - < %s', prog, otherprog) 244RUN('env LUA_PATH="?;;" lua -l%s - < %s', prog, otherprog)
242 245
243-- test messing up the 'arg' table 246-- test messing up the 'arg' table
@@ -413,7 +416,7 @@ prepfile[[#comment in 1st line without \n at the end]]
413RUN('lua %s', prog) 416RUN('lua %s', prog)
414 417
415-- first-line comment with binary file 418-- first-line comment with binary file
416prepfile("#comment\n" .. string.dump(load("print(3)"))) 419prepfile("#comment\n" .. string.dump(load("print(3)")), true)
417RUN('lua %s > %s', prog, out) 420RUN('lua %s > %s', prog, out)
418checkout('3\n') 421checkout('3\n')
419 422