at 23.05-pre 3.7 kB view raw
1import ./make-test-python.nix ({ pkgs, ...}: 2 3let 4 mkConfig = name: keys: '' 5 import XMonad 6 import XMonad.Operations (restart) 7 import XMonad.Util.EZConfig 8 import XMonad.Util.SessionStart 9 import Control.Monad (when) 10 import Text.Printf (printf) 11 import System.Posix.Process (executeFile) 12 import System.Info (arch,os) 13 import System.Environment (getArgs) 14 import System.FilePath ((</>)) 15 16 main = do 17 dirs <- getDirectories 18 launch (def { startupHook = startup } `additionalKeysP` myKeys) dirs 19 20 startup = isSessionStart >>= \sessInit -> 21 spawn "touch /tmp/${name}" 22 >> if sessInit then setSessionStarted else spawn "xterm" 23 24 myKeys = [${builtins.concatStringsSep ", " keys}] 25 26 compiledConfig = printf "xmonad-%s-%s" arch os 27 28 compileRestart resume = do 29 dirs <- asks directories 30 31 whenX (recompile dirs True) $ 32 when resume writeStateToFile 33 *> catchIO 34 ( do 35 args <- getArgs 36 executeFile (cacheDir dirs </> compiledConfig) False args Nothing 37 ) 38 ''; 39 40 oldKeys = 41 [ ''("M-C-x", spawn "xterm")'' 42 ''("M-q", restart "xmonad" True)'' 43 ''("M-C-q", compileRestart True)'' 44 ''("M-C-t", spawn "touch /tmp/somefile")'' # create somefile 45 ]; 46 47 newKeys = 48 [ ''("M-C-x", spawn "xterm")'' 49 ''("M-q", restart "xmonad" True)'' 50 ''("M-C-q", compileRestart True)'' 51 ''("M-C-r", spawn "rm /tmp/somefile")'' # delete somefile 52 ]; 53 54 newConfig = pkgs.writeText "xmonad.hs" (mkConfig "newXMonad" newKeys); 55in { 56 name = "xmonad"; 57 meta = with pkgs.lib.maintainers; { 58 maintainers = [ nequissimus ivanbrennan ]; 59 }; 60 61 nodes.machine = { pkgs, ... }: { 62 imports = [ ./common/x11.nix ./common/user-account.nix ]; 63 test-support.displayManager.auto.user = "alice"; 64 services.xserver.displayManager.defaultSession = "none+xmonad"; 65 services.xserver.windowManager.xmonad = { 66 enable = true; 67 enableConfiguredRecompile = true; 68 enableContribAndExtras = true; 69 extraPackages = with pkgs.haskellPackages; haskellPackages: [ xmobar ]; 70 config = mkConfig "oldXMonad" oldKeys; 71 }; 72 }; 73 74 testScript = { nodes, ... }: let 75 user = nodes.machine.config.users.users.alice; 76 in '' 77 machine.wait_for_x() 78 machine.wait_for_file("${user.home}/.Xauthority") 79 machine.succeed("xauth merge ${user.home}/.Xauthority") 80 machine.send_key("alt-ctrl-x") 81 machine.wait_for_window("${user.name}.*machine") 82 machine.sleep(1) 83 machine.screenshot("terminal1") 84 machine.succeed("rm /tmp/oldXMonad") 85 machine.send_key("alt-q") 86 machine.wait_for_file("/tmp/oldXMonad") 87 machine.wait_for_window("${user.name}.*machine") 88 machine.sleep(1) 89 machine.screenshot("terminal2") 90 91 # /tmp/somefile should not exist yet 92 machine.fail("stat /tmp/somefile") 93 94 # original config has a keybinding that creates somefile 95 machine.send_key("alt-ctrl-t") 96 machine.wait_for_file("/tmp/somefile") 97 98 # set up the new config 99 machine.succeed("mkdir -p ${user.home}/.xmonad") 100 machine.copy_from_host("${newConfig}", "${user.home}/.config/xmonad/xmonad.hs") 101 102 # recompile xmonad using the new config 103 machine.send_key("alt-ctrl-q") 104 machine.wait_for_file("/tmp/newXMonad") 105 106 # new config has a keybinding that deletes somefile 107 machine.send_key("alt-ctrl-r") 108 machine.wait_until_fails("stat /tmp/somefile", timeout=30) 109 110 # restart with the old config, and confirm the old keybinding is back 111 machine.succeed("rm /tmp/oldXMonad") 112 machine.send_key("alt-q") 113 machine.wait_for_file("/tmp/oldXMonad") 114 machine.send_key("alt-ctrl-t") 115 machine.wait_for_file("/tmp/somefile") 116 ''; 117})