forked from lix-project/lix
Merge "Test including relative paths in configuration" into main
This commit is contained in:
commit
72589e7032
|
@ -9,17 +9,10 @@
|
|||
#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
|
||||
|
|
16
tests/unit/libutil-support/tests/test-data.cc
Normal file
16
tests/unit/libutil-support/tests/test-data.cc
Normal file
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
1
tests/unit/libutil/data/puppy.conf
Normal file
1
tests/unit/libutil/data/puppy.conf
Normal file
|
@ -0,0 +1 @@
|
|||
puppy = doggy
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue