about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tvix/cli/src/derivation.rs59
1 files changed, 29 insertions, 30 deletions
diff --git a/tvix/cli/src/derivation.rs b/tvix/cli/src/derivation.rs
index 15df6ed76102..f1747a52ca60 100644
--- a/tvix/cli/src/derivation.rs
+++ b/tvix/cli/src/derivation.rs
@@ -470,13 +470,13 @@ mod tests {
     use crate::known_paths::KnownPaths;
     use nix_compat::store_path::hash_placeholder;
     use std::{cell::RefCell, rc::Rc};
+    use tvix_eval::EvaluationResult;
 
-    #[test]
-    fn derivation() {
-        let mut eval = tvix_eval::Evaluation::new_impure(
-            r#"(derivation { name = "foo"; builder = "/bin/sh"; system = "x86_64-linux";}).outPath"#,
-            None,
-        );
+    /// evaluates a given nix expression and returns the result.
+    /// Takes care of setting up the evaluator so it knows about the
+    // `derivation` builtin.
+    fn eval(str: &str) -> EvaluationResult {
+        let mut eval = tvix_eval::Evaluation::new_impure(str, None);
 
         let known_paths: Rc<RefCell<KnownPaths>> = Default::default();
 
@@ -484,42 +484,41 @@ mod tests {
             .extend(crate::derivation::derivation_builtins(known_paths));
 
         // Add the actual `builtins.derivation` from compiled Nix code
-        // TODO: properly compose this
         eval.src_builtins
             .push(("derivation", include_str!("derivation.nix")));
 
-        let result = eval.evaluate();
+        // run the evaluation itself.
+        eval.evaluate()
+    }
+
+    #[test]
+    fn derivation() {
+        let result = eval(
+            r#"(derivation { name = "foo"; builder = "/bin/sh"; system = "x86_64-linux";}).outPath"#,
+        );
 
         assert!(result.errors.is_empty(), "expect evaluation to succeed");
         let value = result.value.expect("must be some");
-        // TODO: test this more reliably, derive Eq?
-        assert_eq!(
-            "\"/nix/store/xpcvxsx5sw4rbq666blz6sxqlmsqphmr-foo\"",
-            value.to_string()
-        );
+
+        match value {
+            tvix_eval::Value::String(s) => {
+                assert_eq!(
+                    "/nix/store/xpcvxsx5sw4rbq666blz6sxqlmsqphmr-foo",
+                    s.as_str()
+                );
+            }
+            _ => panic!("unexpected value type: {:?}", value),
+        }
     }
 
+    /// a derivation with an empty name is an error.
     #[test]
-    fn derivation_empty_name() {
-        let mut eval = tvix_eval::Evaluation::new_impure(
+    fn derivation_empty_name_fail() {
+        let result = eval(
             r#"(derivation { name = ""; builder = "/bin/sh"; system = "x86_64-linux";}).outPath"#,
-            None,
         );
 
-        let known_paths: Rc<RefCell<KnownPaths>> = Default::default();
-
-        eval.builtins
-            .extend(crate::derivation::derivation_builtins(known_paths));
-
-        // Add the actual `builtins.derivation` from compiled Nix code
-        // TODO: properly compose this
-        eval.src_builtins
-            .push(("derivation", include_str!("derivation.nix")));
-
-        assert!(
-            !eval.evaluate().errors.is_empty(),
-            "expect evaluation to fail"
-        );
+        assert!(!result.errors.is_empty(), "expect evaluation to fail");
     }
 
     // TODO: These tests are commented out because we do not have