mirror of https://github.com/rusefi/lua.git
Small improvements in tests
This commit is contained in:
parent
934e77a286
commit
c197885cb0
|
@ -928,7 +928,7 @@ do
|
||||||
local cl = countlines(rest)
|
local cl = countlines(rest)
|
||||||
-- at most 10 lines in first part, 11 in second, plus '...'
|
-- at most 10 lines in first part, 11 in second, plus '...'
|
||||||
assert(cl <= 10 + 11 + 1)
|
assert(cl <= 10 + 11 + 1)
|
||||||
local brk = string.find(rest, "%.%.%.")
|
local brk = string.find(rest, "%.%.%.\t%(skip")
|
||||||
if brk then -- does message have '...'?
|
if brk then -- does message have '...'?
|
||||||
local rest1 = string.sub(rest, 1, brk)
|
local rest1 = string.sub(rest, 1, brk)
|
||||||
local rest2 = string.sub(rest, brk, #rest)
|
local rest2 = string.sub(rest, brk, #rest)
|
||||||
|
|
|
@ -27,17 +27,19 @@ do
|
||||||
end
|
end
|
||||||
print("progname: "..progname)
|
print("progname: "..progname)
|
||||||
|
|
||||||
local prepfile = function (s, p)
|
|
||||||
p = p or prog
|
local prepfile = function (s, mod, p)
|
||||||
io.output(p)
|
mod = mod and "wb" or "w" -- mod true means binary files
|
||||||
io.write(s)
|
p = p or prog -- file to write the program
|
||||||
assert(io.close())
|
local f = io.open(p, mod)
|
||||||
|
f:write(s)
|
||||||
|
assert(f:close())
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getoutput ()
|
local function getoutput ()
|
||||||
io.input(out)
|
local f = io.open(out)
|
||||||
local t = io.read("a")
|
local t = f:read("a")
|
||||||
io.input():close()
|
f:close()
|
||||||
assert(os.remove(out))
|
assert(os.remove(out))
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
@ -65,10 +67,11 @@ local function RUN (p, ...)
|
||||||
assert(os.execute(s))
|
assert(os.execute(s))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function NoRun (msg, p, ...)
|
local function NoRun (msg, p, ...)
|
||||||
p = string.gsub(p, "lua", '"'..progname..'"', 1)
|
p = string.gsub(p, "lua", '"'..progname..'"', 1)
|
||||||
local s = string.format(p, ...)
|
local s = string.format(p, ...)
|
||||||
s = string.format("%s 2> %s", s, out) -- will send error to 'out'
|
s = string.format("%s >%s 2>&1", s, out) -- send output and error to 'out'
|
||||||
assert(not os.execute(s))
|
assert(not os.execute(s))
|
||||||
assert(string.find(getoutput(), msg, 1, true)) -- check error message
|
assert(string.find(getoutput(), msg, 1, true)) -- check error message
|
||||||
end
|
end
|
||||||
|
@ -108,17 +111,17 @@ RUN('lua %s > %s', prog, out)
|
||||||
checkout("3\n")
|
checkout("3\n")
|
||||||
|
|
||||||
-- bad BOMs
|
-- bad BOMs
|
||||||
prepfile("\xEF")
|
prepfile("\xEF", true)
|
||||||
NoRun("unexpected symbol", 'lua %s > %s', prog, out)
|
NoRun("unexpected symbol", 'lua %s', prog)
|
||||||
|
|
||||||
prepfile("\xEF\xBB")
|
prepfile("\xEF\xBB", true)
|
||||||
NoRun("unexpected symbol", 'lua %s > %s', prog, out)
|
NoRun("unexpected symbol", 'lua %s', prog)
|
||||||
|
|
||||||
prepfile("\xEFprint(3)")
|
prepfile("\xEFprint(3)", true)
|
||||||
NoRun("unexpected symbol", 'lua %s > %s', prog, out)
|
NoRun("unexpected symbol", 'lua %s', prog)
|
||||||
|
|
||||||
prepfile("\xEF\xBBprint(3)")
|
prepfile("\xEF\xBBprint(3)", true)
|
||||||
NoRun("unexpected symbol", 'lua %s > %s', prog, out)
|
NoRun("unexpected symbol", 'lua %s', prog)
|
||||||
|
|
||||||
|
|
||||||
-- test option '-'
|
-- test option '-'
|
||||||
|
@ -213,7 +216,7 @@ convert("a;b;;c")
|
||||||
|
|
||||||
-- test -l over multiple libraries
|
-- test -l over multiple libraries
|
||||||
prepfile("print(1); a=2; return {x=15}")
|
prepfile("print(1); a=2; return {x=15}")
|
||||||
prepfile(("print(a); print(_G['%s'].x)"):format(prog), otherprog)
|
prepfile(("print(a); print(_G['%s'].x)"):format(prog), false, otherprog)
|
||||||
RUN('env LUA_PATH="?;;" lua -l %s -l%s -lstring -l io %s > %s', prog, otherprog, otherprog, out)
|
RUN('env LUA_PATH="?;;" lua -l %s -l%s -lstring -l io %s > %s', prog, otherprog, otherprog, out)
|
||||||
checkout("1\n2\n15\n2\n15\n")
|
checkout("1\n2\n15\n2\n15\n")
|
||||||
|
|
||||||
|
@ -237,7 +240,7 @@ RUN('lua "-e " -- %s a b c', prog) -- "-e " runs an empty command
|
||||||
|
|
||||||
-- test 'arg' availability in libraries
|
-- test 'arg' availability in libraries
|
||||||
prepfile"assert(arg)"
|
prepfile"assert(arg)"
|
||||||
prepfile("assert(arg)", otherprog)
|
prepfile("assert(arg)", false, otherprog)
|
||||||
RUN('env LUA_PATH="?;;" lua -l%s - < %s', prog, otherprog)
|
RUN('env LUA_PATH="?;;" lua -l%s - < %s', prog, otherprog)
|
||||||
|
|
||||||
-- test messing up the 'arg' table
|
-- test messing up the 'arg' table
|
||||||
|
@ -413,7 +416,7 @@ prepfile[[#comment in 1st line without \n at the end]]
|
||||||
RUN('lua %s', prog)
|
RUN('lua %s', prog)
|
||||||
|
|
||||||
-- first-line comment with binary file
|
-- first-line comment with binary file
|
||||||
prepfile("#comment\n" .. string.dump(load("print(3)")))
|
prepfile("#comment\n" .. string.dump(load("print(3)")), true)
|
||||||
RUN('lua %s > %s', prog, out)
|
RUN('lua %s > %s', prog, out)
|
||||||
checkout('3\n')
|
checkout('3\n')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue