plasma-manager/test/basic.nix

98 lines
2.7 KiB
Nix
Raw Normal View History

{ testers, home-manager-module, plasma-module, writeShellScriptBin, kdePackages }:
2022-06-22 22:10:51 +03:00
let
2024-02-26 19:58:45 +03:00
script = writeShellScriptBin "plasma-basic-test" ''
set -eu
2022-06-22 22:10:51 +03:00
export XDG_CONFIG_HOME=''${XDG_CONFIG_HOME:-$HOME/.config}
export PATH=${kdePackages.kconfig}/bin:$PATH
2022-06-22 22:10:51 +03:00
kread_global() {
kreadconfig5 --file $XDG_CONFIG_HOME/kdeglobals "$@"
2022-06-22 22:10:51 +03:00
}
assert_eq() {
want=$1
shift
actual=$(kread_global "$@")
2022-06-22 22:10:51 +03:00
if [ "$actual" != "$want" ]; then
echo >&2 "ERROR: $@: expected $want but got $actual"
2022-06-22 22:10:51 +03:00
exit 1
fi
}
assert_eq false --group KDE --key SingleClick
assert_eq true --group General --key AllowKDEAppsToRememberWindowPositions
# Set with shorthand
assert_eq 1 --group group --key key1
# Set with longhand and immutable
assert_eq 2 --group group --key key2
# Nested groups, with group containing /
assert_eq 3 --group escaped/nested --group group --key key3
# Value and key have leading space
assert_eq " leading space" --group group --key " leading space"
# Set outside plasma-manager, value has leading space, group contains /
assert_eq " value" --group escaped/nested --group group --key untouched
# Escaped key with shell expansion
assert_eq "/home/fake" --group group --key 'escaped[$i]'
2022-06-22 22:10:51 +03:00
'';
2024-02-26 19:58:45 +03:00
in
testers.nixosTest {
name = "plasma-basic";
2022-06-22 22:10:51 +03:00
2024-02-26 19:58:45 +03:00
nodes.machine = {
environment.systemPackages = [ script ];
imports = [ home-manager-module ];
2022-06-22 22:10:51 +03:00
2024-02-26 19:58:45 +03:00
users.users.fake = {
createHome = true;
isNormalUser = true;
2022-06-22 22:10:51 +03:00
};
home-manager.users.fake = { lib, ... }: {
2024-02-26 19:58:45 +03:00
home.stateVersion = "23.11";
imports = [ plasma-module ];
programs.plasma = {
enable = true;
workspace.clickItemTo = "select";
# Test a variety of weird keys and groups
configFile.kdeglobals = {
group = {
" leading space" = " leading space";
key1 = 1;
key2 = {
value = 2;
immutable = true;
};
"escaped[$i]" = {
value = "\${HOME}";
shellExpand = true;
};
};
"escaped\\/nested/group" = {
key3 = 3;
};
};
2024-02-26 19:58:45 +03:00
};
home.activation.preseed = lib.hm.dag.entryBefore [ "configure-plasma" ] ''
mkdir -p ~/.config
cat <<EOF >> ~/.config/kdeglobals
[escaped/nested][group]
untouched = \svalue
EOF
'';
2024-02-26 19:58:45 +03:00
};
2022-06-22 22:10:51 +03:00
};
testScript = ''
# Boot:
start_all()
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("home-manager-fake.service")
# Run tests:
machine.succeed("test -e /home/fake/.config/kdeglobals")
machine.succeed("su - fake -c plasma-basic-test")
'';
}