test nix_state_create's lookupPath argument

(cherry picked from commit 6e5a259f60725b632e52d4839e6e3c285d6971d4)
This commit is contained in:
Philipp Zander 2024-05-13 19:29:48 +02:00 committed by Robert Hensing
parent d817e86c59
commit 9a62664fb1
3 changed files with 53 additions and 1 deletions

19
rust/Cargo.lock generated
View file

@ -98,6 +98,12 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "fastrand"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
[[package]]
name = "glob"
version = "0.3.1"
@ -192,6 +198,7 @@ dependencies = [
"nix-c-raw",
"nix-store",
"nix-util",
"tempfile",
]
[[package]]
@ -339,6 +346,18 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "tempfile"
version = "3.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
dependencies = [
"cfg-if",
"fastrand",
"rustix",
"windows-sys 0.52.0",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"

View file

@ -11,4 +11,5 @@ nix-store = { path = "../nix-store" }
nix-util = { path = "../nix-util" }
nix-c-raw = { path = "../nix-c-raw" }
lazy_static = "1.4.0"
ctor = "0.2.7"
ctor = "0.2.7"
tempfile = "3.10.1"

View file

@ -385,6 +385,7 @@ pub fn test_init() {
#[cfg(test)]
mod tests {
use ctor::ctor;
use std::io::Write as _;
use super::*;
@ -403,6 +404,37 @@ mod tests {
.unwrap();
}
#[test]
fn eval_state_lookup_path() {
let import_expression = "import <test_file0> + import <test_file1>";
let integer0 = 83;
let integer1 = 103;
let mut test_file0 = tempfile::NamedTempFile::new().unwrap();
let mut test_file1 = tempfile::NamedTempFile::new().unwrap();
writeln!(test_file0, "{integer0}").unwrap();
writeln!(test_file1, "{integer1}").unwrap();
gc_registering_current_thread(|| {
let es = EvalState::new(Store::open("auto").unwrap(), []).unwrap();
assert!(es.eval_from_string(import_expression, "<test>").is_err());
let es = EvalState::new(
Store::open("auto").unwrap(),
[
format!("test_file0={}", test_file0.path().to_str().unwrap()).as_str(),
format!("test_file1={}", test_file1.path().to_str().unwrap()).as_str(),
],
)
.unwrap();
let v = es
.require_int(&es.eval_from_string(import_expression, "<test>").unwrap())
.unwrap();
assert_eq!(v, integer0 + integer1);
})
.unwrap();
test_file0.close().unwrap();
test_file1.close().unwrap();
}
#[test]
fn eval_state_eval_from_string() {
gc_registering_current_thread(|| {