test(tvix/eval): add some eval-okay-* tests for trivial types
Change-Id: I85ccc07e08c67abf4fcd3752c58e1702943239ac Reviewed-on: https://cl.tvl.fyi/c/depot/+/6135 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
		
							parent
							
								
									522d93745c
								
							
						
					
					
						commit
						8150803e77
					
				
					 13 changed files with 50 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -2,6 +2,25 @@ use crate::eval::interpret;
 | 
			
		|||
 | 
			
		||||
use test_generator::test_resources;
 | 
			
		||||
 | 
			
		||||
fn eval_okay_test(code_path: &str) {
 | 
			
		||||
    let base = code_path
 | 
			
		||||
        .strip_suffix("nix")
 | 
			
		||||
        .expect("test files always end in .nix");
 | 
			
		||||
    let exp_path = format!("{}exp", base);
 | 
			
		||||
 | 
			
		||||
    let code = std::fs::read_to_string(code_path).expect("should be able to read test code");
 | 
			
		||||
    let exp = std::fs::read_to_string(exp_path).expect("should be able to read test expectation");
 | 
			
		||||
 | 
			
		||||
    let result = interpret(&code).expect("evaluation of eval-okay test should succeed");
 | 
			
		||||
    let result_str = format!("{}", result);
 | 
			
		||||
 | 
			
		||||
    assert_eq!(
 | 
			
		||||
        exp.trim(),
 | 
			
		||||
        result_str,
 | 
			
		||||
        "result value representation (right) must match expectation (left)"
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// identity-* tests contain Nix code snippets which should evaluate to
 | 
			
		||||
// themselves exactly (i.e. literals).
 | 
			
		||||
#[test_resources("src/tests/tvix_tests/identity-*.nix")]
 | 
			
		||||
| 
						 | 
				
			
			@ -23,25 +42,14 @@ fn identity(code_path: &str) {
 | 
			
		|||
//
 | 
			
		||||
// These evaluations are always supposed to succeed, i.e. all snippets
 | 
			
		||||
// are guaranteed to be valid Nix code.
 | 
			
		||||
#[test_resources("src/tests/tvix_tests/eval-okay-*.nix")]
 | 
			
		||||
fn eval_okay(code_path: &str) {
 | 
			
		||||
    eval_okay_test(code_path)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// eval-okay-* tests from the original Nix test suite.
 | 
			
		||||
#[cfg(feature = "nix_tests")]
 | 
			
		||||
#[test_resources("src/tests/nix_tests/eval-okay-*.nix")]
 | 
			
		||||
fn nix_eval_okay(code_path: &str) {
 | 
			
		||||
    let base = code_path
 | 
			
		||||
        .strip_suffix("nix")
 | 
			
		||||
        .expect("test files always end in .nix");
 | 
			
		||||
    let exp_path = format!("{}exp", base);
 | 
			
		||||
 | 
			
		||||
    let code = std::fs::read_to_string(code_path).expect("should be able to read test code");
 | 
			
		||||
    let exp = std::fs::read_to_string(exp_path).expect("should be able to read test expectation");
 | 
			
		||||
 | 
			
		||||
    let result = interpret(&code).expect("evaluation of eval-okay test should succeed");
 | 
			
		||||
    let result_str = format!("{}", result);
 | 
			
		||||
 | 
			
		||||
    assert_eq!(
 | 
			
		||||
        exp.trim(),
 | 
			
		||||
        result_str,
 | 
			
		||||
        "result value representation (right) must match expectation (left)"
 | 
			
		||||
    );
 | 
			
		||||
    eval_okay_test(code_path)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
{ add = 37.34; div = 1.05714; mul = 105.154; sub = 14.35; }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
{
 | 
			
		||||
  add = 12.34 + 25.0;
 | 
			
		||||
  sub = 20.05 - 5.7;
 | 
			
		||||
  mul = 28.42 * 3.70;
 | 
			
		||||
  div = 18.5 / 17.5;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
{ add = 20; div = 3; mul = 8; sub = 15; }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
{
 | 
			
		||||
  add = 15 + 5;
 | 
			
		||||
  sub = 20 - 5;
 | 
			
		||||
  mul = 4 * 2;
 | 
			
		||||
  div = 9 / 3;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
"hello\nworld"
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
''hello
 | 
			
		||||
world''
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
{ a = { b = 15; }; b = { c = "test"; }; }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
{ a.b = 15; b.c = "test"; }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
{ a = { b = 15; c = "test"; }; }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
{
 | 
			
		||||
  a.b = 15;
 | 
			
		||||
  a.c = "test";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
{ a = { b = 42; }; }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
{ a.b = 42; }
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue