nixosTests.xmonad: migrate to runTest

Part Of #386873
This commit is contained in:
Martin Weinelt 2025-03-14 23:21:51 +01:00
parent 4ada7d8158
commit ead8dabde0
No known key found for this signature in database
GPG Key ID: 87C1E9888F856759
2 changed files with 111 additions and 113 deletions

View File

@ -1289,7 +1289,7 @@ in {
xautolock = handleTest ./xautolock.nix {}; xautolock = handleTest ./xautolock.nix {};
xfce = handleTest ./xfce.nix {}; xfce = handleTest ./xfce.nix {};
xfce-wayland = handleTest ./xfce-wayland.nix {}; xfce-wayland = handleTest ./xfce-wayland.nix {};
xmonad = handleTest ./xmonad.nix {}; xmonad = runTest ./xmonad.nix;
xmonad-xdg-autostart = runTest ./xmonad-xdg-autostart.nix; xmonad-xdg-autostart = runTest ./xmonad-xdg-autostart.nix;
xpadneo = runTest ./xpadneo.nix; xpadneo = runTest ./xpadneo.nix;
xrdp = runTest ./xrdp.nix; xrdp = runTest ./xrdp.nix;

View File

@ -1,131 +1,129 @@
import ./make-test-python.nix ( { pkgs, ... }:
{ pkgs, ... }:
let let
mkConfig = name: keys: '' mkConfig = name: keys: ''
import XMonad import XMonad
import XMonad.Operations (restart) import XMonad.Operations (restart)
import XMonad.Util.EZConfig import XMonad.Util.EZConfig
import XMonad.Util.SessionStart import XMonad.Util.SessionStart
import Control.Monad (when) import Control.Monad (when)
import Text.Printf (printf) import Text.Printf (printf)
import System.Posix.Process (executeFile) import System.Posix.Process (executeFile)
import System.Info (arch,os) import System.Info (arch,os)
import System.Environment (getArgs) import System.Environment (getArgs)
import System.FilePath ((</>)) import System.FilePath ((</>))
main = do main = do
dirs <- getDirectories dirs <- getDirectories
launch (def { startupHook = startup } `additionalKeysP` myKeys) dirs launch (def { startupHook = startup } `additionalKeysP` myKeys) dirs
startup = isSessionStart >>= \sessInit -> startup = isSessionStart >>= \sessInit ->
spawn "touch /tmp/${name}" spawn "touch /tmp/${name}"
>> if sessInit then setSessionStarted else spawn "xterm" >> if sessInit then setSessionStarted else spawn "xterm"
myKeys = [${builtins.concatStringsSep ", " keys}] myKeys = [${builtins.concatStringsSep ", " keys}]
compiledConfig = printf "xmonad-%s-%s" arch os compiledConfig = printf "xmonad-%s-%s" arch os
compileRestart resume = do compileRestart resume = do
dirs <- asks directories dirs <- asks directories
whenX (recompile dirs True) $ whenX (recompile dirs True) $
when resume writeStateToFile when resume writeStateToFile
*> catchIO *> catchIO
( do ( do
args <- getArgs args <- getArgs
executeFile (cacheDir dirs </> compiledConfig) False args Nothing executeFile (cacheDir dirs </> compiledConfig) False args Nothing
) )
''; '';
oldKeys = [ oldKeys = [
''("M-C-x", spawn "xterm")'' ''("M-C-x", spawn "xterm")''
''("M-q", restart "xmonad" True)'' ''("M-q", restart "xmonad" True)''
''("M-C-q", compileRestart True)'' ''("M-C-q", compileRestart True)''
''("M-C-t", spawn "touch /tmp/somefile")'' # create somefile ''("M-C-t", spawn "touch /tmp/somefile")'' # create somefile
];
newKeys = [
''("M-C-x", spawn "xterm")''
''("M-q", restart "xmonad" True)''
''("M-C-q", compileRestart True)''
''("M-C-r", spawn "rm /tmp/somefile")'' # delete somefile
];
newConfig = pkgs.writeText "xmonad.hs" (mkConfig "newXMonad" newKeys);
in
{
name = "xmonad";
meta = with pkgs.lib.maintainers; {
maintainers = [
nequissimus
ivanbrennan
]; ];
};
newKeys = [ nodes.machine =
''("M-C-x", spawn "xterm")'' { pkgs, ... }:
''("M-q", restart "xmonad" True)'' {
''("M-C-q", compileRestart True)'' imports = [
''("M-C-r", spawn "rm /tmp/somefile")'' # delete somefile ./common/x11.nix
]; ./common/user-account.nix
newConfig = pkgs.writeText "xmonad.hs" (mkConfig "newXMonad" newKeys);
in
{
name = "xmonad";
meta = with pkgs.lib.maintainers; {
maintainers = [
nequissimus
ivanbrennan
]; ];
test-support.displayManager.auto.user = "alice";
services.displayManager.defaultSession = "none+xmonad";
services.xserver.windowManager.xmonad = {
enable = true;
enableConfiguredRecompile = true;
enableContribAndExtras = true;
extraPackages = with pkgs.haskellPackages; haskellPackages: [ xmobar ];
config = mkConfig "oldXMonad" oldKeys;
};
}; };
nodes.machine = testScript =
{ pkgs, ... }: { nodes, ... }:
{ let
imports = [ user = nodes.machine.users.users.alice;
./common/x11.nix in
./common/user-account.nix ''
]; machine.wait_for_x()
test-support.displayManager.auto.user = "alice"; machine.wait_for_file("${user.home}/.Xauthority")
services.displayManager.defaultSession = "none+xmonad"; machine.succeed("xauth merge ${user.home}/.Xauthority")
services.xserver.windowManager.xmonad = { machine.send_key("alt-ctrl-x")
enable = true; machine.wait_for_window("${user.name}.*machine")
enableConfiguredRecompile = true; machine.sleep(1)
enableContribAndExtras = true; machine.screenshot("terminal1")
extraPackages = with pkgs.haskellPackages; haskellPackages: [ xmobar ]; machine.succeed("rm /tmp/oldXMonad")
config = mkConfig "oldXMonad" oldKeys; machine.send_key("alt-q")
}; machine.wait_for_file("/tmp/oldXMonad")
}; machine.wait_for_window("${user.name}.*machine")
machine.sleep(1)
machine.screenshot("terminal2")
testScript = # /tmp/somefile should not exist yet
{ nodes, ... }: machine.fail("stat /tmp/somefile")
let
user = nodes.machine.config.users.users.alice;
in
''
machine.wait_for_x()
machine.wait_for_file("${user.home}/.Xauthority")
machine.succeed("xauth merge ${user.home}/.Xauthority")
machine.send_key("alt-ctrl-x")
machine.wait_for_window("${user.name}.*machine")
machine.sleep(1)
machine.screenshot("terminal1")
machine.succeed("rm /tmp/oldXMonad")
machine.send_key("alt-q")
machine.wait_for_file("/tmp/oldXMonad")
machine.wait_for_window("${user.name}.*machine")
machine.sleep(1)
machine.screenshot("terminal2")
# /tmp/somefile should not exist yet # original config has a keybinding that creates somefile
machine.fail("stat /tmp/somefile") machine.send_key("alt-ctrl-t")
machine.wait_for_file("/tmp/somefile")
# original config has a keybinding that creates somefile # set up the new config
machine.send_key("alt-ctrl-t") machine.succeed("mkdir -p ${user.home}/.xmonad")
machine.wait_for_file("/tmp/somefile") machine.copy_from_host("${newConfig}", "${user.home}/.config/xmonad/xmonad.hs")
# set up the new config # recompile xmonad using the new config
machine.succeed("mkdir -p ${user.home}/.xmonad") machine.send_key("alt-ctrl-q")
machine.copy_from_host("${newConfig}", "${user.home}/.config/xmonad/xmonad.hs") machine.wait_for_file("/tmp/newXMonad")
# recompile xmonad using the new config # new config has a keybinding that deletes somefile
machine.send_key("alt-ctrl-q") machine.send_key("alt-ctrl-r")
machine.wait_for_file("/tmp/newXMonad") machine.wait_until_fails("stat /tmp/somefile", timeout=30)
# new config has a keybinding that deletes somefile # restart with the old config, and confirm the old keybinding is back
machine.send_key("alt-ctrl-r") machine.succeed("rm /tmp/oldXMonad")
machine.wait_until_fails("stat /tmp/somefile", timeout=30) machine.send_key("alt-q")
machine.wait_for_file("/tmp/oldXMonad")
# restart with the old config, and confirm the old keybinding is back machine.send_key("alt-ctrl-t")
machine.succeed("rm /tmp/oldXMonad") machine.wait_for_file("/tmp/somefile")
machine.send_key("alt-q") '';
machine.wait_for_file("/tmp/oldXMonad") }
machine.send_key("alt-ctrl-t")
machine.wait_for_file("/tmp/somefile")
'';
}
)