mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
Merge pull request #10562 from hercules-ci/unit-test-clean-config
Run unit tests with clean config
This commit is contained in:
commit
d871e7cc5b
7 changed files with 28 additions and 8 deletions
|
@ -113,7 +113,7 @@ static void sigHandler(int signo) { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void initNix()
|
void initNix(bool loadConfig)
|
||||||
{
|
{
|
||||||
/* Turn on buffering for cerr. */
|
/* Turn on buffering for cerr. */
|
||||||
#if HAVE_PUBSETBUF
|
#if HAVE_PUBSETBUF
|
||||||
|
@ -121,7 +121,7 @@ void initNix()
|
||||||
std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
|
std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
initLibStore();
|
initLibStore(loadConfig);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
unix::startSignalHandlerThread();
|
unix::startSignalHandlerThread();
|
||||||
|
|
|
@ -21,8 +21,9 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Don't forget to call initPlugins() after settings are initialized!
|
* Don't forget to call initPlugins() after settings are initialized!
|
||||||
|
* @param loadConfig Whether to load configuration from `nix.conf`, `NIX_CONFIG`, etc. May be disabled for unit tests.
|
||||||
*/
|
*/
|
||||||
void initNix();
|
void initNix(bool loadConfig = true);
|
||||||
|
|
||||||
void parseCmdLine(int argc, char * * argv,
|
void parseCmdLine(int argc, char * * argv,
|
||||||
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg);
|
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg);
|
||||||
|
|
|
@ -19,6 +19,16 @@ nix_err nix_libstore_init(nix_c_context * context)
|
||||||
NIXC_CATCH_ERRS
|
NIXC_CATCH_ERRS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nix_err nix_libstore_init_no_load_config(nix_c_context * context)
|
||||||
|
{
|
||||||
|
if (context)
|
||||||
|
context->last_err_code = NIX_OK;
|
||||||
|
try {
|
||||||
|
nix::initLibStore(false);
|
||||||
|
}
|
||||||
|
NIXC_CATCH_ERRS
|
||||||
|
}
|
||||||
|
|
||||||
nix_err nix_init_plugins(nix_c_context * context)
|
nix_err nix_init_plugins(nix_c_context * context)
|
||||||
{
|
{
|
||||||
if (context)
|
if (context)
|
||||||
|
|
|
@ -35,6 +35,13 @@ typedef struct StorePath StorePath;
|
||||||
*/
|
*/
|
||||||
nix_err nix_libstore_init(nix_c_context * context);
|
nix_err nix_libstore_init(nix_c_context * context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Like nix_libstore_init, but does not load the Nix configuration.
|
||||||
|
*
|
||||||
|
* This is useful when external configuration is not desired, such as when running unit tests.
|
||||||
|
*/
|
||||||
|
nix_err nix_libstore_init_no_load_config(nix_c_context * context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads the plugins specified in Nix's plugin-files setting.
|
* @brief Loads the plugins specified in Nix's plugin-files setting.
|
||||||
*
|
*
|
||||||
|
|
|
@ -427,11 +427,12 @@ void assertLibStoreInitialized() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void initLibStore() {
|
void initLibStore(bool loadConfig) {
|
||||||
if (initLibStoreDone) return;
|
if (initLibStoreDone) return;
|
||||||
|
|
||||||
initLibUtil();
|
initLibUtil();
|
||||||
|
|
||||||
|
if (loadConfig)
|
||||||
loadConfFile();
|
loadConfFile();
|
||||||
|
|
||||||
preloadNSS();
|
preloadNSS();
|
||||||
|
|
|
@ -1279,9 +1279,10 @@ std::vector<Path> getUserConfigFiles();
|
||||||
extern const std::string nixVersion;
|
extern const std::string nixVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NB: This is not sufficient. You need to call initNix()
|
* @param loadConfig Whether to load configuration from `nix.conf`, `NIX_CONFIG`, etc. May be disabled for unit tests.
|
||||||
|
* @note When using libexpr, and/or libmain, This is not sufficient. See initNix().
|
||||||
*/
|
*/
|
||||||
void initLibStore();
|
void initLibStore(bool loadConfig = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It's important to initialize before doing _anything_, which is why we
|
* It's important to initialize before doing _anything_, which is why we
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace nix {
|
||||||
class LibStoreTest : public virtual ::testing::Test {
|
class LibStoreTest : public virtual ::testing::Test {
|
||||||
public:
|
public:
|
||||||
static void SetUpTestSuite() {
|
static void SetUpTestSuite() {
|
||||||
initLibStore();
|
initLibStore(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue