mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-08 09:18:30 +00:00
added lua testlib
This commit is contained in:
parent
e9e9e81fbf
commit
3ec485505f
47
tests/testlib.lua
Executable file
47
tests/testlib.lua
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
-- common testing environment
|
||||||
|
|
||||||
|
require("posix")
|
||||||
|
|
||||||
|
-- escape codes to colorize output on terminal
|
||||||
|
local c1="\027[47;34m"
|
||||||
|
local c0="\027[0m"
|
||||||
|
|
||||||
|
---
|
||||||
|
-- writes colorized
|
||||||
|
--
|
||||||
|
function cwriteln(...)
|
||||||
|
io.write(c1, ...)
|
||||||
|
io.write(c0, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- creates a tmp directory
|
||||||
|
function mktempd()
|
||||||
|
local f = io.popen('mktemp -d', 'r')
|
||||||
|
local s = f:read('*a')
|
||||||
|
f:close()
|
||||||
|
s = s:gsub('[\n\r]+', ' ')
|
||||||
|
s = s:match("^%s*(.-)%s*$")
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- spawns a subprocess.
|
||||||
|
--
|
||||||
|
function spawn(...)
|
||||||
|
local pid = posix.fork()
|
||||||
|
if pid < 0 then
|
||||||
|
cwriteln("Error, failed fork!")
|
||||||
|
os.exit(-1)
|
||||||
|
end
|
||||||
|
if lpid == 0 then
|
||||||
|
posix.exec(...)
|
||||||
|
-- should not return
|
||||||
|
cwriteln("Error, failed to spawn: ", ...)
|
||||||
|
os.exit(-1);
|
||||||
|
end
|
||||||
|
return pid
|
||||||
|
end
|
||||||
|
|
||||||
|
print(mktempd())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user