refactor(tvix/eval): use new public API in test code

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>
This commit is contained in:
Vincent Ambo 2022-12-09 00:31:45 +03:00 committed by clbot
parent d101151fc5
commit 1138fbcaad
2 changed files with 48 additions and 41 deletions

View file

@ -1,5 +1,3 @@
use crate::eval::interpret;
use crate::eval::Options;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use test_generator::test_resources; use test_generator::test_resources;
@ -19,41 +17,43 @@ fn eval_test(code_path: &str, expect_success: bool) {
return; return;
} }
match interpret(&code, Some(code_path.into()), Options::test_options()) { let result = crate::Evaluation::new(&code, Some(code_path.into())).evaluate();
Ok(result) => {
let result_str = format!("{}", result); if expect_success && !result.errors.is_empty() {
if let Ok(exp) = std::fs::read_to_string(exp_path) { panic!(
if expect_success { "{code_path}: evaluation of eval-okay test should succeed, but failed with {:?}",
assert_eq!( result.errors,
result_str, );
exp.trim(), }
"{code_path}: result value representation (left) must match expectation (right)"
); if !expect_success && !result.errors.is_empty() {
} else { return;
assert_ne!( }
result_str,
exp.trim(), let result_str = result.value.unwrap().to_string();
"{code_path}: test passed unexpectedly! consider moving it out of notyetpassing"
); if let Ok(exp) = std::fs::read_to_string(exp_path) {
} if expect_success {
} else { assert_eq!(
if expect_success { result_str,
panic!("{code_path}: should be able to read test expectation"); exp.trim(),
} else { "{code_path}: result value representation (left) must match expectation (right)"
panic!( );
"{code_path}: test should have failed, but succeeded with output {}", } else {
result assert_ne!(
); result_str,
} exp.trim(),
} "{code_path}: test passed unexpectedly! consider moving it out of notyetpassing"
);
} }
Err(e) => { } else {
if expect_success { if expect_success {
panic!( panic!("{code_path}: should be able to read test expectation");
"{code_path}: evaluation of eval-okay test should succeed, but failed with {:?}", } else {
e 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) { fn identity(code_path: &str) {
let code = std::fs::read_to_string(code_path).expect("should be able to read test code"); 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()) let result = crate::Evaluation::new(&code, None).evaluate();
.expect("evaluation of identity test should succeed"); assert!(
let result_str = format!("{}", result); result.errors.is_empty(),
"evaluation of identity test failed: {:?}",
result.errors
);
let result_str = result.value.unwrap().to_string();
assert_eq!( assert_eq!(
result_str, result_str,

View file

@ -40,8 +40,10 @@ fn nix_eval(expr: &str) -> String {
#[track_caller] #[track_caller]
fn compare_eval(expr: &str) { fn compare_eval(expr: &str) {
let nix_result = nix_eval(expr); let nix_result = nix_eval(expr);
let tvix_result = tvix_eval::interpret(expr, None, Default::default()) let tvix_result = tvix_eval::Evaluation::new(expr, None)
.unwrap() .evaluate()
.value
.expect("tvix evaluation should succeed")
.to_string(); .to_string();
assert_eq!(nix_result.trim(), tvix_result); assert_eq!(nix_result.trim(), tvix_result);