Make tests more reliable on "early errors"

When e.g. test-leaks.lua fails, it will cause a Lua error before starting the
test runner. This means that the test will just hang, because nothing causes
awesome to quit.

Handle this by starting a timer when the test runner is loaded and quitting
awesome in there if no test run was started yet. This only works if all tests
load the runner before doing anything that could fail, so the require("_runner")
is moved to the beginning in every test.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-03-06 10:20:45 +01:00
parent ab408103ee
commit e18bece3df
8 changed files with 30 additions and 7 deletions

View File

@ -16,6 +16,20 @@ runner.add_to_default_rules = function(r)
table.insert(awful.rules.rules, r)
end
-- 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
io.stderr:write("Error: run_steps() was never called\n")
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)
runner.run_steps = function(steps)
-- Setup timer/timeout to limit waiting for signal and quitting awesome.
@ -24,6 +38,8 @@ runner.run_steps = function(steps)
local wait=20
local step=1
local step_count=0
assert(not running, "run_steps() was called twice")
running = true
t:connect_signal("timeout", function() timer.delayed_call(function()
io.flush() -- for "tail -f".
step_count = step_count + 1

View File

@ -1,5 +1,6 @@
--- Test for awful.widget.watch
local runner = require("_runner")
local watch = require("awful.widget.watch")
local callbacks_done = 0
@ -25,6 +26,6 @@ local steps = {
end
end
}
require("_runner").run_steps(steps)
runner.run_steps(steps)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,6 +1,7 @@
-- Some benchmarks that aren't really tests, but are included here anyway so
-- that we notice if they break.
local runner = require("_runner")
local awful = require("awful")
local GLib = require("lgi").GLib
local create_wibox = require("_wibox_helper").create_wibox
@ -75,6 +76,6 @@ benchmark(relayout_textclock, "relayout textclock")
benchmark(redraw_textclock, "redraw textclock")
benchmark(e2e_tag_switch, "tag switch")
require("_runner").run_steps({ function() return true end })
runner.run_steps({ function() return true end })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,6 +1,7 @@
--- Tests for focus signals / property.
-- Test for https://github.com/awesomeWM/awesome/issues/134.
local runner = require("_runner")
local awful = require("awful")
local beautiful = require("beautiful")
@ -44,6 +45,6 @@ local steps = {
end
}
require("_runner").run_steps(steps)
runner.run_steps(steps)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,4 +1,5 @@
-- Some memory leak checks involving clients as integration tests.
local runner = require("_runner")
local awful = require("awful")
local wibox = require("wibox")
@ -78,6 +79,6 @@ local steps = {
end,
}
require("_runner").run_steps(steps)
runner.run_steps(steps)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,5 +1,6 @@
-- Some memory leak checks as integration tests.
local runner = require("_runner")
local awful = require("awful")
local cairo = require("lgi").cairo
local create_wibox = require("_wibox_helper").create_wibox
@ -77,6 +78,6 @@ collectable(awful.widget.tasklist(1, awful.widget.tasklist.filter.currenttags))
prepare_for_collect = emit_refresh
collectable(create_wibox())
require("_runner").run_steps({ function() return true end })
runner.run_steps({ function() return true end })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,5 +1,6 @@
--- Tests for spawn's startup notifications.
local runner = require("_runner")
local spawn = require("awful.spawn")
local manage_called, c_snid
@ -38,6 +39,6 @@ local steps = {
end
}
require("_runner").run_steps(steps)
runner.run_steps(steps)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,5 +1,6 @@
--- Tests for spawn
local runner = require("_runner")
local spawn = require("awful.spawn")
local spawns_done = 0
@ -63,6 +64,6 @@ local steps = {
end,
}
require("_runner").run_steps(steps)
runner.run_steps(steps)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80