2015-08-13 10:57:29 +02:00
|
|
|
local timer = require("gears.timer")
|
|
|
|
local awful = require("awful")
|
2017-03-08 21:18:33 +01:00
|
|
|
local gtable = require("gears.table")
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2016-02-07 13:04:01 +01:00
|
|
|
local runner = {
|
2016-12-27 21:39:08 +01:00
|
|
|
quit_awesome_on_error = os.getenv('TEST_PAUSE_ON_ERRORS') ~= '1',
|
2015-07-10 13:17:50 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 14:17:35 +02:00
|
|
|
local verbose = os.getenv('VERBOSE') == '1'
|
|
|
|
|
2015-07-10 13:17:50 +02:00
|
|
|
-- Helpers.
|
|
|
|
|
|
|
|
--- Add some rules to awful.rules.rules, after the defaults.
|
2017-03-08 21:18:33 +01:00
|
|
|
local default_rules = gtable.clone(awful.rules.rules)
|
2015-07-10 13:17:50 +02:00
|
|
|
runner.add_to_default_rules = function(r)
|
2017-03-08 21:18:33 +01:00
|
|
|
awful.rules.rules = gtable.clone(default_rules)
|
2016-12-27 21:39:08 +01:00
|
|
|
table.insert(awful.rules.rules, r)
|
2015-07-10 13:17:50 +02:00
|
|
|
end
|
|
|
|
|
2016-03-06 10:20:45 +01:00
|
|
|
-- Was the runner started already?
|
|
|
|
local running = false
|
|
|
|
|
|
|
|
-- This is used if a test causes errors before starting the runner
|
|
|
|
timer.start_new(1, function()
|
|
|
|
if not running then
|
2017-07-09 14:17:35 +02:00
|
|
|
io.stderr:write("Error: run_steps() was never called.\n")
|
2016-03-06 10:20:45 +01:00
|
|
|
if not runner.quit_awesome_on_error then
|
|
|
|
io.stderr:write("Keeping awesome open...\n")
|
|
|
|
return -- keep awesome open on error.
|
|
|
|
end
|
|
|
|
awesome.quit()
|
|
|
|
end
|
|
|
|
end)
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2017-07-09 14:17:35 +02:00
|
|
|
runner.step_kill_clients = function(step)
|
|
|
|
if step == 1 then
|
|
|
|
for _,c in ipairs(client.get()) do
|
|
|
|
c:kill()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if #client.get() == 0 then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
runner.run_steps = function(steps, options)
|
2016-12-27 21:39:08 +01:00
|
|
|
-- Setup timer/timeout to limit waiting for signal and quitting awesome.
|
2017-01-01 14:46:29 +01:00
|
|
|
local t = timer({timeout=0})
|
2016-12-27 21:39:08 +01:00
|
|
|
local wait=20
|
|
|
|
local step=1
|
|
|
|
local step_count=0
|
2017-07-09 14:17:35 +02:00
|
|
|
options = options or {
|
|
|
|
kill_clients=true,
|
|
|
|
}
|
2016-12-27 21:39:08 +01:00
|
|
|
assert(not running, "run_steps() was called twice")
|
|
|
|
running = true
|
2017-07-09 14:17:35 +02:00
|
|
|
|
|
|
|
if options.kill_clients then
|
|
|
|
-- Add a final step to kill all clients and wait for them to finish.
|
|
|
|
-- Ref: https://github.com/awesomeWM/awesome/pull/1904#issuecomment-312793006
|
|
|
|
steps[#steps + 1] = runner.step_kill_clients
|
|
|
|
end
|
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
t:connect_signal("timeout", function() timer.delayed_call(function()
|
|
|
|
io.flush() -- for "tail -f".
|
|
|
|
step_count = step_count + 1
|
|
|
|
local step_as_string = step..'/'..#steps..' (@'..step_count..')'
|
2017-07-09 14:17:35 +02:00
|
|
|
if verbose then
|
|
|
|
print(string.format('Running step %s..', step_as_string))
|
|
|
|
end
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
-- Call the current step's function.
|
|
|
|
local success, result = xpcall(function()
|
|
|
|
return steps[step](step_count)
|
|
|
|
end, debug.traceback)
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
if not success then
|
|
|
|
io.stderr:write('Error: running function for step '
|
|
|
|
..step_as_string..': '..tostring(result)..'!\n')
|
|
|
|
t:stop()
|
|
|
|
if not runner.quit_awesome_on_error then
|
|
|
|
io.stderr:write("Keeping awesome open...\n")
|
|
|
|
return -- keep awesome open on error.
|
|
|
|
end
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
elseif result then
|
|
|
|
-- true: test succeeded.
|
|
|
|
if step < #steps then
|
|
|
|
-- Next step.
|
|
|
|
step = step+1
|
|
|
|
step_count = 0
|
|
|
|
wait = 5
|
2017-01-01 14:46:29 +01:00
|
|
|
t.timeout = 0
|
2016-12-27 21:39:08 +01:00
|
|
|
t:again()
|
|
|
|
return
|
|
|
|
end
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
elseif result == false then
|
2017-03-31 03:37:16 +02:00
|
|
|
io.stderr:write("Step "..step_as_string.." failed (returned false).\n")
|
2016-12-27 21:39:08 +01:00
|
|
|
if not runner.quit_awesome_on_error then
|
|
|
|
io.stderr:write("Keeping awesome open...\n")
|
|
|
|
return
|
|
|
|
end
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
else
|
2017-07-09 14:17:35 +02:00
|
|
|
-- No result yet, run this step again.
|
2016-12-27 21:39:08 +01:00
|
|
|
wait = wait-1
|
|
|
|
if wait > 0 then
|
2017-01-01 14:46:29 +01:00
|
|
|
t.timeout = 0.1
|
2016-12-27 21:39:08 +01:00
|
|
|
t:again()
|
|
|
|
else
|
|
|
|
io.stderr:write("Error: timeout waiting for signal in step "
|
|
|
|
..step_as_string..".\n")
|
|
|
|
t:stop()
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
2017-07-09 14:17:35 +02:00
|
|
|
|
|
|
|
local client_count = #client.get()
|
|
|
|
if client_count > 0 then
|
|
|
|
io.stderr:write(string.format(
|
|
|
|
"NOTE: there were %d clients left after the test.\n", client_count))
|
|
|
|
|
|
|
|
-- Remove any clients.
|
|
|
|
for _,c in ipairs(client.get()) do
|
|
|
|
c:kill()
|
|
|
|
end
|
2016-12-27 21:39:08 +01:00
|
|
|
end
|
2017-07-09 14:17:35 +02:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
if success and result then
|
2017-07-09 14:17:35 +02:00
|
|
|
io.stderr:write("Test finished successfully.\n")
|
2016-12-27 21:39:08 +01:00
|
|
|
end
|
|
|
|
awesome.quit()
|
|
|
|
end) end)
|
|
|
|
t:start()
|
2015-07-10 13:17:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return runner
|
2015-12-12 17:42:33 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|