about summary refs log tree commit diff
path: root/tvix/eval/src/tests/one_offs.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-01-21T12·18+0300
committertazjin <tazjin@tvl.su>2023-01-22T20·48+0000
commit5719763fd3afaa5dd157da604069b037ca4bf79a (patch)
treeb6330b0c4a729cc1ae67971f62d1381805a261cd /tvix/eval/src/tests/one_offs.rs
parent8513a58b37ffb032a621fb25d5952f6d4df27872 (diff)
feat(tvix/eval): support builtins implemented in Nix itself r/5735
This makes it possible to inject builtins into the builtin set that
are written in Nix code, and which at runtime are represented by a
thunk that will compile them the first time they are used.

Change-Id: Ia632367328f66fb2f26cb64ae464f8f3dc9c6d30
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7891
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/eval/src/tests/one_offs.rs')
-rw-r--r--tvix/eval/src/tests/one_offs.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/tvix/eval/src/tests/one_offs.rs b/tvix/eval/src/tests/one_offs.rs
new file mode 100644
index 000000000000..63bb8f7af378
--- /dev/null
+++ b/tvix/eval/src/tests/one_offs.rs
@@ -0,0 +1,19 @@
+use crate::*;
+
+#[test]
+fn test_source_builtin() {
+    // Test an evaluation with a source-only builtin. The test ensures
+    // that the artificially constructed thunking is correct.
+
+    let mut eval = Evaluation::new_impure("builtins.testSourceBuiltin", None);
+    eval.src_builtins.push(("testSourceBuiltin", "42"));
+
+    let result = eval.evaluate();
+    assert!(
+        result.errors.is_empty(),
+        "evaluation failed: {:?}",
+        result.errors
+    );
+
+    assert!(matches!(result.value.unwrap(), Value::Integer(42)));
+}