aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Dionne-Riel <samuel@dionne-riel.com>2021-03-17 19:02:11 -0400
committerSamuel Dionne-Riel <samuel@dionne-riel.com>2021-03-19 15:20:47 -0400
commitbf07581497d55ade85d80e5d9ad9bf5d962e3403 (patch)
treee8beb9738723d2ead3e733e85807bc899a1994c5
parent1765711b68c8647b502c2c009dace9632e9300d7 (diff)
tests: Test `.config` stays clean with XDG_CONFIG_HOME set
-rw-r--r--tests/config.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/config.sh b/tests/config.sh
index 1edc09c1a..01c78f2c3 100644
--- a/tests/config.sh
+++ b/tests/config.sh
@@ -1,5 +1,31 @@
source common.sh
+# Isolate the home for this test.
+# Other tests (e.g. flake registry tests) could be writing to $HOME in parallel.
+export HOME=$TEST_ROOT/userhome
+
+# Test that using XDG_CONFIG_HOME works
+# Assert the config folder didn't exist initially.
+[ ! -e "$HOME/.config" ]
+# Without XDG_CONFIG_HOME, creates $HOME/.config
+unset XDG_CONFIG_HOME
+# Run against the nix registry to create the config dir
+# (Tip: this relies on removing non-existent entries being a no-op!)
+nix registry remove userhome-without-xdg
+# Verifies it created it
+[ -e "$HOME/.config" ]
+# Remove the directory it created
+rm -rf "$HOME/.config"
+# Run the same test, but with XDG_CONFIG_HOME
+export XDG_CONFIG_HOME=$TEST_ROOT/confighome
+# Assert the XDG_CONFIG_HOME/nix path does not exist yet.
+[ ! -e "$TEST_ROOT/confighome/nix" ]
+nix registry remove userhome-with-xdg
+# Verifies the confighome path has been created
+[ -e "$TEST_ROOT/confighome/nix" ]
+# Assert the .config folder hasn't been created.
+[ ! -e "$HOME/.config" ]
+
# Test that files are loaded from XDG by default
export XDG_CONFIG_HOME=$TEST_ROOT/confighome
export XDG_CONFIG_DIRS=$TEST_ROOT/dir1:$TEST_ROOT/dir2