about summary refs log tree commit diff
path: root/tvix/eval/src/tests
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-12-30T20·36+0100
committerclbot <clbot@tvl.fyi>2023-12-31T13·15+0000
commit4fba57c2c90f2e7b02da9187e59f8d64deef3fb2 (patch)
tree9e29cd30ab4a9c060bc15550ddca400f6af03da4 /tvix/eval/src/tests
parenta5c5f1a29e8e9b39314a3ab024e170745ac96a3e (diff)
refactor(tvix/eval): remove code and location from struct r/7289
Instead, it's passed in the evaluate/compile_only functions, which feels
more naturally. It lets us set up the Evaluation struct long before
we actually feed it with data to evaluate.

Now that Evaluation::new() would be accepting an empty list of
arguments, we can simply implement Default, making things a bit more
idiomatic.

Change-Id: I4369658634909a0c504fdffa18242a130daa0239
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10475
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/eval/src/tests')
-rw-r--r--tvix/eval/src/tests/mod.rs14
-rw-r--r--tvix/eval/src/tests/one_offs.rs6
2 files changed, 11 insertions, 9 deletions
diff --git a/tvix/eval/src/tests/mod.rs b/tvix/eval/src/tests/mod.rs
index b7bea6094d44..7ec702883465 100644
--- a/tvix/eval/src/tests/mod.rs
+++ b/tvix/eval/src/tests/mod.rs
@@ -53,11 +53,11 @@ fn eval_test(code_path: &str, expect_success: bool) {
         return;
     }
 
-    let mut eval = crate::Evaluation::new_impure(&code, Some(code_path.into()));
+    let mut eval = crate::Evaluation::new_impure();
     eval.strict = true;
     eval.builtins.extend(mock_builtins::builtins());
 
-    let result = eval.evaluate();
+    let result = eval.evaluate(&code, Some(code_path.into()));
     let failed = match result.value {
         Some(Value::Catchable(_)) => true,
         _ => !result.errors.is_empty(),
@@ -106,11 +106,13 @@ fn eval_test(code_path: &str, expect_success: bool) {
 fn identity(code_path: &str) {
     let code = std::fs::read_to_string(code_path).expect("should be able to read test code");
 
-    let mut eval = crate::Evaluation::new(&code, None);
-    eval.strict = true;
-    eval.io_handle = Box::new(crate::StdIO);
+    let eval = crate::Evaluation {
+        strict: true,
+        io_handle: Box::new(crate::StdIO),
+        ..Default::default()
+    };
 
-    let result = eval.evaluate();
+    let result = eval.evaluate(&code, None);
     assert!(
         result.errors.is_empty(),
         "evaluation of identity test failed: {:?}",
diff --git a/tvix/eval/src/tests/one_offs.rs b/tvix/eval/src/tests/one_offs.rs
index 23bc9465d6bb..6024058a1296 100644
--- a/tvix/eval/src/tests/one_offs.rs
+++ b/tvix/eval/src/tests/one_offs.rs
@@ -5,10 +5,10 @@ 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);
+    let mut eval = Evaluation::new_impure();
     eval.src_builtins.push(("testSourceBuiltin", "42"));
 
-    let result = eval.evaluate();
+    let result = eval.evaluate("builtins.testSourceBuiltin", None);
     assert!(
         result.errors.is_empty(),
         "evaluation failed: {:?}",
@@ -25,7 +25,7 @@ fn test_source_builtin() {
 
 #[test]
 fn skip_broken_bytecode() {
-    let result = Evaluation::new(/* code = */ "x", None).evaluate();
+    let result = Evaluation::default().evaluate(/* code = */ "x", None);
 
     assert_eq!(result.errors.len(), 1);