Commit a56c9d93 authored by François Perrad's avatar François Perrad
Browse files

avoid conflict when parallel running

(reported by Anton Soldatov)
parent a1cc14d5
Pipeline #84736 passed with stages
in 21 seconds
......@@ -42,59 +42,59 @@ end
plan'no_plan'
diag(lua)
local f = io.open('hello.lua', 'w')
local f = io.open('hello-241.lua', 'w')
f:write([[
print 'Hello World'
]])
f:close()
local cmd = lua .. " hello.lua"
local cmd = lua .. " hello-241.lua"
f = io.popen(cmd)
is(f:read'*l', 'Hello World', "file")
f:close()
cmd = lua .. " -- hello.lua"
cmd = lua .. " -- hello-241.lua"
f = io.popen(cmd)
is(f:read'*l', 'Hello World', "-- file")
f:close()
cmd = lua .. " no_file.lua 2>&1"
cmd = lua .. " no_file-241.lua 2>&1"
f = io.popen(cmd)
like(f:read'*l', "^[^:]+: cannot open no_file.lua", "no file")
like(f:read'*l', "^[^:]+: cannot open no_file%-241%.lua", "no file")
f:close()
if jit then
os.execute(lua .. " -b hello.lua hello.luac")
os.execute(lua .. " -b hello-241.lua hello-241.luac")
else
os.execute(luac .. " -s -o hello.luac hello.lua")
os.execute(luac .. " -s -o hello-241.luac hello-241.lua")
end
cmd = lua .. " hello.luac"
cmd = lua .. " hello-241.luac"
f = io.popen(cmd)
is(f:read'*l', 'Hello World', "bytecode")
f:close()
os.remove('hello.luac') -- clean up
os.remove('hello-241.luac') -- clean up
if not jit then
os.execute(luac .. " -s -o hello2.luac hello.lua hello.lua")
cmd = lua .. " hello2.luac"
os.execute(luac .. " -s -o hello-hello-241.luac hello-241.lua hello-241.lua")
cmd = lua .. " hello-hello-241.luac"
f = io.popen(cmd)
is(f:read'*l', 'Hello World', "combine 1")
is(f:read'*l', 'Hello World', "combine 2")
f:close()
os.remove('hello2.luac') -- clean up
os.remove('hello-hello-241.luac') -- clean up
end
cmd = lua .. " < hello.lua"
cmd = lua .. " < hello-241.lua"
f = io.popen(cmd)
is(f:read'*l', 'Hello World', "redirect")
f:close()
cmd = lua .. " - < hello.lua"
cmd = lua .. " - < hello-241.lua"
f = io.popen(cmd)
is(f:read'*l', 'Hello World', "redirect")
f:close()
cmd = lua .. " -i hello.lua < hello.lua 2>&1"
cmd = lua .. " -i hello-241.lua < hello-241.lua 2>&1"
f = io.popen(cmd)
like(f:read'*l', '^Lua', "-i")
is(f:read'*l', 'Hello World')
......@@ -139,13 +139,13 @@ else
end
f:close()
cmd = lua .. [[ -e"a=1" -e "print(a)" hello.lua]]
cmd = lua .. [[ -e"a=1" -e "print(a)" hello-241.lua]]
f = io.popen(cmd)
is(f:read'*l', '1', "-e & script")
is(f:read'*l', 'Hello World')
f:close()
cmd = lua .. [[ -e"a=1" -i < hello.lua 2>&1]]
cmd = lua .. [[ -e"a=1" -i < hello-241.lua 2>&1]]
f = io.popen(cmd)
like(f:read'*l', '^Lua', "-e & -i")
f:close()
......@@ -168,7 +168,7 @@ f = io.popen(cmd)
like(f:read'*l', '^Lua', "-v")
f:close()
cmd = lua .. [[ -v hello.lua 2>&1]]
cmd = lua .. [[ -v hello-241.lua 2>&1]]
f = io.popen(cmd)
like(f:read'*l', '^Lua', "-v & script")
is(f:read'*l', 'Hello World')
......@@ -180,7 +180,7 @@ like(f:read'*l', '^Lua', "-v --")
f:close()
if has_opt_E then
cmd = lua .. [[ -E hello.lua 2>&1]]
cmd = lua .. [[ -E hello-241.lua 2>&1]]
f = io.popen(cmd)
is(f:read'*l', 'Hello World', "-E")
f:close()
......@@ -219,12 +219,12 @@ f = io.popen(cmd)
isnt(f:read'*l', nil, "-l lpeg")
f:close()
cmd = lua .. [[ -l no_lib hello.lua 2>&1]]
cmd = lua .. [[ -l no_lib hello-241.lua 2>&1]]
f = io.popen(cmd)
like(f:read'*l', "^[^:]+: module 'no_lib' not found:", "-l no lib")
f:close()
os.remove('hello.lua') -- clean up
os.remove('hello-241.lua') -- clean up
done_testing()
-- Local Variables:
......
......@@ -64,7 +64,7 @@ local size_n = string.char(string.packsize and string.packsize'n' or 0) -- lua_N
local sizes = size_i .. size_T .. size_I .. size_j .. size_n
do -- hello.lua
local f = io.open('hello.lua', 'w')
local f = io.open('hello-242.lua', 'w')
f:write([[
print 'Hello World'
]])
......@@ -101,24 +101,24 @@ do -- luac --u
f:close()
end
do -- luac -p hello.lua
local cmd = luac .. [[ -p hello.lua 2>&1]]
do -- luac -p hello-242.lua
local cmd = luac .. [[ -p hello-242.lua 2>&1]]
local f = io.popen(cmd)
is(f:read'*l', nil)
f:close()
end
do -- luac -p - < hello.lua
local cmd = luac .. [[ -p - < hello.lua 2>&1]]
do -- luac -p - < hello-242.lua
local cmd = luac .. [[ -p - < hello-242.lua 2>&1]]
local f = io.popen(cmd)
is(f:read'*l', nil)
f:close()
end
do -- luac -p no_file.lua
local cmd = luac .. [[ -p no_file.lua 2>&1]]
do -- luac -p no_file-242.lua
local cmd = luac .. [[ -p no_file-242.lua 2>&1]]
local f = io.popen(cmd)
like(f:read'*l', "^[^:]+: cannot open no_file.lua", "no file")
like(f:read'*l', "^[^:]+: cannot open no_file%-242%.lua", "no file")
f:close()
end
......@@ -129,8 +129,8 @@ do -- luac -o
f:close()
end
do -- luac -v -l -l hello.lua
local cmd = luac .. [[ -v -l -l hello.lua]]
do -- luac -v -l -l hello-242.lua
local cmd = luac .. [[ -v -l -l hello-242.lua]]
local f = io.popen(cmd)
like(f:read'*l', '^Lua', "-v -l -l")
is(f:read'*l', '')
......@@ -138,7 +138,7 @@ do -- luac -v -l -l hello.lua
f:close()
end
os.remove('hello.lua') -- clean up
os.remove('hello-242.lua') -- clean up
do -- luac -l luac.out
local cmd = luac .. [[ -l luac.out]]
......@@ -271,7 +271,7 @@ if _VERSION >= 'Lua 5.3' then -- bad float format
end
do -- cover.lua
local f = io.open('cover.lua', 'w')
local f = io.open('cover-242.lua', 'w')
f:write([[
local a = false
b = a + 1
......@@ -288,27 +288,27 @@ s = nil
]])
f:close()
local cmd = luac .. [[ -o cover.out cover.lua 2>&1]]
local cmd = luac .. [[ -o cover-242.out cover-242.lua 2>&1]]
f = io.popen(cmd)
is(f:read'*l', nil, "-o cover.out cover.lua")
is(f:read'*l', nil, "-o cover-242.out cover-242.lua")
f:close()
cmd = luac .. [[ -l cover.out]]
cmd = luac .. [[ -l cover-242.out]]
f = io.popen(cmd)
is(f:read'*l', '', "-l cover.out")
is(f:read'*l', '', "-l cover-242.out")
like(f:read'*l', "^main")
f:close()
cmd = luac .. [[ -l -l cover.out]]
cmd = luac .. [[ -l -l cover-242.out]]
f = io.popen(cmd)
is(f:read'*l', '', "-l -l cover.out")
is(f:read'*l', '', "-l -l cover-242.out")
like(f:read'*l', "^main")
f:close()
end
os.remove('luac.out') -- clean up
os.remove('cover.lua') -- clean up
os.remove('cover.out') -- clean up
os.remove('cover-242.lua') -- clean up
os.remove('cover-242.out') -- clean up
done_testing()
-- Local Variables:
......
......@@ -149,7 +149,7 @@ error_like(function () collectgarbage('unknown') end,
"function collectgarbage (invalid)")
do -- dofile
local f = io.open('lib1.lua', 'w')
local f = io.open('lib-301.lua', 'w')
f:write[[
function norm (x, y)
return (x^2 + y^2)^0.5
......@@ -160,24 +160,24 @@ function twice (x)
end
]]
f:close()
dofile('lib1.lua')
dofile('lib-301.lua')
local n = norm(3.4, 1.0)
like(twice(n), '^7%.088', "function dofile")
os.remove('lib1.lua') -- clean up
os.remove('lib-301.lua') -- clean up
error_like(function () dofile('no_file.lua') end,
"cannot open no_file.lua: No such file or directory",
error_like(function () dofile('no_file-301.lua') end,
"cannot open no_file%-301%.lua: No such file or directory",
"function dofile (no file)")
f = io.open('foo.lua', 'w')
f = io.open('foo-301.lua', 'w')
f:write[[?syntax error?]]
f:close()
error_like(function () dofile('foo.lua') end,
"^foo%.lua:%d+:",
error_like(function () dofile('foo-301.lua') end,
"^foo%-301%.lua:%d+:",
"function dofile (syntax error)")
os.remove('foo.lua') -- clean up
os.remove('foo-301.lua') -- clean up
end
do -- error
......@@ -359,7 +359,7 @@ end
end
do -- loadfile
local f = io.open('foo.lua', 'w')
local f = io.open('foo-301.lua', 'w')
if _VERSION ~= 'Lua 5.1' or jit then
f:write'\xEF\xBB\xBF' -- BOM
end
......@@ -369,19 +369,19 @@ function foo (x)
end
]]
f:close()
f = loadfile('foo.lua')
f = loadfile('foo-301.lua')
is(foo, nil, "function loadfile")
f()
is(foo('ok'), 'ok')
if has_loadfile52 then
local msg
f, msg = loadfile('foo.lua', 'b')
f, msg = loadfile('foo-301.lua', 'b')
like(msg, "attempt to load")
is(f, nil, "mode")
local env = {}
f = loadfile('foo.lua', 't', env)
f = loadfile('foo-301.lua', 't', env)
is(env.foo, nil, "function loadfile")
f()
is(env.foo('ok'), 'ok')
......@@ -389,20 +389,20 @@ end
diag("no loadfile with mode & env")
end
os.remove('foo.lua') -- clean up
os.remove('foo-301.lua') -- clean up
local msg
f, msg = loadfile('no_file.lua')
f, msg = loadfile('no_file-301.lua')
is(f, nil, "function loadfile (no file)")
is(msg, "cannot open no_file.lua: No such file or directory")
is(msg, "cannot open no_file-301.lua: No such file or directory")
f = io.open('foo.lua', 'w')
f = io.open('foo-301.lua', 'w')
f:write[[?syntax error?]]
f:close()
f, msg = loadfile('foo.lua')
f, msg = loadfile('foo-301.lua')
is(f, nil, "function loadfile (syntax error)")
like(msg, '^foo%.lua:%d+:')
os.remove('foo.lua') -- clean up
like(msg, '^foo%-301%.lua:%d+:')
os.remove('foo-301.lua') -- clean up
end
-- loadstring
......
......@@ -63,16 +63,16 @@ do -- flush
end
do -- open
os.remove('file.no')
local f, msg = io.open("file.no")
os.remove('file-308.no')
local f, msg = io.open("file-308.no")
is(f, nil, "function open")
is(msg, "file.no: No such file or directory")
is(msg, "file-308.no: No such file or directory")
os.remove('file.txt')
f = io.open('file.txt', 'w')
os.remove('file-308.txt')
f = io.open('file-308.txt', 'w')
f:write("file with text\n")
f:close()
f = io.open('file.txt')
f = io.open('file-308.txt')
like(f, '^file %(0?[Xx]?%x+%)$', "function open")
is(io.close(f), true, "function close")
......@@ -84,14 +84,14 @@ do -- open
if _VERSION == 'Lua 5.1' then
todo("not with 5.1")
end
error_like(function () io.open('file.txt', 'baz') end,
error_like(function () io.open('file-308.txt', 'baz') end,
"^[^:]+:%d+: bad argument #2 to 'open' %(invalid mode%)",
"function open (bad mode)")
end
do -- type
is(io.type("not a file"), nil, "function type")
local f = io.open('file.txt')
local f = io.open('file-308.txt')
is(io.type(f), 'file')
like(tostring(f), '^file %(0?[Xx]?%x+%)$')
io.close(f)
......@@ -103,7 +103,7 @@ do -- input
is(io.stdin, io.input(), "function input")
is(io.stdin, io.input(nil))
local f = io.stdin
like(io.input('file.txt'), '^file %(0?[Xx]?%x+%)$')
like(io.input('file-308.txt'), '^file %(0?[Xx]?%x+%)$')
is(f, io.input(f))
end
......@@ -137,11 +137,11 @@ do -- popen
end
do -- lines
for line in io.lines('file.txt') do
for line in io.lines('file-308.txt') do
is(line, "file with text", "function lines(filename)")
end
error_like(function () io.lines('file.no') end,
error_like(function () io.lines('file-308.no') end,
"No such file or directory",
"function lines(no filename)")
end
......@@ -163,14 +163,14 @@ do -- :close
is(r, nil, "method close (std)")
is(msg, "cannot close standard file")
local f = io.open('file.txt')
local f = io.open('file-308.txt')
is(f:close(), true, "method close")
end
do -- :flush
is(io.stderr:flush(), true, "method flush")
local f = io.open('file.txt')
local f = io.open('file-308.txt')
f:close()
error_like(function () f:flush() end,
"^[^:]+:%d+: attempt to use a closed file",
......@@ -178,13 +178,13 @@ do -- :flush
end
do -- :read & :write
local f = io.open('file.txt')
local f = io.open('file-308.txt')
f:close()
error_like(function () f:read() end,
"^[^:]+:%d+: attempt to use a closed file",
"method read (closed)")
f = io.open('file.txt')
f = io.open('file-308.txt')
local s = f:read()
is(s:len(), 14, "method read")
is(s, "file with text")
......@@ -192,13 +192,13 @@ do -- :read & :write
is(s, nil)
f:close()
f = io.open('file.txt')
f = io.open('file-308.txt')
error_like(function () f:read('*z') end,
"^[^:]+:%d+: bad argument #1 to 'read' %(invalid %w+%)",
"method read (invalid)")
f:close()
f = io.open('file.txt')
f = io.open('file-308.txt')
local s1, s2 = f:read('*l', '*l')
is(s1:len(), 14, "method read *l")
is(s1, "file with text")
......@@ -206,7 +206,7 @@ do -- :read & :write
f:close()
if has_read52 then
f = io.open('file.txt')
f = io.open('file-308.txt')
s1, s2 = f:read('*L', '*L')
is(s1:len(), 15, "method read *L")
is(s1, "file with text\n")
......@@ -216,19 +216,19 @@ do -- :read & :write
diag("no read *L")
end
f = io.open('file.txt')
f = io.open('file-308.txt')
local n1, n2 = f:read('*n', '*n')
is(n1, nil, "method read *n")
is(n2, nil)
f:close()
f = io.open('file.num', 'w')
f = io.open('file-308.num', 'w')
f:write('1\n')
f:write('0xFF\n')
f:write(string.rep('012', 90) .. '\n')
f:close()
f = io.open('file.num')
f = io.open('file-308.num')
n1, n2 = f:read('*n', '*n')
is(n1, 1, "method read *n")
is(n2, 255, "method read *n")
......@@ -240,16 +240,16 @@ do -- :read & :write
end
f:close()
os.remove('file.num') -- clean up
os.remove('file-308.num') -- clean up
f = io.open('file.txt')
f = io.open('file-308.txt')
s = f:read('*a')
is(s:len(), 15, "method read *a")
is(s, "file with text\n")
f:close()
if has_read53 then
f = io.open('file.txt')
f = io.open('file-308.txt')
s = f:read('a')
is(s:len(), 15, "method read a")
is(s, "file with text\n")
......@@ -258,14 +258,14 @@ do -- :read & :write
diag("* mandatory")
end
f = io.open('file.txt')
f = io.open('file-308.txt')
is(f:read(0), '', "method read number")
eq_array({f:read(5, 5, 15)}, {'file ', 'with ', "text\n"})
f:close()
end
do -- :lines
local f = io.open('file.txt')
local f = io.open('file-308.txt')
for line in f:lines() do
is(line, "file with text", "method lines")
end
......@@ -274,7 +274,7 @@ do -- :lines
is(io.type(f), 'closed file')
if has_lines52 then
f = io.open('file.txt')
f = io.open('file-308.txt')
for two_char in f:lines(2) do
is(two_char, "fi", "method lines (with read option)")
break
......@@ -286,29 +286,29 @@ do -- :lines
end
do -- :seek
local f = io.open('file.txt')
local f = io.open('file-308.txt')
f:close()
error_like(function () f:seek('end', 0) end,
"^[^:]+:%d+: attempt to use a closed file",
"method seek (closed)")
f = io.open('file.txt')
f = io.open('file-308.txt')
error_like(function () f:seek('bad', 0) end,
"^[^:]+:%d+: bad argument #1 to 'seek' %(invalid option 'bad'%)",
"method seek (invalid)")
f = io.open('file.bin', 'w')
f = io.open('file-308.bin', 'w')
f:write('ABCDE')
f:close()
f = io.open('file.bin')
f = io.open('file-308.bin')
is(f:seek('end', 0), 5, "method seek")
f:close()
os.remove('file.bin') --clean up
os.remove('file-308.bin') --clean up
end
do -- :setvbuf
local f = io.open('file.txt')
local f = io.open('file-308.txt')
is(f:setvbuf('no'), true, "method setvbuf 'no'")
is(f:setvbuf('full', 4096), true, "method setvbuf 'full'")
......@@ -317,16 +317,16 @@ do -- :setvbuf
f:close()
end
os.remove('file.txt') -- clean up
os.remove('file-308.txt') -- clean up
do -- :write
local f = io.open('file.out', 'w')
local f = io.open('file-308.out', 'w')
f:close()
error_like(function () f:write('end') end,
"^[^:]+:%d+: attempt to use a closed file",
"method write (closed)")
f = io.open('file.out', 'w')
f = io.open('file-308.out', 'w')
if has_write51 then
is(f:write('end'), true, "method write")
else
......@@ -334,7 +334,7 @@ do -- :write
end
f:close()
os.remove('file.out') --clean up
os.remove('file-308.out') --clean up
end
done_testing()
......
......@@ -172,29 +172,29 @@ do -- getenv
end
do -- remove
local f = io.open('file.rm', 'w')
local f = io.open('file-309.rm', 'w')
f:write("file to remove")
f:close()
local r = os.remove("file.rm")
local r = os.remove("file-309.rm")
is(r, true, "function remove")
local msg
r, msg = os.remove('file.rm')
r, msg = os.remove('file-309.rm')
is(r, nil, "function remove")
like(msg, '^file.rm: No such file or directory')
like(msg, '^file%-309%.rm: No such file or directory')
end
do -- rename
local f = io.open('file.old', 'w')
local f = io.open('file-309.old', 'w')
f:write("file to rename")
f:close()
os.remove('file.new')
local r = os.rename('file.old', 'file.new')
os.remove('file-309.new')
local r = os.rename('file-309.old', 'file-309.new')
is(r, true, "function rename")
os.remove('file.new') -- clean up
os.remove('file-309.new') -- clean up
local msg
r, msg = os.rename('file.old', 'file.new')
r, msg = os.rename('file-309.old', 'file-309.new')
is(r, nil, "function rename")
like(msg, 'No such file or directory')
end
......