aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-08-25 11:58:55 -0700
committerRebecca Turner <rbt@sent.as>2024-08-25 15:54:22 -0700
commit690f07272e58bfe86d12adb0bd6c81c031f930fd (patch)
treee01efa0e48d38eb44eb1d3445719a6adab29a33a /tests
parent5fc6fcb31035f79a8e590f07d73dc6cc592e9e29 (diff)
Support relative and `~/` paths in config settings
Change-Id: I5566a9858ba255f4ac5051d1368c7dfb24460f0a
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/libutil/paths-setting.cc55
1 files changed, 54 insertions, 1 deletions
diff --git a/tests/unit/libutil/paths-setting.cc b/tests/unit/libutil/paths-setting.cc
index c198b25e0..2d37ad525 100644
--- a/tests/unit/libutil/paths-setting.cc
+++ b/tests/unit/libutil/paths-setting.cc
@@ -48,7 +48,60 @@ TEST_F(PathsSettingTest, parse)
ASSERT_THAT(config.paths.parse("/puppy/../doggy.nix", {}), Eq<Paths>({"/doggy.nix"}));
}
-TEST_F(PathsSettingTest, append) {
+TEST_F(PathsSettingTest, parseRelative)
+{
+ auto options = ApplyConfigOptions{.path = "/doggy/kinds/config.nix"};
+ auto config = mkConfig();
+ ASSERT_THAT(
+ config.paths.parse("puppy.nix", options),
+ Eq<Paths>({"/doggy/kinds/puppy.nix"})
+ );
+
+ // Splits on whitespace:
+ ASSERT_THAT(
+ config.paths.parse("puppy.nix /doggy.nix", options), Eq<Paths>({"/doggy/kinds/puppy.nix", "/doggy.nix"})
+ );
+
+ // Canonicizes paths:
+ ASSERT_THAT(config.paths.parse("../soft.nix", options), Eq<Paths>({"/doggy/soft.nix"}));
+
+ // Canonicizes paths:
+ ASSERT_THAT(config.paths.parse("./soft.nix", options), Eq<Paths>({"/doggy/kinds/soft.nix"}));
+}
+
+TEST_F(PathsSettingTest, parseHome)
+{
+ auto options = ApplyConfigOptions{
+ .path = "/doggy/kinds/config.nix",
+ .home = "/home/puppy"
+ };
+ auto config = mkConfig();
+
+ ASSERT_THAT(
+ config.paths.parse("puppy.nix", options),
+ Eq<Paths>({"/doggy/kinds/puppy.nix"})
+ );
+
+ ASSERT_THAT(
+ config.paths.parse("~/.config/nix/puppy.nix", options),
+ Eq<Paths>({"/home/puppy/.config/nix/puppy.nix"})
+ );
+
+ // Splits on whitespace:
+ ASSERT_THAT(
+ config.paths.parse("~/puppy.nix ~/doggy.nix", options),
+ Eq<Paths>({"/home/puppy/puppy.nix", "/home/puppy/doggy.nix"})
+ );
+
+ // Canonicizes paths:
+ ASSERT_THAT(config.paths.parse("~/../why.nix", options), Eq<Paths>({"/home/why.nix"}));
+
+ // Home paths for other users not allowed. Needs to start with `~/`.
+ ASSERT_THROW(config.paths.parse("~root/config.nix", options), Error);
+}
+
+TEST_F(PathsSettingTest, append)
+{
auto config = mkConfig();
ASSERT_TRUE(config.paths.isAppendable());