about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-09-23T10·18+0300
committerflokli <flokli@flokli.de>2023-09-23T12·54+0000
commit4f13b520470f261be234bd5efa7913118534d0af (patch)
tree7f6a87ff8714826e1bbb2be54be005eb7e4356a8
parent09a901de5bde8a583d50fe4086c5128c6c0114c7 (diff)
feat(tvix/cli): add back a derivation test r/6639
Setting up the evaluator is a bit annoying currently, might get easier
with b/262, but it's better than no tests on that granularity at all.

Change-Id: Ie8c61466768f37f4efbc19ad497d37f87ddc2044
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9446
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
-rw-r--r--tvix/cli/src/derivation.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/tvix/cli/src/derivation.rs b/tvix/cli/src/derivation.rs
index 88e87b2f908e..e2184c4a676a 100644
--- a/tvix/cli/src/derivation.rs
+++ b/tvix/cli/src/derivation.rs
@@ -429,7 +429,37 @@ pub use derivation_builtins::builtins as derivation_builtins;
 
 #[cfg(test)]
 mod tests {
+    use crate::known_paths::KnownPaths;
     use nix_compat::store_path::hash_placeholder;
+    use std::{cell::RefCell, rc::Rc};
+
+    #[test]
+    fn derivation() {
+        let mut eval = tvix_eval::Evaluation::new_impure(
+            r#"(derivation { name = "foo"; 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")));
+
+        let result = eval.evaluate();
+
+        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()
+        );
+    }
 
     // TODO: These tests are commented out because we do not have
     // scaffolding to drive generators during testing at the moment.