snix/tvix/eval/src/tests/one_offs.rs
Vincent Ambo c98c5399b9 fix(tvix/eval): skip runtime completely on compiler errors
This branch was missing, and an assumption elsewhere just executed the
returned (broken) bytecode.

This fixes b/253.

Change-Id: I015023ba921bc08ea03882167f1f560feca25e50
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8090
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Autosubmit: tazjin <tazjin@tvl.su>
2023-02-13 16:21:47 +00:00

36 lines
887 B
Rust

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
);
let value = result.value.unwrap();
assert!(
matches!(value, Value::Integer(42)),
"expected the integer 42, but got {}",
value,
);
}
#[test]
fn skip_broken_bytecode() {
let result = Evaluation::new(/* code = */ "x", None).evaluate();
assert_eq!(result.errors.len(), 1);
assert!(matches!(
result.errors[0].kind,
ErrorKind::UnknownStaticVariable
));
}