feat: eval_state::test_init
(cherry picked from commit 040982222c9eb8ea91d7174e6f2e21bbc6cda8a4)
This commit is contained in:
parent
4095bda02a
commit
726e891be8
1 changed files with 18 additions and 13 deletions
|
|
@ -353,27 +353,32 @@ impl Drop for EvalState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initialize the Nix library for testing. This includes some modifications to the Nix settings, that must not be used in production.
|
||||||
|
/// Use at your own peril, in rust test suites.
|
||||||
|
pub fn test_init() {
|
||||||
|
init().unwrap();
|
||||||
|
|
||||||
|
// During development, we encountered a problem where the build hook
|
||||||
|
// would cause the test suite to reinvokes itself, causing an infinite loop.
|
||||||
|
// While _NIX_TEST_NO_SANDBOX=1 should prevent this, we may also set the
|
||||||
|
// build hook to "" to prevent this.
|
||||||
|
// settings::set("build-hook", "")?;
|
||||||
|
|
||||||
|
// When testing in the sandbox, the default build dir would be a parent of the storeDir,
|
||||||
|
// which causes an error. So we set a custom build dir here.
|
||||||
|
nix_util::settings::set("sandbox-build-dir", "/custom-build-dir-for-test").unwrap();
|
||||||
|
std::env::set_var("_NIX_TEST_NO_SANDBOX", "1");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ctor::ctor;
|
use ctor::ctor;
|
||||||
use nix_util::settings;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[ctor]
|
#[ctor]
|
||||||
fn setup() {
|
fn setup() {
|
||||||
init().unwrap();
|
test_init();
|
||||||
|
|
||||||
// During development, we encountered a problem where the build hook
|
|
||||||
// would cause the test suite to reinvokes itself, causing an infinite loop.
|
|
||||||
// While _NIX_TEST_NO_SANDBOX=1 should prevent this, we may also set the
|
|
||||||
// build hook to "" to prevent this.
|
|
||||||
// settings::set("build-hook", "")?;
|
|
||||||
|
|
||||||
// When testing in the sandbox, the default build dir would be a parent of the storeDir,
|
|
||||||
// which causes an error. So we set a custom build dir here.
|
|
||||||
settings::set("sandbox-build-dir", "/custom-build-dir-for-test").unwrap();
|
|
||||||
std::env::set_var("_NIX_TEST_NO_SANDBOX", "1");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue