aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2020-04-24 21:41:22 +0200
committerRobert Helgesson <robert@rycee.net>2020-04-24 21:46:34 +0200
commit95b95b14075aca3eea5a747aad2e24606f2f0fea (patch)
treee0e25f8328511aa63bff1fd8e4e268c59f478094 /tests
parentcfaf2139801aef64add340db037c64eaacfae670 (diff)
tests: improve test purity
Before the XDG variables would be set from the user's environment, if available. This would break some tests. With this change the tests should be fully deterministic. Fixes #1190
Diffstat (limited to 'tests')
-rw-r--r--tests/default.nix10
-rw-r--r--tests/modules/home-environment/session-variables-expected.txt3
-rw-r--r--tests/modules/misc/xsession/basic-xprofile-expected.txt2
-rw-r--r--tests/modules/misc/xsession/basic.nix2
-rw-r--r--tests/modules/misc/xsession/keyboard-without-layout.nix2
-rw-r--r--tests/modules/programs/bash/session-variables-expected.txt2
-rw-r--r--tests/modules/programs/bash/session-variables.nix2
-rw-r--r--tests/modules/programs/getmail/getmail.nix3
-rw-r--r--tests/modules/programs/lieer/lieer.nix3
-rw-r--r--tests/modules/programs/mbsync/mbsync.nix3
-rw-r--r--tests/modules/programs/neomutt/neomutt-with-msmtp.nix5
-rw-r--r--tests/modules/programs/neomutt/neomutt.nix5
-rw-r--r--tests/modules/programs/tmux/hm-session-vars.sh5
-rw-r--r--tests/modules/programs/tmux/secure-socket-enabled.nix5
-rw-r--r--tests/modules/services/lieer/lieer-service.nix3
-rw-r--r--tests/modules/targets/generic-linux-session-vars-expected.txt6
-rw-r--r--tests/modules/targets/generic-linux.nix14
17 files changed, 21 insertions, 54 deletions
diff --git a/tests/default.nix b/tests/default.nix
index b29b27acebe..9eb5afcde0e 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -14,7 +14,15 @@ let
modules = import ../modules/modules.nix {
inherit lib pkgs;
check = false;
- };
+ } ++ [
+ # Fix impurities. Without these some of the user's environment
+ # will leak into the tests through `builtins.getEnv`.
+ {
+ xdg.enable = true;
+ home.username = "hm-user";
+ home.homeDirectory = "/home/hm-user";
+ }
+ ];
in
diff --git a/tests/modules/home-environment/session-variables-expected.txt b/tests/modules/home-environment/session-variables-expected.txt
index 5c3868c3901..4e18e2b31a8 100644
--- a/tests/modules/home-environment/session-variables-expected.txt
+++ b/tests/modules/home-environment/session-variables-expected.txt
@@ -4,3 +4,6 @@ export __HM_SESS_VARS_SOURCED=1
export V1="v1"
export V2="v2-v1"
+export XDG_CACHE_HOME="/home/hm-user/.cache"
+export XDG_CONFIG_HOME="/home/hm-user/.config"
+export XDG_DATA_HOME="/home/hm-user/.local/share"
diff --git a/tests/modules/misc/xsession/basic-xprofile-expected.txt b/tests/modules/misc/xsession/basic-xprofile-expected.txt
index 05733a974ff..282f8f5c5de 100644
--- a/tests/modules/misc/xsession/basic-xprofile-expected.txt
+++ b/tests/modules/misc/xsession/basic-xprofile-expected.txt
@@ -1,4 +1,4 @@
-. "/test-home/.nix-profile/etc/profile.d/hm-session-vars.sh"
+. "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh"
if [ -e "$HOME/.profile" ]; then
. "$HOME/.profile"
diff --git a/tests/modules/misc/xsession/basic.nix b/tests/modules/misc/xsession/basic.nix
index 39df6362380..d6756291cfe 100644
--- a/tests/modules/misc/xsession/basic.nix
+++ b/tests/modules/misc/xsession/basic.nix
@@ -4,8 +4,6 @@ with lib;
{
config = {
- home.homeDirectory = "/test-home";
-
xsession = {
enable = true;
windowManager.command = "window manager command";
diff --git a/tests/modules/misc/xsession/keyboard-without-layout.nix b/tests/modules/misc/xsession/keyboard-without-layout.nix
index 015efe6154a..90038cfd034 100644
--- a/tests/modules/misc/xsession/keyboard-without-layout.nix
+++ b/tests/modules/misc/xsession/keyboard-without-layout.nix
@@ -6,8 +6,6 @@ with lib;
config = {
home.stateVersion = "19.09";
- home.homeDirectory = "/test-home";
-
home.keyboard = { options = [ "ctrl:nocaps" "altwin:no_win" ]; };
xsession = {
diff --git a/tests/modules/programs/bash/session-variables-expected.txt b/tests/modules/programs/bash/session-variables-expected.txt
index e13d63d4c78..0d93217a915 100644
--- a/tests/modules/programs/bash/session-variables-expected.txt
+++ b/tests/modules/programs/bash/session-variables-expected.txt
@@ -1,6 +1,6 @@
# -*- mode: sh -*-
-. "/home/testuser/.nix-profile/etc/profile.d/hm-session-vars.sh"
+. "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh"
export V1="v1"
export V2="v2-v1"
diff --git a/tests/modules/programs/bash/session-variables.nix b/tests/modules/programs/bash/session-variables.nix
index ea789a1d061..1ef65a34442 100644
--- a/tests/modules/programs/bash/session-variables.nix
+++ b/tests/modules/programs/bash/session-variables.nix
@@ -13,8 +13,6 @@ with lib;
};
};
- home.homeDirectory = "/home/testuser";
-
nmt.script = ''
assertFileExists home-files/.profile
assertFileContent \
diff --git a/tests/modules/programs/getmail/getmail.nix b/tests/modules/programs/getmail/getmail.nix
index fe10b98f981..b0d979c4672 100644
--- a/tests/modules/programs/getmail/getmail.nix
+++ b/tests/modules/programs/getmail/getmail.nix
@@ -6,9 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ];
config = {
- home.username = "hm-user";
- home.homeDirectory = "/home/hm-user";
-
accounts.email.accounts = {
"hm@example.com" = {
getmail = {
diff --git a/tests/modules/programs/lieer/lieer.nix b/tests/modules/programs/lieer/lieer.nix
index 1671f4f5e3b..2ce4fb4e031 100644
--- a/tests/modules/programs/lieer/lieer.nix
+++ b/tests/modules/programs/lieer/lieer.nix
@@ -6,9 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ];
config = {
- home.username = "hm-user";
- home.homeDirectory = "/home/hm-user";
-
programs.lieer.enable = true;
accounts.email.accounts = { "hm@example.com".lieer.enable = true; };
diff --git a/tests/modules/programs/mbsync/mbsync.nix b/tests/modules/programs/mbsync/mbsync.nix
index 03a54c178f5..fa8e28cb4a6 100644
--- a/tests/modules/programs/mbsync/mbsync.nix
+++ b/tests/modules/programs/mbsync/mbsync.nix
@@ -6,9 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ];
config = {
- home.username = "hm-user";
- home.homeDirectory = "/home/hm-user";
-
programs.mbsync = {
enable = true;
groups.inboxes = {
diff --git a/tests/modules/programs/neomutt/neomutt-with-msmtp.nix b/tests/modules/programs/neomutt/neomutt-with-msmtp.nix
index 5f94d21a144..22f65599cf4 100644
--- a/tests/modules/programs/neomutt/neomutt-with-msmtp.nix
+++ b/tests/modules/programs/neomutt/neomutt-with-msmtp.nix
@@ -6,11 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ];
config = {
- home.username = "hm-user";
- home.homeDirectory = "/home/hm-user";
- xdg.configHome = mkForce "/home/hm-user/.config";
- xdg.cacheHome = mkForce "/home/hm-user/.cache";
-
accounts.email.accounts = {
"hm@example.com" = {
primary = true;
diff --git a/tests/modules/programs/neomutt/neomutt.nix b/tests/modules/programs/neomutt/neomutt.nix
index 91cb9dca249..c0caa44af4a 100644
--- a/tests/modules/programs/neomutt/neomutt.nix
+++ b/tests/modules/programs/neomutt/neomutt.nix
@@ -6,11 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ];
config = {
- home.username = "hm-user";
- home.homeDirectory = "/home/hm-user";
- xdg.configHome = mkForce "/home/hm-user/.config";
- xdg.cacheHome = mkForce "/home/hm-user/.cache";
-
accounts.email.accounts = {
"hm@example.com" = {
primary = true;
diff --git a/tests/modules/programs/tmux/hm-session-vars.sh b/tests/modules/programs/tmux/hm-session-vars.sh
deleted file mode 100644
index 40d9c24b50d..00000000000
--- a/tests/modules/programs/tmux/hm-session-vars.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-# Only source this once.
-if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
-export __HM_SESS_VARS_SOURCED=1
-
-export TMUX_TMPDIR="${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}"
diff --git a/tests/modules/programs/tmux/secure-socket-enabled.nix b/tests/modules/programs/tmux/secure-socket-enabled.nix
index 7e8c535c049..ca2de66310d 100644
--- a/tests/modules/programs/tmux/secure-socket-enabled.nix
+++ b/tests/modules/programs/tmux/secure-socket-enabled.nix
@@ -11,9 +11,8 @@ with lib;
nmt.script = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
- assertFileContent home-path/etc/profile.d/hm-session-vars.sh ${
- ./hm-session-vars.sh
- }
+ assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
+ 'export TMUX_TMPDIR="''${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}"'
'';
};
}
diff --git a/tests/modules/services/lieer/lieer-service.nix b/tests/modules/services/lieer/lieer-service.nix
index faef5053c5f..03dcdc749b1 100644
--- a/tests/modules/services/lieer/lieer-service.nix
+++ b/tests/modules/services/lieer/lieer-service.nix
@@ -6,9 +6,6 @@ with lib;
imports = [ ../../accounts/email-test-accounts.nix ];
config = {
- home.username = "hm-user";
- home.homeDirectory = "/home/hm-user";
-
services.lieer.enable = true;
accounts.email.accounts = {
diff --git a/tests/modules/targets/generic-linux-session-vars-expected.txt b/tests/modules/targets/generic-linux-session-vars-expected.txt
deleted file mode 100644
index ad9e0ada63f..00000000000
--- a/tests/modules/targets/generic-linux-session-vars-expected.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-# Only source this once.
-if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
-export __HM_SESS_VARS_SOURCED=1
-
-export XDG_DATA_DIRS="/nix/var/nix/profiles/default/share:/homeless-shelter/.nix-profile/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"
-. "@nix@/etc/profile.d/nix.sh"
diff --git a/tests/modules/targets/generic-linux.nix b/tests/modules/targets/generic-linux.nix
index 2e06b2545d5..8596ac3d93a 100644
--- a/tests/modules/targets/generic-linux.nix
+++ b/tests/modules/targets/generic-linux.nix
@@ -4,20 +4,16 @@ with lib;
{
config = {
- home.homeDirectory = "/homeless-shelter";
-
targets.genericLinux.enable = true;
nmt.script = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
- assertFileContent \
+ assertFileContains \
+ home-path/etc/profile.d/hm-session-vars.sh \
+ 'export XDG_DATA_DIRS="/nix/var/nix/profiles/default/share:/home/hm-user/.nix-profile/share''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"'
+ assertFileContains \
home-path/etc/profile.d/hm-session-vars.sh \
- ${
- pkgs.substituteAll {
- src = ./generic-linux-session-vars-expected.txt;
- nix = pkgs.nix;
- }
- }
+ '. "${pkgs.nix}/etc/profile.d/nix.sh"'
'';
};
}