From 4f13b520470f261be234bd5efa7913118534d0af Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 23 Sep 2023 13:18:31 +0300 Subject: feat(tvix/cli): add back a derivation test 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 Tested-by: BuildkiteCI Reviewed-by: raitobezarius --- tvix/cli/src/derivation.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tvix/cli/src/derivation.rs') diff --git a/tvix/cli/src/derivation.rs b/tvix/cli/src/derivation.rs index 88e87b2f90..e2184c4a67 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> = 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. -- cgit 1.4.1