nixosTests.sway: factor out swaymsg

This commit is contained in:
Patrick Hilhorst 2022-02-03 20:00:58 +01:00
parent aca22fb124
commit c39cc2e840
No known key found for this signature in database
GPG key ID: 3BB083304DADC0FF

View file

@ -68,6 +68,14 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
enableOCR = true; enableOCR = true;
testScript = { nodes, ... }: '' testScript = { nodes, ... }: ''
import shlex
def swaymsg(command: str, succeed=True):
with machine.nested(f"sending swaymsg {command!r}" + " (allowed to fail)" * (not succeed)):
(machine.succeed if succeed else machine.execute)(
f"su - alice -c {shlex.quote('swaymsg -- ' + command)}"
)
start_all() start_all()
machine.wait_for_unit("multi-user.target") machine.wait_for_unit("multi-user.target")
@ -79,9 +87,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
machine.wait_for_file("/tmp/sway-ipc.sock") machine.wait_for_file("/tmp/sway-ipc.sock")
# Test XWayland (foot does not support X): # Test XWayland (foot does not support X):
machine.succeed( swaymsg("exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty")
"su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty'"
)
machine.wait_for_text("alice@machine") machine.wait_for_text("alice@machine")
machine.send_chars("test-x11\n") machine.send_chars("test-x11\n")
machine.wait_for_file("/tmp/test-x11-exit-ok") machine.wait_for_file("/tmp/test-x11-exit-ok")
@ -105,9 +111,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
# Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if # Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if
# $WAYLAND_DISPLAY is correctly imported into the D-Bus user env): # $WAYLAND_DISPLAY is correctly imported into the D-Bus user env):
machine.succeed( swaymsg("exec gpg --no-tty --yes --quick-generate-key test")
"su - alice -c 'swaymsg -- exec gpg --no-tty --yes --quick-generate-key test'"
)
machine.wait_until_succeeds("pgrep --exact gpg") machine.wait_until_succeeds("pgrep --exact gpg")
machine.wait_for_text("Passphrase") machine.wait_for_text("Passphrase")
machine.screenshot("gpg_pinentry") machine.screenshot("gpg_pinentry")
@ -120,7 +124,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
machine.screenshot("sway_exit") machine.screenshot("sway_exit")
# Exit Sway and verify process exit status 0: # Exit Sway and verify process exit status 0:
machine.succeed("su - alice -c 'swaymsg exit || true'") swaymsg("exit", succeed=False)
machine.wait_until_fails("pgrep -x sway") machine.wait_until_fails("pgrep -x sway")
machine.wait_for_file("/tmp/sway-exit-ok") machine.wait_for_file("/tmp/sway-exit-ok")
''; '';