From 8150803e77fb749bb331cf4072ebc9e87d3d0e96 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 10 Aug 2022 20:02:05 +0300 Subject: 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 --- tvix/eval/src/tests/mod.rs | 40 +++++++++++++--------- .../tvix_tests/eval-okay-arithmetic-float.exp | 1 + .../tvix_tests/eval-okay-arithmetic-float.nix | 6 ++++ .../tests/tvix_tests/eval-okay-arithmetic-int.exp | 1 + .../tests/tvix_tests/eval-okay-arithmetic-int.nix | 6 ++++ .../tvix_tests/eval-okay-multiline-string.exp | 1 + .../tvix_tests/eval-okay-multiline-string.nix | 2 ++ .../tvix_tests/eval-okay-multiple-nested-attrs.exp | 1 + .../tvix_tests/eval-okay-multiple-nested-attrs.nix | 1 + .../eval-okay-overlapping-nested-attrs.exp | 1 + .../eval-okay-overlapping-nested-attrs.nix | 4 +++ .../tvix_tests/eval-okay-simple-nested-attrs.exp | 1 + .../tvix_tests/eval-okay-simple-nested-attrs.nix | 1 + 13 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-float.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-float.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-int.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-int.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-multiline-string.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-multiline-string.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-multiple-nested-attrs.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-multiple-nested-attrs.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-overlapping-nested-attrs.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-overlapping-nested-attrs.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-simple-nested-attrs.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-simple-nested-attrs.nix diff --git a/tvix/eval/src/tests/mod.rs b/tvix/eval/src/tests/mod.rs index c51acfab976f..ca8c114ba320 100644 --- a/tvix/eval/src/tests/mod.rs +++ b/tvix/eval/src/tests/mod.rs @@ -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) } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-float.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-float.exp new file mode 100644 index 000000000000..08ef6079f899 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-float.exp @@ -0,0 +1 @@ +{ add = 37.34; div = 1.05714; mul = 105.154; sub = 14.35; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-float.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-float.nix new file mode 100644 index 000000000000..9d12aee061b2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-float.nix @@ -0,0 +1,6 @@ +{ + add = 12.34 + 25.0; + sub = 20.05 - 5.7; + mul = 28.42 * 3.70; + div = 18.5 / 17.5; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-int.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-int.exp new file mode 100644 index 000000000000..a5711e8bfe9b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-int.exp @@ -0,0 +1 @@ +{ add = 20; div = 3; mul = 8; sub = 15; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-int.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-int.nix new file mode 100644 index 000000000000..c53790db099b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-arithmetic-int.nix @@ -0,0 +1,6 @@ +{ + add = 15 + 5; + sub = 20 - 5; + mul = 4 * 2; + div = 9 / 3; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-multiline-string.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-multiline-string.exp new file mode 100644 index 000000000000..9839e480b781 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-multiline-string.exp @@ -0,0 +1 @@ +"hello\nworld" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-multiline-string.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-multiline-string.nix new file mode 100644 index 000000000000..84beb22ed5c3 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-multiline-string.nix @@ -0,0 +1,2 @@ +''hello +world'' diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-multiple-nested-attrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-multiple-nested-attrs.exp new file mode 100644 index 000000000000..b5c707cf462e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-multiple-nested-attrs.exp @@ -0,0 +1 @@ +{ a = { b = 15; }; b = { c = "test"; }; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-multiple-nested-attrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-multiple-nested-attrs.nix new file mode 100644 index 000000000000..5d611930ca7a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-multiple-nested-attrs.nix @@ -0,0 +1 @@ +{ a.b = 15; b.c = "test"; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-overlapping-nested-attrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-overlapping-nested-attrs.exp new file mode 100644 index 000000000000..2483a2718301 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-overlapping-nested-attrs.exp @@ -0,0 +1 @@ +{ a = { b = 15; c = "test"; }; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-overlapping-nested-attrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-overlapping-nested-attrs.nix new file mode 100644 index 000000000000..4154ff9da29f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-overlapping-nested-attrs.nix @@ -0,0 +1,4 @@ +{ + a.b = 15; + a.c = "test"; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-simple-nested-attrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-nested-attrs.exp new file mode 100644 index 000000000000..6db47b033efb --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-nested-attrs.exp @@ -0,0 +1 @@ +{ a = { b = 42; }; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-simple-nested-attrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-nested-attrs.nix new file mode 100644 index 000000000000..a97394d16523 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-nested-attrs.nix @@ -0,0 +1 @@ +{ a.b = 42; } -- cgit 1.4.1