aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-08-26 09:28:14 -0700
committerRebecca Turner <rbt@sent.as>2024-09-01 15:52:48 -0700
commit75c0de3e3cbd972328c7d0c6fdea79abbfa204df (patch)
treefd7217cf74435eb1d9d5abfcd75df33caa02fe50 /tests
parent02eb07cfd539c34c080cb1baf042e5e780c1fcc2 (diff)
Test including relative paths in configuration
Change-Id: If6c69a5e16d1ccd223fba392890f08f0032fb754
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/libutil-support/tests/characterization.hh9
-rw-r--r--tests/unit/libutil-support/tests/test-data.cc16
-rw-r--r--tests/unit/libutil-support/tests/test-data.hh (renamed from tests/unit/libstore-support/tests/test-data.hh)13
-rw-r--r--tests/unit/libutil/config.cc33
-rw-r--r--tests/unit/libutil/data/puppy.conf1
-rw-r--r--tests/unit/meson.build2
6 files changed, 56 insertions, 18 deletions
diff --git a/tests/unit/libutil-support/tests/characterization.hh b/tests/unit/libutil-support/tests/characterization.hh
index db82476da..2bf606bd8 100644
--- a/tests/unit/libutil-support/tests/characterization.hh
+++ b/tests/unit/libutil-support/tests/characterization.hh
@@ -9,18 +9,11 @@
#include <filesystem>
#include "types.hh"
+#include "test-data.hh"
namespace nix {
/**
- * The path to the unit test data directory. See the contributing guide
- * in the manual for further details.
- */
-static Path getUnitTestData() {
- return getEnv("_NIX_TEST_UNIT_DATA").value();
-}
-
-/**
* Whether we should update "golden masters" instead of running tests
* against them. See the contributing guide in the manual for further
* details.
diff --git a/tests/unit/libutil-support/tests/test-data.cc b/tests/unit/libutil-support/tests/test-data.cc
new file mode 100644
index 000000000..016bd5e78
--- /dev/null
+++ b/tests/unit/libutil-support/tests/test-data.cc
@@ -0,0 +1,16 @@
+#include "test-data.hh"
+#include "strings.hh"
+
+namespace nix {
+
+Path getUnitTestData()
+{
+ return getEnv("_NIX_TEST_UNIT_DATA").value();
+}
+
+Path getUnitTestDataPath(std::string_view path)
+{
+ return absPath(getUnitTestData() + "/" + path);
+}
+
+}
diff --git a/tests/unit/libstore-support/tests/test-data.hh b/tests/unit/libutil-support/tests/test-data.hh
index 1fec6f912..794ec6265 100644
--- a/tests/unit/libstore-support/tests/test-data.hh
+++ b/tests/unit/libutil-support/tests/test-data.hh
@@ -1,25 +1,20 @@
#pragma once
-#include "environment-variables.hh"
#include "types.hh"
+#include "environment-variables.hh"
+#include "file-system.hh"
namespace nix {
-// TODO: These helpers should be available in all unit tests.
-
/**
* The path to the unit test data directory. See the contributing guide
* in the manual for further details.
*/
-static Path getUnitTestData() {
- return getEnv("_NIX_TEST_UNIT_DATA").value();
-}
+Path getUnitTestData();
/**
* Resolve a path under the unit test data directory to an absolute path.
*/
-static Path getUnitTestDataPath(std::string_view path) {
- return absPath(getUnitTestData() + "/" + path);
-}
+Path getUnitTestDataPath(std::string_view path);
}
diff --git a/tests/unit/libutil/config.cc b/tests/unit/libutil/config.cc
index 1629969ba..1600f4ff0 100644
--- a/tests/unit/libutil/config.cc
+++ b/tests/unit/libutil/config.cc
@@ -1,5 +1,9 @@
#include "config.hh"
#include "args.hh"
+#include "file-system.hh"
+#include "environment-variables.hh"
+#include "logging.hh"
+#include "tests/test-data.hh"
#include <sstream>
#include <gtest/gtest.h>
@@ -287,6 +291,35 @@ namespace nix {
), Error);
}
+ TEST(Config, includeRelativePath) {
+ Config config;
+ Setting<std::string> setting{&config, "", "puppy", "description"};
+
+ config.applyConfig("include puppy.conf", {
+ .path = getUnitTestDataPath("nix.conf")
+ });
+
+ std::map<std::string, Config::SettingInfo> settings;
+ config.getSettings(settings);
+ ASSERT_FALSE(settings.empty());
+ ASSERT_EQ(settings["puppy"].value, "doggy");
+ }
+
+ TEST(Config, includeTildePath) {
+ Config config;
+ Setting<std::string> setting{&config, "", "puppy", "description"};
+
+ config.applyConfig("include ~/puppy.conf", {
+ .path = "/doesnt-exist",
+ .home = getUnitTestData()
+ });
+
+ std::map<std::string, Config::SettingInfo> settings;
+ config.getSettings(settings);
+ ASSERT_FALSE(settings.empty());
+ ASSERT_EQ(settings["puppy"].value, "doggy");
+ }
+
TEST(Config, applyConfigInvalidThrows) {
Config config;
ASSERT_THROW(config.applyConfig("value == key"), UsageError);
diff --git a/tests/unit/libutil/data/puppy.conf b/tests/unit/libutil/data/puppy.conf
new file mode 100644
index 000000000..805e484ef
--- /dev/null
+++ b/tests/unit/libutil/data/puppy.conf
@@ -0,0 +1 @@
+puppy = doggy
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
index 55c7566bd..8ff0b5ec5 100644
--- a/tests/unit/meson.build
+++ b/tests/unit/meson.build
@@ -19,6 +19,7 @@ libutil_test_support_sources = files(
'libutil-support/tests/cli-literate-parser.cc',
'libutil-support/tests/hash.cc',
'libutil-support/tests/terminal-code-eater.cc',
+ 'libutil-support/tests/test-data.cc',
)
libutil_test_support = library(
'lixutil-test-support',
@@ -95,7 +96,6 @@ libstore_test_support_sources = files(
'libstore-support/tests/derived-path.cc',
'libstore-support/tests/outputs-spec.cc',
'libstore-support/tests/path.cc',
- 'libstore-support/tests/test-data.hh',
)
libstore_test_support = library(