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,23 +3,27 @@
|
|||
local runner = require("_runner")
|
||||
local spawn = require("awful.spawn")
|
||||
|
||||
local todo = 2
|
||||
local had_exit, had_success
|
||||
local had_error = false
|
||||
|
||||
local function wait_a_bit(count)
|
||||
if todo == 0 or count == 5 then
|
||||
return true
|
||||
local function check_done()
|
||||
if had_exit and had_success then
|
||||
if had_error then
|
||||
runner.done("Some error occurred, see above")
|
||||
else
|
||||
runner.done()
|
||||
end
|
||||
end
|
||||
end
|
||||
runner.run_steps({
|
||||
function()
|
||||
local err = spawn.with_line_callback(
|
||||
|
||||
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
|
||||
had_exit = true
|
||||
check_done()
|
||||
end,
|
||||
stderr = function(line)
|
||||
had_error = true
|
||||
|
@ -27,38 +31,16 @@ runner.run_steps({
|
|||
end,
|
||||
stdout = function(line)
|
||||
if line == "SUCCESS" then
|
||||
todo = todo - 1
|
||||
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)
|
||||
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
|
||||
})
|
||||
|
||||
assert(type(err) ~= "string", err)
|
||||
runner.run_direct()
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||
|
|
Loading…
Reference in New Issue