feat: eval_state::test_init

(cherry picked from commit 040982222c9eb8ea91d7174e6f2e21bbc6cda8a4)
This commit is contained in:
Robert Hensing 2024-04-10 14:34:51 +02:00
parent 4095bda02a
commit 726e891be8

View file

@ -353,15 +353,9 @@ impl Drop for EvalState {
} }
} }
#[cfg(test)] /// Initialize the Nix library for testing. This includes some modifications to the Nix settings, that must not be used in production.
mod tests { /// Use at your own peril, in rust test suites.
use ctor::ctor; pub fn test_init() {
use nix_util::settings;
use super::*;
#[ctor]
fn setup() {
init().unwrap(); init().unwrap();
// During development, we encountered a problem where the build hook // During development, we encountered a problem where the build hook
@ -372,8 +366,19 @@ mod tests {
// When testing in the sandbox, the default build dir would be a parent of the storeDir, // 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. // which causes an error. So we set a custom build dir here.
settings::set("sandbox-build-dir", "/custom-build-dir-for-test").unwrap(); nix_util::settings::set("sandbox-build-dir", "/custom-build-dir-for-test").unwrap();
std::env::set_var("_NIX_TEST_NO_SANDBOX", "1"); std::env::set_var("_NIX_TEST_NO_SANDBOX", "1");
}
#[cfg(test)]
mod tests {
use ctor::ctor;
use super::*;
#[ctor]
fn setup() {
test_init();
} }
#[test] #[test]