diff options
| author | Nikolai Nechaev <nikolay_nechaev@mail.ru> | 2026-04-28 19:17:12 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-28 11:17:12 +0100 |
| commit | d4c6ff434c5c7aa66bc7c28e5ce336d2a694bfcc (patch) | |
| tree | 3813063b81dc435177baba35ffdb655d4e3bd154 /hyprtester/src/tests/main/window.cpp | |
| parent | e1bda229bdf070f1eed01858f862ca975783df71 (diff) | |
hyprtester: minor refactoring/restructure (#14154)
* hyprtester: Minor misc fixes
- Use `std::filesystem::path` instead of `std::string` in some places;
- Use `std::ranges::sort`, as suggested by clang-tidy;
- Reset colors at the end of every log line;
- Give more specific error messages in main.
* hyprtester: Fix a bug in `hyprlandAlive()`
Successful standard library calls are permitted to (and do) modify the
value of `errno` arbitrarily. Checking the value of `errno` only makes
sense when the library function returns an error. So, the correct
condition of a successful signal delivery is that the call to `kill`
returns 0.
Btw, given the possible other error values of `kill(2)`, should we even
consider `errno` at all?
* hyprtester: Restructure main
Split main's `main()` into multiple functions, separate responsibilities
more cleanly.
Add default values for cmd-line options to the help message.
* hyprtester: Remove redundant path canonicalization
* hyprtester: Run unified clean up code before every test
* tests: Use RAII for clients in client tests
Turn clients in client tests into classes. Constructors
initialize, destructors deinitialize.
Not only is it better design when entities (clients) are
modeled as classes, keeping all the methods connected,
this also ensures the tests perform their custom cleanup.
This will be especially important when we introduce early
termination on failure into the tests.
* hyprtester: Rewrite the testing framework!
- Implement a new test definition system used via the `TEST_CASE` and
`SUBTEST` macros.
- Adds `ASSERT*` and reimplements `EXPECT*` macros. The former now
terminate the test immediately. Also add some new macros, such as
`FAIL_TEST`.
- Move existing tests to the new system. For trivial cases, break
existing test functions down to multiple test cases.
- For non-trivial cases and a few other possible improvements, leave
TODOs.
* tests: Use `EXPECT*` instead of `ASSERT*` in some places
`ASSERT*` macros terminate the test as soon as they fail. They are
appropriate to use when, if something fails, the rest of the test
does not make sense and more error messages from failing checks will
just pollute the output.
`EXPECT*` macros mark the test as failed but its execution continues.
It makes sense to use them when error messages from the following checks
in the test may be useful for someone who will be reading the log.
I changed some uses of `ASSERT*` in main tests to `EXPECT*`. But I was
not reading tests very carefully, so maybe I was wrong in some places.
My rule of thumb was:
- Checks that ensure that a kitty opens / a certain set/number of
windows exists are fatal;
- A series of checks, especially on the same string returned by
`Hyprland`, are non-fatal;
- Checks in tests with tightly coupled steps (i.e., do this, check,
do this with the result of the previous step, check, etc) are fatal.
Diffstat (limited to 'hyprtester/src/tests/main/window.cpp')
| -rw-r--r-- | hyprtester/src/tests/main/window.cpp | 344 |
1 files changed, 98 insertions, 246 deletions
diff --git a/hyprtester/src/tests/main/window.cpp b/hyprtester/src/tests/main/window.cpp index f8e7c499..730c51be 100644 --- a/hyprtester/src/tests/main/window.cpp +++ b/hyprtester/src/tests/main/window.cpp @@ -14,8 +14,7 @@ #include "../shared.hpp" #include "tests.hpp" -static int ret = 0; - +// TODO: seems redundant, can just use `Tests::spawnKitty`? static bool spawnKitty(const std::string& class_, const std::vector<std::string>& args = {}) { NLog::log("{}Spawning {}", Colors::YELLOW, class_); if (!Tests::spawnKitty(class_, args)) { @@ -52,31 +51,26 @@ static std::string getWindowAddress(const std::string& winInfo) { auto pos2 = winInfo.find(" -> "); if (pos == std::string::npos || pos2 == std::string::npos) { NLog::log("{}Wrong window info", Colors::RED); - ret = 1; return "Wrong window info"; } return winInfo.substr(pos + 7, pos2 - pos - 7); } -static void testSwapWindow() { - NLog::log("{}Testing swapwindow", Colors::GREEN); - +TEST_CASE(swapWindow) { // test on workspace "swapwindow" NLog::log("{}Switching to workspace \"swapwindow\"", Colors::YELLOW); getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:swapwindow' })"); if (!Tests::spawnKitty("kitty_A")) { - ret = 1; - return; + FAIL_TEST("Could not spawn kitty"); } if (!Tests::spawnKitty("kitty_B")) { - ret = 1; - return; + FAIL_TEST("Could not spawn kitty"); } NLog::log("{}Expecting 2 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 2); + ASSERT(Tests::windowCount(), 2); // Test swapwindow by direction { @@ -138,18 +132,9 @@ static void testSwapWindow() { getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_B' })"); EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("{}", ws)); } - - // kill all - NLog::log("{}Killing all windows", Colors::YELLOW); - Tests::killAllWindows(); - - NLog::log("{}Expecting 0 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 0); } -static void testGroupRules() { - NLog::log("{}Testing group window rules", Colors::YELLOW); - +TEST_CASE(windowGroupRules) { OK(getFromSocket("/eval hl.config({ general = { border_size = 8 } })")); OK(getFromSocket("/eval hl.workspace_rule({ workspace = 'w[tv1]', border_size = 0 })")); OK(getFromSocket("/eval hl.workspace_rule({ workspace = 'f[1]', border_size = 0 })")); @@ -157,8 +142,7 @@ static void testGroupRules() { OK(getFromSocket("/eval hl.window_rule({ match = { workspace = 'f[1]' }, border_size = 0 })")); if (!Tests::spawnKitty("kitty_A")) { - ret = 1; - return; + FAIL_TEST("Could not spawn kitty"); } { @@ -167,8 +151,7 @@ static void testGroupRules() { } if (!Tests::spawnKitty("kitty_B")) { - ret = 1; - return; + FAIL_TEST("Could not spawn kitty"); } { @@ -194,8 +177,7 @@ static void testGroupRules() { } if (!Tests::spawnKitty("kitty_C")) { - ret = 1; - return; + FAIL_TEST("Could not spawn kitty"); } OK(getFromSocket("/dispatch hl.dsp.window.move({ out_of_group = 'right' })")); @@ -204,9 +186,6 @@ static void testGroupRules() { auto str = getFromSocket("/getprop active border_size"); EXPECT_CONTAINS(str, "8"); } - - OK(getFromSocket("/reload")); - Tests::killAllWindows(); } static bool isActiveWindow(const std::string& class_, char fullscreen = '0', bool log = true) { @@ -236,11 +215,11 @@ static bool waitForActiveWindow(const std::string& class_, char fullscreen = '0' /// Tests behavior of a window being focused when on that window's workspace /// another fullscreen window exists. -static bool testWindowFocusOnFullscreenConflict() { +TEST_CASE(windowFocusOnFullscreenConflict) { if (!spawnKitty("kitty_A")) - return false; + FAIL_TEST("Could not spawn kitty"); if (!spawnKitty("kitty_B")) - return false; + FAIL_TEST("Could not spawn kitty"); OK(getFromSocket("/eval hl.config({ misc = { focus_on_activate = true } })")); @@ -263,7 +242,7 @@ static bool testWindowFocusOnFullscreenConflict() { // Make a window that will request focus const std::string removeToActivate = spawnKittyActivating(); if (removeToActivate.empty()) - return false; + FAIL_TEST("Could not spawn kitty_activating"); OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })")); OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })")); EXPECT(isActiveWindow("kitty_A", '2'), true); @@ -293,7 +272,7 @@ static bool testWindowFocusOnFullscreenConflict() { // Make a window that will request focus const std::string removeToActivate = spawnKittyActivating(); if (removeToActivate.empty()) - return false; + FAIL_TEST("Could not spawn kitty_activating"); OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })")); OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })")); EXPECT(isActiveWindow("kitty_A", '2'), true); @@ -318,30 +297,17 @@ static bool testWindowFocusOnFullscreenConflict() { // Make a window that will request focus - the setting is treated normally const std::string removeToActivate = spawnKittyActivating(); if (removeToActivate.empty()) - return false; + FAIL_TEST("Could not spawn kitty_activating"); OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_A' })")); OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })")); EXPECT(isActiveWindow("kitty_A", '2'), true); std::filesystem::remove(removeToActivate); EXPECT(waitForActiveWindow("kitty_A", '2'), true); } - - NLog::log("{}Reloading config", Colors::YELLOW); - OK(getFromSocket("/reload")); - - NLog::log("{}Killing all windows", Colors::YELLOW); - Tests::killAllWindows(); - - NLog::log("{}Expecting 0 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 0); - - return true; } -static void testMaximizeSize() { - NLog::log("{}Testing maximize size", Colors::GREEN); - - EXPECT(spawnKitty("kitty_A"), true); +TEST_CASE(windowMaximizeSize) { + ASSERT(spawnKitty("kitty_A"), true); // check kitty properties. Maximizing shouldnt change its size { @@ -359,44 +325,28 @@ static void testMaximizeSize() { EXPECT(str.contains("size: 1876,1036"), true); EXPECT(str.contains("fullscreen: 1"), true); } - - NLog::log("{}Killing all windows", Colors::YELLOW); - Tests::killAllWindows(); - - NLog::log("{}Expecting 0 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 0); } -static void testFloatingFocusOnFullscreen() { - NLog::log("{}Testing floating focus on fullscreen", Colors::GREEN); - - EXPECT(spawnKitty("kitty_A"), true); +TEST_CASE(floatingFocusOnFullscreen) { + ASSERT(spawnKitty("kitty_A"), true); OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle' })")); - EXPECT(spawnKitty("kitty_B"), true); + ASSERT(spawnKitty("kitty_B"), true); OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'maximized' })")); OK(getFromSocket("/dispatch hl.dsp.window.cycle_next()")); OK(getFromSocket("/eval hl.plugin.test.floating_focus_on_fullscreen()")); - - NLog::log("{}Killing all windows", Colors::YELLOW); - Tests::killAllWindows(); - - NLog::log("{}Expecting 0 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 0); } -static void testGroupFallbackFocus() { - NLog::log("{}Testing group fallback focus", Colors::GREEN); - - EXPECT(spawnKitty("kitty_A"), true); +TEST_CASE(groupFallbackFocus) { + ASSERT(spawnKitty("kitty_A"), true); OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); - EXPECT(spawnKitty("kitty_B"), true); - EXPECT(spawnKitty("kitty_C"), true); - EXPECT(spawnKitty("kitty_D"), true); + ASSERT(spawnKitty("kitty_B"), true); + ASSERT(spawnKitty("kitty_C"), true); + ASSERT(spawnKitty("kitty_D"), true); { auto str = getFromSocket("/activewindow"); @@ -414,27 +364,18 @@ static void testGroupFallbackFocus() { auto str = getFromSocket("/activewindow"); EXPECT(str.contains("class: kitty_B"), true); } - - NLog::log("{}Killing all windows", Colors::YELLOW); - Tests::killAllWindows(); - - NLog::log("{}Expecting 0 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 0); } -static void testBringActiveToTopMouseMovement() { - NLog::log("{}Testing bringactivetotop mouse movement", Colors::GREEN); - - Tests::killAllWindows(); +TEST_CASE(bringActiveToTopMouseMovement) { OK(getFromSocket("/eval hl.config({ input = { follow_mouse = 2 } })")); OK(getFromSocket("/eval hl.config({ input = { float_switch_override_focus = 0 } })")); - EXPECT(spawnKitty("a"), true); + ASSERT(spawnKitty("a"), true); OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set' })")); OK(getFromSocket("/dispatch hl.dsp.window.move({ x = 500, y = 300 })")); OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 400, y = 400 })")); - EXPECT(spawnKitty("b"), true); + ASSERT(spawnKitty("b"), true); OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set' })")); OK(getFromSocket("/dispatch hl.dsp.window.move({ x = 500, y = 300 })")); OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 400, y = 400 })")); @@ -444,31 +385,26 @@ static void testBringActiveToTopMouseMovement() { return (clients.rfind("class: a") > clients.rfind("class: b")) ? "a" : "b"; }; - EXPECT(getTopWindow(), std::string("b")); + ASSERT(getTopWindow(), std::string("b")); OK(getFromSocket("/dispatch hl.dsp.cursor.move({ x = 700, y = 500 })")); OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:a' })")); - EXPECT_CONTAINS(getFromSocket("/activewindow"), "class: a"); + ASSERT_CONTAINS(getFromSocket("/activewindow"), "class: a"); OK(getFromSocket("/dispatch hl.dsp.window.bring_to_top()")); - EXPECT(getTopWindow(), std::string("a")); + ASSERT(getTopWindow(), std::string("a")); OK(getFromSocket("/eval hl.plugin.test.click(272, 1)")); OK(getFromSocket("/eval hl.plugin.test.click(272, 0)")); - EXPECT(getTopWindow(), std::string("a")); - - Tests::killAllWindows(); + ASSERT(getTopWindow(), std::string("a")); } -static void testInitialFloatSize() { - NLog::log("{}Testing initial float size", Colors::GREEN); - - Tests::killAllWindows(); +TEST_CASE(initialFloatSize) { OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty' }, float = true })")); OK(getFromSocket("/eval hl.config({ input = { float_switch_override_focus = 0 } })")); - EXPECT(spawnKitty("kitty"), true); + ASSERT(spawnKitty("kitty"), true); { // Kitty by default opens as 640x400, if this changes this test will break @@ -490,21 +426,17 @@ static void testInitialFloatSize() { EXPECT(str.contains("size: 640,400"), true); EXPECT(str.contains("floating: 1"), true); } - - Tests::killAllWindows(); } /// Tests that the `focus_on_activate` effect of window rules always overrides /// the `misc:focus_on_activate` variable. -static bool testWindowRuleFocusOnActivate() { - OK(getFromSocket("/reload")); - +TEST_CASE(windowRuleFocusOnActivate) { if (!spawnKitty("kitty_default")) { - NLog::log("{}Error: failed to spawn kitty", Colors::RED); - return false; + FAIL_TEST("Could not spawn kitty"); } // Do not focus anyone automatically + // TODO: this looks like a bug: the following line should not be commented out ///////////OK(getFromSocket("/eval hl.window_rule({ match = { class = '.*' }, no_initial_focus = true })")); // `focus_on_activate off` takes over @@ -514,15 +446,15 @@ static bool testWindowRuleFocusOnActivate() { const std::string removeToActivate = spawnKittyActivating("kitty_antifocus"); if (removeToActivate.empty()) { - return false; + FAIL_TEST("Could not spawn kitty_antifocus"); } - EXPECT(waitForActiveWindow("kitty_antifocus"), true); + ASSERT(waitForActiveWindow("kitty_antifocus"), true); OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_default' })")); - EXPECT(isActiveWindow("kitty_default"), true); + ASSERT(isActiveWindow("kitty_default"), true); std::filesystem::remove(removeToActivate); // The focus should NOT transition, since the window rule explicitly forbids that - EXPECT(waitForActiveWindow("kitty_antifocus", '0', false), false); + ASSERT(waitForActiveWindow("kitty_antifocus", '0', false), false); } // `focus_on_activate on` takes over @@ -532,37 +464,24 @@ static bool testWindowRuleFocusOnActivate() { const std::string removeToActivate = spawnKittyActivating("kitty_superfocus"); if (removeToActivate.empty()) { - return false; + FAIL_TEST("Could not spawn kitty_superfocus"); } - EXPECT(waitForActiveWindow("kitty_superfocus"), true); + ASSERT(waitForActiveWindow("kitty_superfocus"), true); OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_default' })")); - EXPECT(isActiveWindow("kitty_default"), true); + ASSERT(isActiveWindow("kitty_default"), true); std::filesystem::remove(removeToActivate); // Now that we requested activation, the focus SHOULD transition to kitty_superfocus, according to the window rule - EXPECT(waitForActiveWindow("kitty_superfocus"), true); + ASSERT(waitForActiveWindow("kitty_superfocus"), true); } - - NLog::log("{}Reloading config", Colors::YELLOW); - OK(getFromSocket("/reload")); - - NLog::log("{}Killing all windows", Colors::YELLOW); - Tests::killAllWindows(); - - NLog::log("{}Expecting 0 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 0); - - return true; } // tests if a pinned window contains the valid workspace after change -static bool testPinnedWorkspacesValid() { - OK(getFromSocket("/reload")); +TEST_CASE(pinnedWorkspacesValid) { getFromSocket("/dispatch hl.dsp.focus({ workspace = '1337' })"); if (!spawnKitty("kitty")) { - NLog::log("{}Error: failed to spawn kitty", Colors::RED); - return false; + FAIL_TEST("Could not spawn kitty"); } OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:kitty' })")); @@ -582,38 +501,23 @@ static bool testPinnedWorkspacesValid() { EXPECT(str.contains("pinned: 1"), true); } - OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'unset', window = 'class:kitty' })")) + OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'unset', window = 'class:kitty' })")); { auto str = getFromSocket("/activewindow"); EXPECT(str.contains("workspace: 1338"), true); EXPECT(str.contains("pinned: 0"), true); } - - NLog::log("{}Reloading config", Colors::YELLOW); - OK(getFromSocket("/reload")); - - NLog::log("{}Killing all windows", Colors::YELLOW); - Tests::killAllWindows(); - - NLog::log("{}Expecting 0 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 0); - - return true; } -static bool testWindowRuleWorkspaceEmpty() { - NLog::log("{}Testing windowrule workspace empty", Colors::YELLOW); - OK(getFromSocket("/reload")); - +TEST_CASE(windowruleWorkspaceEmpty) { OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_A' }, workspace = 'empty' })")); OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_B' }, workspace = 'emptyn' })")); getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"); if (!spawnKitty("kitty")) { - NLog::log("{}Error: failed to spawn kitty", Colors::RED); - return false; + FAIL_TEST("Could not spawn kitty"); } { @@ -622,8 +526,7 @@ static bool testWindowRuleWorkspaceEmpty() { } if (!spawnKitty("kitty_A")) { - NLog::log("{}Error: failed to spawn kitty", Colors::RED); - return false; + FAIL_TEST("Could not spawn kitty"); } { @@ -633,23 +536,16 @@ static bool testWindowRuleWorkspaceEmpty() { getFromSocket("/dispatch hl.dsp.focus({ workspace = '3' })"); if (!spawnKitty("kitty_B")) { - NLog::log("{}Error: failed to spawn kitty", Colors::RED); - return false; + FAIL_TEST("Could not spawn kitty"); } { auto str = getFromSocket("/activewindow"); EXPECT(str.contains("workspace: 4"), true); } - - Tests::killAllWindows(); - - return true; } -static bool testContentRules() { - NLog::log("{}Testing content window rules", Colors::YELLOW); - +TEST_CASE(contentWindowRules) { // kill me PLEASE OK(getFromSocket("/eval hl.window_rule({ match = { class = 'kitty_content_string' }, content = 'game' })")); @@ -657,33 +553,32 @@ static bool testContentRules() { OK(getFromSocket("/eval hl.window_rule({ match = { content = 'game' }, border_size = 10 })")); OK(getFromSocket("/eval hl.window_rule({ match = { content = '3' }, opacity = '0.5' })")); - const auto testProps = []() { - EXPECT_CONTAINS(getFromSocket("/getprop active border_size"), "10"); - EXPECT_CONTAINS(getFromSocket("/getprop active opacity"), "0.5"); - }; +#define TEST_PROPS() \ + EXPECT_CONTAINS(getFromSocket("/getprop active border_size"), "10"); \ + EXPECT_CONTAINS(getFromSocket("/getprop active opacity"), "0.5"); + if (!spawnKitty("kitty_content_string")) - return false; + FAIL_TEST("Could not spawn kitty_content_string"); waitForActiveWindow("kitty_content_string"); - testProps(); + TEST_PROPS(); Tests::killAllWindows(); - EXPECT(Tests::windowCount(), 0); + ASSERT(Tests::windowCount(), 0); if (!spawnKitty("kitty_content_numbers")) - return false; + FAIL_TEST("Could not spawn kitty_content_numbers"); waitForActiveWindow("kitty_content_numbers"); - testProps(); + TEST_PROPS(); Tests::killAllWindows(); - EXPECT(Tests::windowCount(), 0); - return true; -} + ASSERT(Tests::windowCount(), 0); -static bool test14038() { - NLog::log("{}Testing #14038 crash", Colors::YELLOW); +#undef TEST_PROPS +} +TEST_CASE(issue14038) { if (!spawnKitty("kitty_14038")) - return false; + FAIL_TEST("Could not spawn kitty"); OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = 'special:a', follow = false, window = 'class:kitty_14038' })")); OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle', window = 'class:kitty_14038' })")); @@ -691,21 +586,16 @@ static bool test14038() { OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'toggle', window = 'class:kitty_14038' })")); // this should not crash hyprland. If we are alive, we good. - - Tests::killAllWindows(); - EXPECT(Tests::windowCount(), 0); - return true; } -static bool test() { - NLog::log("{}Testing windows", Colors::GREEN); - +// TODO: decompose this into multiple test cases +TEST_CASE(windows) { // test on workspace "window" NLog::log("{}Switching to workspace `window`", Colors::YELLOW); getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:window' })"); if (!spawnKitty("kitty_A")) - return false; + FAIL_TEST("Could not spawn kitty"); // check kitty properties. One kitty should take the entire screen, as this is smart gaps NLog::log("{}Expecting kitty_A to take up the whole screen", Colors::YELLOW); @@ -749,7 +639,7 @@ static bool test() { OK(getFromSocket("/eval hl.config({ dwindle = { default_split_ratio = 1.25 } })")); if (!spawnKitty("kitty_B")) - return false; + FAIL_TEST("Could not spawn kitty"); NLog::log("{}Expecting kitty_B size: {},{}", Colors::YELLOW, WIDTH1, HEIGHT); EXPECT_CONTAINS(getFromSocket("/activewindow"), std::format("size: {},{}", WIDTH1, HEIGHT)); @@ -761,7 +651,7 @@ static bool test() { OK(getFromSocket("/eval hl.config({ dwindle = { default_split_ratio = 0.75 } })")); if (!spawnKitty("kitty_B")) - return false; + FAIL_TEST("Could not spawn kitty"); try { NLog::log("{}Expecting kitty_B size: {},{}", Colors::YELLOW, WIDTH2, HEIGHT); @@ -791,10 +681,7 @@ static bool test() { EXPECT_MAX_DELTA(std::stoi(std::string{sizes[1]}), HEIGHT, 2); } - } catch (...) { - NLog::log("{}Exception thrown", Colors::RED); - EXPECT(false, true); - } + } catch (...) { FAIL_TEST("Exception thrown"); } OK(getFromSocket("/eval hl.config({ dwindle = { default_split_ratio = 1 } })")); } @@ -807,7 +694,7 @@ static bool test() { Tests::waitUntilWindowsN(3); NLog::log("{}Expecting 3 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 3); + ASSERT(Tests::windowCount(), 3); NLog::log("{}Checking props of xeyes", Colors::YELLOW); // check some window props of xeyes, try to float it @@ -825,23 +712,16 @@ static bool test() { Tests::killAllWindows(); NLog::log("{}Expecting 0 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 0); - - testSwapWindow(); + ASSERT(Tests::windowCount(), 0); getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })"); - if (!testWindowFocusOnFullscreenConflict()) { - ret = 1; - return false; - } - NLog::log("{}Testing spawning a floating window over a fullscreen window", Colors::YELLOW); { if (!spawnKitty("kitty_A")) - return false; + FAIL_TEST("Could not spawn kitty"); OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })")); - EXPECT(Tests::windowCount(), 1); + ASSERT(Tests::windowCount(), 1); OK(getFromSocket("/dispatch hl.dsp.exec_cmd('kitty', { float = true })")); Tests::waitUntilWindowsN(2); @@ -869,7 +749,7 @@ static bool test() { OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-max-rule', max_size = '1500 500' })")); OK(getFromSocket("r/eval hl.window_rule({ name = 'kitty-max-rule', min_size = '1200 500' })")); if (!spawnKitty("kitty_maxsize")) - return false; + FAIL_TEST("Could not spawn kitty"); auto dwindle = getFromSocket("/activewindow"); EXPECT_CONTAINS(dwindle, "size: 1500,500"); @@ -881,19 +761,19 @@ static bool test() { // EXPECT_CONTAINS(getFromSocket("/activewindow"), "size: 1200,500"); Tests::killAllWindows(); - EXPECT(Tests::windowCount(), 0); + ASSERT(Tests::windowCount(), 0); OK(getFromSocket("r/eval hl.config({ general = { layout = 'master' } })")); if (!spawnKitty("kitty_maxsize")) - return false; + FAIL_TEST("Could not spawn kitty"); auto master = getFromSocket("/activewindow"); EXPECT_CONTAINS(master, "size: 1500,500"); EXPECT_CONTAINS(master, "at: 210,290"); if (!spawnKitty("kitty_maxsize")) - return false; + FAIL_TEST("Could not spawn kitty"); // FIXME: I can't be arsed. OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_maxsize' })")); @@ -902,7 +782,7 @@ static bool test() { NLog::log("{}Reloading config", Colors::YELLOW); OK(getFromSocket("/reload")); Tests::killAllWindows(); - EXPECT(Tests::windowCount(), 0); + ASSERT(Tests::windowCount(), 0); } NLog::log("{}Testing minsize/maxsize rules", Colors::YELLOW); @@ -913,7 +793,7 @@ static bool test() { OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-max-rule', max_size = '1500 500' })")); OK(getFromSocket("r/eval hl.window_rule({ name = 'kitty-max-rule', min_size = '1200 500' })")); if (!spawnKitty("kitty_maxsize")) - return false; + FAIL_TEST("Could not spawn kitty"); { auto res = getFromSocket("/getprop active max_size"); @@ -930,7 +810,7 @@ static bool test() { NLog::log("{}Reloading config", Colors::YELLOW); OK(getFromSocket("/reload")); Tests::killAllWindows(); - EXPECT(Tests::windowCount(), 0); + ASSERT(Tests::windowCount(), 0); } { @@ -940,7 +820,7 @@ static bool test() { OK(getFromSocket("r/eval hl.window_rule({ name = 'kitty-max-rule', min_size = '1200 500' })")); OK(getFromSocket("r/eval hl.window_rule({ name = 'kitty-max-rule', float = true })")); if (!spawnKitty("kitty_maxsize")) - return false; + FAIL_TEST("Could not spawn kitty"); { auto res = getFromSocket("/getprop active max_size"); @@ -962,12 +842,12 @@ static bool test() { NLog::log("{}Reloading config", Colors::YELLOW); OK(getFromSocket("/reload")); Tests::killAllWindows(); - EXPECT(Tests::windowCount(), 0); + ASSERT(Tests::windowCount(), 0); } NLog::log("{}Testing window rules", Colors::YELLOW); if (!spawnKitty("wr_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); { auto str = getFromSocket("/activewindow"); const int SIZE = 200; @@ -987,7 +867,7 @@ static bool test() { OK(getFromSocket("/eval hl.window_rule({ name = 'special-magic-kitty', workspace = 'special:magic' })")); if (!spawnKitty("magic_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); { auto str = getFromSocket("/activewindow"); @@ -1005,7 +885,7 @@ static bool test() { OK(getFromSocket("/eval hl.window_rule({ name = 'border-magic-kitty', border_color = 'rgba(c6ff00ff) rgba(ff0000ee) 45deg' })")); if (!spawnKitty("border_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:border_kitty' })")); @@ -1019,7 +899,7 @@ static bool test() { Tests::killAllWindows(); if (!spawnKitty("tag_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); { auto str = getFromSocket("/activewindow"); @@ -1034,7 +914,7 @@ static bool test() { OK(getFromSocket("/eval hl.window_rule({ match = { fullscreen = false }, border_size = 10 })")); if (!spawnKitty("overlap_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); { auto str = getFromSocket("/getprop active border_size"); @@ -1048,9 +928,9 @@ static bool test() { OK(getFromSocket("/eval hl.window_rule({ match = { class = 'persistent_size_kitty' }, persistent_size = true, float = true })")); if (!spawnKitty("persistent_size_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); - OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 600, y = 400 })")) + OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 600, y = 400 })")); { auto str = getFromSocket("/activewindow"); @@ -1061,7 +941,7 @@ static bool test() { Tests::killAllWindows(); if (!spawnKitty("persistent_size_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); { auto str = getFromSocket("/activewindow"); @@ -1076,7 +956,7 @@ static bool test() { OK(getFromSocket("/eval hl.window_rule({ match = { float = true }, border_size = 10 })")); if (!spawnKitty("border_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); { auto str = getFromSocket("/getprop active border_size"); @@ -1105,7 +985,7 @@ static bool test() { "max_size = 'monitor_w*0.75 monitor_h*0.75', move = '20+(monitor_w*0.1) monitor_h*0.5' })")); if (!spawnKitty("expr_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); { auto str = getFromSocket("/activewindow"); @@ -1131,7 +1011,7 @@ static bool test() { OK(getFromSocket("/eval hl.window_rule({ match = { class = 'plugin_kitty' }, plugin_rule = 'effect' })")); if (!spawnKitty("plugin_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); OK(getFromSocket("/eval hl.plugin.test.check_window_rule()")); @@ -1145,35 +1025,7 @@ static bool test() { OK(getFromSocket("/eval hl.window_rule({ name = 'test-plugin-rule', plugin_rule = 'effect' })")); if (!spawnKitty("plugin_kitty")) - return false; + FAIL_TEST("Could not spawn kitty"); OK(getFromSocket("/eval hl.plugin.test.check_window_rule()")); - - OK(getFromSocket("/reload")); - Tests::killAllWindows(); - - testGroupRules(); - testMaximizeSize(); - testFloatingFocusOnFullscreen(); - testBringActiveToTopMouseMovement(); - testGroupFallbackFocus(); - testInitialFloatSize(); - testWindowRuleFocusOnActivate(); - testPinnedWorkspacesValid(); - testWindowRuleWorkspaceEmpty(); - testContentRules(); - test14038(); - - NLog::log("{}Reloading config", Colors::YELLOW); - OK(getFromSocket("/reload")); - - NLog::log("{}Killing all windows", Colors::YELLOW); - Tests::killAllWindows(); - - NLog::log("{}Expecting 0 windows", Colors::YELLOW); - EXPECT(Tests::windowCount(), 0); - - return !ret; } - -REGISTER_TEST_FN(test) |
