diff options
author | Vincent Ambo <mail@tazj.in> | 2022-12-08T21·31+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-12-21T13·09+0000 |
commit | 1138fbcaad3a7d69f707c4f47d84f314bc95d45a (patch) | |
tree | ee2d1852e47b35e5b150ec8cc19a68c388d15b80 | |
parent | d101151fc58c9ec8bbc6e39c6c29ebfc7f538473 (diff) |
refactor(tvix/eval): use new public API in test code r/5439
This removes internal uses of the previous crate::eval module, which is being removed. Change-Id: I5fb3c53460a9c5381853d0258f9ed074ab23c630 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7543 Tested-by: BuildkiteCI Autosubmit: tazjin <tazjin@tvl.su> Reviewed-by: grfn <grfn@gws.fyi>
-rw-r--r-- | tvix/eval/src/tests/mod.rs | 83 | ||||
-rw-r--r-- | tvix/eval/tests/nix_oracle.rs | 6 |
2 files changed, 48 insertions, 41 deletions
diff --git a/tvix/eval/src/tests/mod.rs b/tvix/eval/src/tests/mod.rs index 84fc89641c85..65aa12e0a01b 100644 --- a/tvix/eval/src/tests/mod.rs +++ b/tvix/eval/src/tests/mod.rs @@ -1,5 +1,3 @@ -use crate::eval::interpret; -use crate::eval::Options; use pretty_assertions::assert_eq; use test_generator::test_resources; @@ -19,41 +17,43 @@ fn eval_test(code_path: &str, expect_success: bool) { return; } - match interpret(&code, Some(code_path.into()), Options::test_options()) { - Ok(result) => { - let result_str = format!("{}", result); - if let Ok(exp) = std::fs::read_to_string(exp_path) { - if expect_success { - assert_eq!( - result_str, - exp.trim(), - "{code_path}: result value representation (left) must match expectation (right)" - ); - } else { - assert_ne!( - result_str, - exp.trim(), - "{code_path}: test passed unexpectedly! consider moving it out of notyetpassing" - ); - } - } else { - if expect_success { - panic!("{code_path}: should be able to read test expectation"); - } else { - panic!( - "{code_path}: test should have failed, but succeeded with output {}", - result - ); - } - } + let result = crate::Evaluation::new(&code, Some(code_path.into())).evaluate(); + + if expect_success && !result.errors.is_empty() { + panic!( + "{code_path}: evaluation of eval-okay test should succeed, but failed with {:?}", + result.errors, + ); + } + + if !expect_success && !result.errors.is_empty() { + return; + } + + let result_str = result.value.unwrap().to_string(); + + if let Ok(exp) = std::fs::read_to_string(exp_path) { + if expect_success { + assert_eq!( + result_str, + exp.trim(), + "{code_path}: result value representation (left) must match expectation (right)" + ); + } else { + assert_ne!( + result_str, + exp.trim(), + "{code_path}: test passed unexpectedly! consider moving it out of notyetpassing" + ); } - Err(e) => { - if expect_success { - panic!( - "{code_path}: evaluation of eval-okay test should succeed, but failed with {:?}", - e - ); - } + } else { + if expect_success { + panic!("{code_path}: should be able to read test expectation"); + } else { + panic!( + "{code_path}: test should have failed, but succeeded with output {}", + result_str + ); } } } @@ -64,9 +64,14 @@ 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 result = interpret(&code, None, Options::test_options()) - .expect("evaluation of identity test should succeed"); - let result_str = format!("{}", result); + let result = crate::Evaluation::new(&code, None).evaluate(); + assert!( + result.errors.is_empty(), + "evaluation of identity test failed: {:?}", + result.errors + ); + + let result_str = result.value.unwrap().to_string(); assert_eq!( result_str, diff --git a/tvix/eval/tests/nix_oracle.rs b/tvix/eval/tests/nix_oracle.rs index 34ed50351053..4910a18bec08 100644 --- a/tvix/eval/tests/nix_oracle.rs +++ b/tvix/eval/tests/nix_oracle.rs @@ -40,8 +40,10 @@ fn nix_eval(expr: &str) -> String { #[track_caller] fn compare_eval(expr: &str) { let nix_result = nix_eval(expr); - let tvix_result = tvix_eval::interpret(expr, None, Default::default()) - .unwrap() + let tvix_result = tvix_eval::Evaluation::new(expr, None) + .evaluate() + .value + .expect("tvix evaluation should succeed") .to_string(); assert_eq!(nix_result.trim(), tvix_result); |