test-gravity.lua: Turn into a direct test
This commit makes test-gravity.lua use the new infrastructure that was added in the previous commit: Instead of pretending to be a steps-based test, this is now a direct test. This gets rid of all the useless wait_a_bit steps that exist purely to satisfy the steps-based test runner. This commit makes test-gravity.lua about one third shorter. Also, the test might run a tiny bit faster, since there is no more timer that regularly checks if the test is done, but instead it finishes immediately when the external process finishes. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
f304c608e8
commit
a7f4777272
|
@ -3,62 +3,44 @@
|
||||||
local runner = require("_runner")
|
local runner = require("_runner")
|
||||||
local spawn = require("awful.spawn")
|
local spawn = require("awful.spawn")
|
||||||
|
|
||||||
local todo = 2
|
local had_exit, had_success
|
||||||
local had_error = false
|
local had_error = false
|
||||||
|
|
||||||
local function wait_a_bit(count)
|
local function check_done()
|
||||||
if todo == 0 or count == 5 then
|
if had_exit and had_success then
|
||||||
return true
|
if had_error then
|
||||||
end
|
runner.done("Some error occurred, see above")
|
||||||
end
|
else
|
||||||
runner.run_steps({
|
runner.done()
|
||||||
function()
|
|
||||||
local err = spawn.with_line_callback(
|
|
||||||
{ os.getenv("build_dir") .. "/test-gravity" },
|
|
||||||
{
|
|
||||||
exit = function(what, code)
|
|
||||||
assert(what == "exit", what)
|
|
||||||
assert(code == 0, "Exit code was " .. code)
|
|
||||||
todo = todo - 1
|
|
||||||
end,
|
|
||||||
stderr = function(line)
|
|
||||||
had_error = true
|
|
||||||
print("Read on stderr: " .. line)
|
|
||||||
end,
|
|
||||||
stdout = function(line)
|
|
||||||
if line == "SUCCESS" then
|
|
||||||
todo = todo - 1
|
|
||||||
elseif line:sub(1, 5) ~= "LOG: " then
|
|
||||||
had_error = true
|
|
||||||
print("Read on stdout: " .. line)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
assert(type(err) ~= "string", err)
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
-- Buy the external program some time to finish
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
wait_a_bit,
|
|
||||||
function()
|
|
||||||
if todo == 0 then
|
|
||||||
assert(not had_error, "Some error occurred, see above")
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
end
|
||||||
|
|
||||||
|
local err = spawn.with_line_callback(
|
||||||
|
{ os.getenv("build_dir") .. "/test-gravity" },
|
||||||
|
{
|
||||||
|
exit = function(what, code)
|
||||||
|
assert(what == "exit", what)
|
||||||
|
assert(code == 0, "Exit code was " .. code)
|
||||||
|
had_exit = true
|
||||||
|
check_done()
|
||||||
|
end,
|
||||||
|
stderr = function(line)
|
||||||
|
had_error = true
|
||||||
|
print("Read on stderr: " .. line)
|
||||||
|
end,
|
||||||
|
stdout = function(line)
|
||||||
|
if line == "SUCCESS" then
|
||||||
|
had_success = true
|
||||||
|
check_done()
|
||||||
|
elseif line:sub(1, 5) ~= "LOG: " then
|
||||||
|
had_error = true
|
||||||
|
print("Read on stdout: " .. line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
assert(type(err) ~= "string", err)
|
||||||
|
runner.run_direct()
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue