refact: Accept &str in eval_from_string

(cherry picked from commit 0ce86f66801ce0a052316a742ded241c773099dd)
This commit is contained in:
Robert Hensing 2024-04-08 16:23:59 +02:00
parent 7ce6900bfd
commit eadd2827a5

View file

@ -68,7 +68,7 @@ impl EvalState {
pub fn store(&self) -> &Store {
&self.store
}
pub fn eval_from_string(&self, expr: String, path: String) -> Result<Value> {
pub fn eval_from_string(&self, expr: &str, path: &str) -> Result<Value> {
let expr_ptr =
CString::new(expr).with_context(|| "eval_from_string: expr contains null byte")?;
let path_ptr =
@ -214,9 +214,7 @@ mod tests {
gc_registering_current_thread(|| {
let store = Store::open("auto").unwrap();
let es = EvalState::new(store).unwrap();
let v = es
.eval_from_string("1".to_string(), "<test>".to_string())
.unwrap();
let v = es.eval_from_string("1", "<test>").unwrap();
let v2 = v.clone();
es.force(&v).unwrap();
let t = es.value_type(&v).unwrap();
@ -233,9 +231,7 @@ mod tests {
gc_registering_current_thread(|| {
let store = Store::open("auto").unwrap();
let es = EvalState::new(store).unwrap();
let v = es
.eval_from_string("true".to_string(), "<test>".to_string())
.unwrap();
let v = es.eval_from_string("true", "<test>").unwrap();
es.force(&v).unwrap();
let t = es.value_type(&v).unwrap();
assert!(t == ValueType::Bool);
@ -248,9 +244,7 @@ mod tests {
gc_registering_current_thread(|| {
let store = Store::open("auto").unwrap();
let es = EvalState::new(store).unwrap();
let v = es
.eval_from_string("\"hello\"".to_string(), "<test>".to_string())
.unwrap();
let v = es.eval_from_string("\"hello\"", "<test>").unwrap();
es.force(&v).unwrap();
let t = es.value_type(&v).unwrap();
assert!(t == ValueType::String);
@ -265,9 +259,7 @@ mod tests {
gc_registering_current_thread(|| {
let store = Store::open("auto").unwrap();
let es = EvalState::new(store).unwrap();
let v = es
.eval_from_string("true".to_string(), "<test>".to_string())
.unwrap();
let v = es.eval_from_string("true", "<test>").unwrap();
es.force(&v).unwrap();
let r = es.require_string(&v);
assert!(r.is_err());
@ -285,9 +277,7 @@ mod tests {
gc_registering_current_thread(|| {
let store = Store::open("auto").unwrap();
let es = EvalState::new(store).unwrap();
let v = es
.eval_from_string("/foo".to_string(), "<test>".to_string())
.unwrap();
let v = es.eval_from_string("/foo", "<test>").unwrap();
es.force(&v).unwrap();
let r = es.require_string(&v);
assert!(r.is_err());
@ -305,10 +295,7 @@ mod tests {
let store = Store::open("auto").unwrap();
let es = EvalState::new(store).unwrap();
let v = es
.eval_from_string(
"builtins.substring 0 1 \"ü\"".to_string(),
"<test>".to_string(),
)
.eval_from_string("builtins.substring 0 1 \"ü\"", "<test>")
.unwrap();
es.force(&v).unwrap();
let t = es.value_type(&v).unwrap();
@ -329,7 +316,7 @@ mod tests {
let store = Store::open("auto").unwrap();
let es = EvalState::new(store).unwrap();
let v = es
.eval_from_string("(derivation { name = \"hello\"; system = \"dummy\"; builder = \"cmd.exe\"; }).outPath".to_string(), "<test>".to_string())
.eval_from_string("(derivation { name = \"hello\"; system = \"dummy\"; builder = \"cmd.exe\"; }).outPath", "<test>")
.unwrap();
es.force(&v).unwrap();
let t = es.value_type(&v).unwrap();
@ -347,9 +334,7 @@ mod tests {
gc_registering_current_thread(|| {
let store = Store::open("auto").unwrap();
let es = EvalState::new(store).unwrap();
let v = es
.eval_from_string("{ }".to_string(), "<test>".to_string())
.unwrap();
let v = es.eval_from_string("{ }", "<test>").unwrap();
es.force(&v).unwrap();
let t = es.value_type(&v).unwrap();
assert!(t == ValueType::AttrSet);