diff --git a/luaa.c b/luaa.c index e5cd0556..332105d1 100644 --- a/luaa.c +++ b/luaa.c @@ -54,6 +54,7 @@ #include #include +#include #include /* for gethostname() */ @@ -214,6 +215,17 @@ luaA_kill(lua_State *L) return 1; } +/** Synchronize with the X11 server. This is needed in the test suite to avoid + * some race conditions. You should never need to use this function. + * @function sync + */ +static int +luaA_sync(lua_State *L) +{ + xcb_aux_sync(globalconf.connection); + return 0; +} + /** Load an image from a given path. * * @param name The file name. @@ -647,6 +659,7 @@ luaA_init(xdgHandle* xdg, string_array_t *searchpath) { "xkb_get_group_names", luaA_xkb_get_group_names}, { "xrdb_get_value", luaA_xrdb_get_value}, { "kill", luaA_kill}, + { "sync", luaA_sync}, { NULL, NULL } }; diff --git a/tests/_runner.lua b/tests/_runner.lua index c446c04b..5d5b4810 100644 --- a/tests/_runner.lua +++ b/tests/_runner.lua @@ -32,7 +32,7 @@ end) runner.run_steps = function(steps) -- Setup timer/timeout to limit waiting for signal and quitting awesome. -- This would be common for all tests. - local t = timer({timeout=0.1}) + local t = timer({timeout=0}) local wait=20 local step=1 local step_count=0 @@ -64,6 +64,7 @@ runner.run_steps = function(steps) step = step+1 step_count = 0 wait = 5 + t.timeout = 0 t:again() return end @@ -78,6 +79,7 @@ runner.run_steps = function(steps) else wait = wait-1 if wait > 0 then + t.timeout = 0.1 t:again() else io.stderr:write("Error: timeout waiting for signal in step " diff --git a/tests/run.sh b/tests/run.sh index 24caf274..64f3f941 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -228,7 +228,7 @@ for f in $tests; do grep -q -E '[Ee]rror|assertion failed' "$awesome_log"; then echo "===> ERROR running $f <===" grep --color -o --binary-files=text -E '.*[Ee]rror.*|.*assertion failed.*' "$awesome_log" || true - ((errors++)) + ((++errors)) fi done diff --git a/tests/test-awesomerc.lua b/tests/test-awesomerc.lua index fe2b294e..90769455 100644 --- a/tests/test-awesomerc.lua +++ b/tests/test-awesomerc.lua @@ -58,6 +58,7 @@ local steps = { assert(not old_c.ontop) get_callback({modkey}, "t")() + awesome.sync() return true end, @@ -75,6 +76,7 @@ local steps = { assert(t.master_width_factor == 0.5) get_callback({modkey}, "l")() + awesome.sync() return true end, @@ -89,6 +91,7 @@ local steps = { assert(t.master_count == 1) get_callback({modkey, "Shift"}, "h")() + awesome.sync() return true end, @@ -104,6 +107,7 @@ local steps = { get_callback({modkey, "Control"}, "h")() get_callback({modkey, "Shift" }, "l")() + awesome.sync() return true end, @@ -118,6 +122,7 @@ local steps = { assert(t.index == 1) get_callback({modkey, }, "Right")() + awesome.sync() return true end, diff --git a/tests/test-awful-client.lua b/tests/test-awful-client.lua index 5bacf765..3cec2a0a 100644 --- a/tests/test-awful-client.lua +++ b/tests/test-awful-client.lua @@ -108,21 +108,21 @@ table.insert(steps, function() end) table.insert(steps, function() --- The request should have been denied -assert(client.focus == c2) + -- The request should have been denied + assert(client.focus == c2) --- Test the remove function -awful.ewmh.remove_activate_filter(function() end) + -- Test the remove function + awful.ewmh.remove_activate_filter(function() end) -awful.ewmh.add_activate_filter(awful.ewmh.generic_activate_filters[1]) + awful.ewmh.add_activate_filter(awful.ewmh.generic_activate_filters[1]) -awful.ewmh.remove_activate_filter(awful.ewmh.generic_activate_filters[1]) + awful.ewmh.remove_activate_filter(awful.ewmh.generic_activate_filters[1]) -assert(original_count == #awful.ewmh.generic_activate_filters) + assert(original_count == #awful.ewmh.generic_activate_filters) -c1:emit_signal("request::activate", "i_said_so") + c1:emit_signal("request::activate", "i_said_so") -return client.focus == c1 + return client.focus == c1 end) local has_error @@ -214,7 +214,12 @@ table.insert(multi_screen_steps, function() for _, c in ipairs(client.get()) do c:kill() end + if #client.get() == 0 then + return true + end +end) +table.insert(multi_screen_steps, function() for i=1, screen.count() do local s = screen[i] test_client("screen"..i, nil, { @@ -229,81 +234,91 @@ table.insert(multi_screen_steps, function() end) table.insert(multi_screen_steps, function() -if #client.get() ~= screen.count() then return end + if #client.get() ~= screen.count() then return end -for _, c in ipairs(client.get()) do - assert(#c:tags() == 1) - assert(c.first_tag.name == "NEW_AT_"..c.screen.index) -end + for _, c in ipairs(client.get()) do + assert(#c:tags() == 1) + assert(c.first_tag.name == "NEW_AT_"..c.screen.index) + end --- Kill the client -for _, c in ipairs(client.get()) do - c:kill() -end + -- Kill the client + for _, c in ipairs(client.get()) do + c:kill() + end + return true +end) -if screen.count() < 2 then return true end +table.insert(multi_screen_steps, function() + if #client.get() == 0 then + return true + end +end) --- Now, add client where the target tag and screen don't match -test_client("test_tag1", nil, { - tag = screen[2].tags[2], - screen = screen[1], - }) +table.insert(multi_screen_steps, function() --- Add a client with multiple tags on the same screen, but not c.screen -test_client("test_tags1", nil, { - tags = { screen[1].tags[3], screen[1].tags[4] }, - screen = screen[2], - }) + if screen.count() < 2 then return true end --- Identical, but using the tag names -test_client("test_tags2", nil, { - tags = { "3", "4" }, - screen = screen[2], - }) + -- Now, add client where the target tag and screen don't match + test_client("test_tag1", nil, { + tag = screen[2].tags[2], + screen = screen[1], + }) --- Also test tags, but with an invalid screen array -test_client("test_tags3", nil, { - tags = { screen[2].tags[3], screen[1].tags[4] }, - screen = screen[1], - }) + -- Add a client with multiple tags on the same screen, but not c.screen + test_client("test_tags1", nil, { + tags = { screen[1].tags[3], screen[1].tags[4] }, + screen = screen[2], + }) --- Another test for tags, but with no matching names -test_client("test_tags4", nil, { - tags = { "foobar", "bobcat" }, - screen = screen[1], - }) + -- Identical, but using the tag names + test_client("test_tags2", nil, { + tags = { "3", "4" }, + screen = screen[2], + }) -return true + -- Also test tags, but with an invalid screen array + test_client("test_tags3", nil, { + tags = { screen[2].tags[3], screen[1].tags[4] }, + screen = screen[1], + }) + + -- Another test for tags, but with no matching names + test_client("test_tags4", nil, { + tags = { "foobar", "bobcat" }, + screen = screen[1], + }) + + return true end) table.insert(multi_screen_steps, function() -if screen.count() < 2 then return true end -if #client.get() ~= 5 then return end + if screen.count() < 2 then return true end + if #client.get() ~= 5 then return end -local c_by_class = {} + local c_by_class = {} -for _, c in ipairs(client.get()) do - c_by_class[c.class] = c -end + for _, c in ipairs(client.get()) do + c_by_class[c.class] = c + end -assert(c_by_class["test_tag1"].screen == screen[2]) -assert(#c_by_class["test_tag1"]:tags() == 1) + assert(c_by_class["test_tag1"].screen == screen[2]) + assert(#c_by_class["test_tag1"]:tags() == 1) -assert(c_by_class["test_tags1"].screen == screen[1]) -assert(#c_by_class["test_tags1"]:tags() == 2) + assert(c_by_class["test_tags1"].screen == screen[1]) + assert(#c_by_class["test_tags1"]:tags() == 2) -assert(c_by_class["test_tags2"].screen == screen[2]) -assert(#c_by_class["test_tags2"]:tags() == 2) + assert(c_by_class["test_tags2"].screen == screen[2]) + assert(#c_by_class["test_tags2"]:tags() == 2) -assert(c_by_class["test_tags3"].screen == screen[2]) -assert(#c_by_class["test_tags3"]:tags() == 1) + assert(c_by_class["test_tags3"].screen == screen[2]) + assert(#c_by_class["test_tags3"]:tags() == 1) -assert(c_by_class["test_tags4"].screen == screen[1]) -assert(#c_by_class["test_tags4"]:tags() == 1) -assert(c_by_class["test_tags4"]:tags()[1] == screen[1].selected_tag) + assert(c_by_class["test_tags4"].screen == screen[1]) + assert(#c_by_class["test_tags4"]:tags() == 1) + assert(c_by_class["test_tags4"]:tags()[1] == screen[1].selected_tag) -return true + return true end) require("_multi_screen")(steps, multi_screen_steps) diff --git a/tests/test-awful-widget-button.lua b/tests/test-awful-widget-button.lua index b7051547..f6cd2c5a 100644 --- a/tests/test-awful-widget-button.lua +++ b/tests/test-awful-widget-button.lua @@ -82,6 +82,7 @@ table.insert(steps, function() awful.placement.centered(mouse) root.fake_input("button_press", 1) + awesome.sync() return true end) @@ -94,10 +95,11 @@ end) -- Test a button release table.insert(steps, function() - root.fake_input("button_release", 1) - assert(button._private.image ~= img) + root.fake_input("button_release", 1) + awesome.sync() + return true end) @@ -106,6 +108,7 @@ table.insert(steps, function() assert(button._private.image == img) root.fake_input("button_press", 1) + awesome.sync() return true end) @@ -123,6 +126,7 @@ assert(button._private.image ~= img) -- test if the button is released when the mouse move out awful.placement.right(mouse--[[, {parent = w}]]) root.fake_input("button_release", 1) +awesome.sync() return true end) diff --git a/tests/test-geometry.lua b/tests/test-geometry.lua index 7b6bf19c..c90d1b9d 100644 --- a/tests/test-geometry.lua +++ b/tests/test-geometry.lua @@ -55,18 +55,20 @@ local steps = { awful.rules.rules = { -- All clients will match this rule. { rule = { },properties = { - titlebars_enabled = true, - border_width = 10, - border_color = "#00ff00", - size_hints_honor = false, - x = 0, - y = 0, - width = 100, - height = 100 + titlebars_enabled = true, + border_width = 10, + border_color = "#00ff00", + size_hints_honor = false, + x = 0, + y = 0, + width = 100, + height = 100 + }} } - } -} -return true + -- Wait for the previous c:kill() to be done + if #client.get() == 0 then + return true + end end, function(count) if count == 1 then diff --git a/tests/test-leak-client.lua b/tests/test-leak-client.lua index 09e2d290..edba1ef5 100644 --- a/tests/test-leak-client.lua +++ b/tests/test-leak-client.lua @@ -62,7 +62,7 @@ local steps = { -- Wait for one iteration so that gears.timer handles other delayed -- calls (= the tasklist updates) second_call = true - else + elseif #client.get() == 0 then assert(#objs == 1) -- Test that we have a client and that it's invalid (tostring()