diff options
Diffstat (limited to 'tvix/eval/src/tests')
471 files changed, 2441 insertions, 228 deletions
diff --git a/tvix/eval/src/tests/mod.rs b/tvix/eval/src/tests/mod.rs index 49ca35973e..21b5d35e6a 100644 --- a/tvix/eval/src/tests/mod.rs +++ b/tvix/eval/src/tests/mod.rs @@ -1,58 +1,6 @@ -use crate::eval::interpret; -use pretty_assertions::assert_eq; +/// Module for one-off tests which do not follow the rest of the +/// test layout. +mod one_offs; -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, None, Default::default()) - .expect("evaluation of eval-okay test should succeed"); - let result_str = format!("{}", result); - - assert_eq!( - result_str, - exp.trim(), - "result value representation (left) must match expectation (right)" - ); -} - -// identity-* tests contain Nix code snippets which should evaluate to -// themselves exactly (i.e. literals). -#[test_resources("src/tests/tvix_tests/identity-*.nix")] -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, Default::default()) - .expect("evaluation of identity test should succeed"); - let result_str = format!("{}", result); - - assert_eq!( - result_str, - code.trim(), - "result value representation (left) must match expectation (right)" - ) -} - -// eval-okay-* tests contain a snippet of Nix code, and an expectation -// of the produced string output of the evaluator. -// -// 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) { - eval_okay_test(code_path) -} +mod nix_tests; diff --git a/tvix/eval/src/tests/nix_tests.rs b/tvix/eval/src/tests/nix_tests.rs new file mode 100644 index 0000000000..17968e4bdb --- /dev/null +++ b/tvix/eval/src/tests/nix_tests.rs @@ -0,0 +1,207 @@ +use crate::value::Value; +use builtin_macros::builtins; +use pretty_assertions::assert_eq; +use rstest::rstest; +use std::path::PathBuf; + +#[builtins] +mod mock_builtins { + //! Builtins which are required by language tests, but should not + //! actually exist in //tvix/eval. + use crate as tvix_eval; + use crate::generators::GenCo; + use crate::*; + use genawaiter::rc::Gen; + + #[builtin("derivation")] + async fn builtin_derivation(co: GenCo, input: Value) -> Result<Value, ErrorKind> { + let input = input.to_attrs()?; + let attrs = input.update(NixAttrs::from_iter( + [ + ( + "outPath", + "/nix/store/00000000000000000000000000000000-mock", + ), + ( + "drvPath", + "/nix/store/00000000000000000000000000000000-mock.drv", + ), + ("type", "derivation"), + ] + .into_iter(), + )); + + Ok(Value::Attrs(Box::new(attrs))) + } +} + +#[cfg(feature = "impure")] +fn eval_test(code_path: PathBuf, expect_success: bool) { + std::env::set_var("TEST_VAR", "foo"); // for eval-okay-getenv.nix + + eprintln!("path: {}", code_path.display()); + assert_eq!( + code_path.extension().unwrap(), + "nix", + "test files always end in .nix" + ); + + let code = std::fs::read_to_string(&code_path).expect("should be able to read test code"); + + let mut eval = crate::Evaluation::new_impure(); + eval.strict = true; + eval.builtins.extend(mock_builtins::builtins()); + + let result = eval.evaluate(code, Some(code_path.clone())); + let failed = match result.value { + Some(Value::Catchable(_)) => true, + _ => !result.errors.is_empty(), + }; + if expect_success && failed { + panic!( + "{}: evaluation of eval-okay test should succeed, but failed with {:?}", + code_path.display(), + result.errors, + ); + } + + if !expect_success && failed { + return; + } + // !expect_success can also mean the output differs, so don't panic if the + // evaluation didn't fail. + + let value = result.value.unwrap(); + let result_str = value.to_string(); + + let exp_path = code_path.with_extension("exp"); + if exp_path.exists() { + // If there's an .exp file provided alongside, compare it with the + // output of the NixValue .to_string() method. + let exp_str = std::fs::read_to_string(&exp_path).expect("unable to read .exp file"); + + if expect_success { + assert_eq!( + result_str, + exp_str.trim(), + "{}: result value representation (left) must match expectation (right)", + code_path.display() + ); + } else { + assert_ne!( + result_str, + exp_str.trim(), + "{}: test passed unexpectedly! consider moving it out of notyetpassing", + code_path.display() + ); + + // Early return here, we don't compare .xml outputs if this is a ! + // expect_success test. + return; + } + } + + let exp_xml_path = code_path.with_extension("exp.xml"); + if exp_xml_path.exists() { + // If there's an XML file provided alongside, compare it with the + // output produced when serializing the Value as XML. + let exp_xml_str = std::fs::read_to_string(exp_xml_path).expect("unable to read .xml file"); + + let mut xml_actual_buf = Vec::new(); + crate::builtins::value_to_xml(&mut xml_actual_buf, &value).expect("value_to_xml failed"); + + assert_eq!( + String::from_utf8(xml_actual_buf).expect("to_xml produced invalid utf-8"), + exp_xml_str, + "{}: result value representation (left) must match expectation (right)", + code_path.display() + ); + } +} + +// identity-* tests contain Nix code snippets which should evaluate to +// themselves exactly (i.e. literals). +#[cfg(feature = "impure")] +#[rstest] +fn identity(#[files("src/tests/tvix_tests/identity-*.nix")] code_path: PathBuf) { + use crate::EvalIO; + + let code = std::fs::read_to_string(code_path).expect("should be able to read test code"); + + let mut eval = crate::Evaluation::new(Box::new(crate::StdIO) as Box<dyn EvalIO>, false); + eval.strict = true; + + let result = eval.evaluate(&code, None); + assert!( + result.errors.is_empty(), + "evaluation of identity test failed: {:?}", + result.errors + ); + + let result_str = result.value.unwrap().to_string(); + + assert_eq!( + result_str, + code.trim(), + "result value representation (left) must match expectation (right)" + ) +} + +// eval-okay-* tests contain a snippet of Nix code, and an expectation +// of the produced string output of the evaluator. +// +// These evaluations are always supposed to succeed, i.e. all snippets +// are guaranteed to be valid Nix code. +#[cfg(feature = "impure")] +#[rstest] +fn eval_okay(#[files("src/tests/tvix_tests/eval-okay-*.nix")] code_path: PathBuf) { + eval_test(code_path, true) +} + +// eval-okay-* tests from the original Nix test suite. +#[cfg(feature = "impure")] +#[rstest] +fn nix_eval_okay(#[files("src/tests/nix_tests/eval-okay-*.nix")] code_path: PathBuf) { + eval_test(code_path, true) +} + +// eval-okay-* tests from the original Nix test suite which do not yet pass for tvix +// +// Eventually there will be none of these left, and this function +// will disappear :) +// +// Please don't submit failing tests unless they're in +// notyetpassing; this makes the test suite much more useful for +// regression testing, since there should always be zero non-ignored +// failing tests. +#[cfg(feature = "impure")] +#[rstest] +fn nix_eval_okay_currently_failing( + #[files("src/tests/nix_tests/notyetpassing/eval-okay-*.nix")] code_path: PathBuf, +) { + eval_test(code_path, false) +} + +#[cfg(feature = "impure")] +#[rstest] +fn eval_okay_currently_failing( + #[files("src/tests/tvix_tests/notyetpassing/eval-okay-*.nix")] code_path: PathBuf, +) { + eval_test(code_path, false) +} + +// eval-fail-* tests contain a snippet of Nix code, which is +// expected to fail evaluation. The exact type of failure +// (assertion, parse error, etc) is not currently checked. +#[cfg(feature = "impure")] +#[rstest] +fn eval_fail(#[files("src/tests/tvix_tests/eval-fail-*.nix")] code_path: PathBuf) { + eval_test(code_path, false) +} + +// eval-fail-* tests from the original Nix test suite. +#[cfg(feature = "impure")] +#[rstest] +fn nix_eval_fail(#[files("src/tests/nix_tests/eval-fail-*.nix")] code_path: PathBuf) { + eval_test(code_path, false) +} diff --git a/tvix/eval/src/tests/nix_tests/eval-fail-foldlStrict-strict-op-application.nix b/tvix/eval/src/tests/nix_tests/eval-fail-foldlStrict-strict-op-application.nix new file mode 100644 index 0000000000..1620cc76ee --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-fail-foldlStrict-strict-op-application.nix @@ -0,0 +1,5 @@ +# Tests that the result of applying op is forced even if the value is never used +builtins.foldl' + (_: f: f null) + null + [ (_: throw "Not the final value, but is still forced!") (_: 23) ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-closure.exp b/tvix/eval/src/tests/nix_tests/eval-okay-closure.exp new file mode 100644 index 0000000000..e7dbf97816 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-closure.exp @@ -0,0 +1 @@ +[ { foo = true; key = -13; } { foo = true; key = -12; } { foo = true; key = -11; } { foo = true; key = -9; } { foo = true; key = -8; } { foo = true; key = -7; } { foo = true; key = -5; } { foo = true; key = -4; } { foo = true; key = -3; } { key = -1; } { foo = true; key = 0; } { foo = true; key = 1; } { foo = true; key = 2; } { foo = true; key = 4; } { foo = true; key = 5; } { foo = true; key = 6; } { key = 8; } { foo = true; key = 9; } { foo = true; key = 10; } { foo = true; key = 13; } { foo = true; key = 14; } { foo = true; key = 15; } { key = 17; } { foo = true; key = 18; } { foo = true; key = 19; } { foo = true; key = 22; } { foo = true; key = 23; } { key = 26; } { foo = true; key = 27; } { foo = true; key = 28; } { foo = true; key = 31; } { foo = true; key = 32; } { key = 35; } { foo = true; key = 36; } { foo = true; key = 40; } { foo = true; key = 41; } { key = 44; } { foo = true; key = 45; } { foo = true; key = 49; } { key = 53; } { foo = true; key = 54; } { foo = true; key = 58; } { key = 62; } { foo = true; key = 67; } { key = 71; } { key = 80; } ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-context-introspection.nix b/tvix/eval/src/tests/nix_tests/eval-okay-context-introspection.nix deleted file mode 100644 index 43178bd2ee..0000000000 --- a/tvix/eval/src/tests/nix_tests/eval-okay-context-introspection.nix +++ /dev/null @@ -1,24 +0,0 @@ -let - drv = derivation { - name = "fail"; - builder = "/bin/false"; - system = "x86_64-linux"; - outputs = [ "out" "foo" ]; - }; - - path = "${./eval-okay-context-introspection.nix}"; - - desired-context = { - "${builtins.unsafeDiscardStringContext path}" = { - path = true; - }; - "${builtins.unsafeDiscardStringContext drv.drvPath}" = { - outputs = [ "foo" "out" ]; - allOutputs = true; - }; - }; - - legit-context = builtins.getContext "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}"; - - constructed-context = builtins.getContext (builtins.appendContext "" desired-context); -in legit-context == constructed-context diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-context-introspection.exp b/tvix/eval/src/tests/nix_tests/eval-okay-eq.exp index 27ba77ddaf..27ba77ddaf 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-context-introspection.exp +++ b/tvix/eval/src/tests/nix_tests/eval-okay-eq.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-eq.exp.disabled b/tvix/eval/src/tests/nix_tests/eval-okay-eq.exp.disabled deleted file mode 100644 index 2015847b65..0000000000 --- a/tvix/eval/src/tests/nix_tests/eval-okay-eq.exp.disabled +++ /dev/null @@ -1 +0,0 @@ -Bool(True) diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-elements.exp b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-elements.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-elements.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-elements.nix b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-elements.nix new file mode 100644 index 0000000000..c666e07f3a --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-elements.nix @@ -0,0 +1,9 @@ +# Tests that the rhs argument of op is not forced unconditionally +let + lst = builtins.foldl' + (acc: x: acc ++ [ x ]) + [ ] + [ 42 (throw "this shouldn't be evaluated") ]; +in + +builtins.head lst diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.exp b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.nix b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.nix new file mode 100644 index 0000000000..abcd5366ab --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.nix @@ -0,0 +1,6 @@ +# Checks that the nul value for the accumulator is not forced unconditionally. +# Some languages provide a foldl' that is strict in this argument, but Nix does not. +builtins.foldl' + (_: x: x) + (throw "This is never forced") + [ "but the results of applying op are" 42 ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict.exp b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict.exp new file mode 100644 index 0000000000..837e12b406 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict.exp @@ -0,0 +1 @@ +500500 diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict.nix b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict.nix new file mode 100644 index 0000000000..3b87188d24 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-foldlStrict.nix @@ -0,0 +1,3 @@ +with import ./lib.nix; + +builtins.foldl' (x: y: x + y) 0 (range 1 1000) diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.nix b/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.nix index 102ee82b5e..e1c0f86cc4 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.nix +++ b/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.nix @@ -1,36 +1,35 @@ -# RFC 7159, section 13. builtins.fromJSON '' { - "Image": { - "Width": 800, - "Height": 600, - "Title": "View from 15th Floor", - "Thumbnail": { - "Url": "http://www.example.com/image/481989943", - "Height": 125, - "Width": 100 + "Video": { + "Title": "The Penguin Chronicles", + "Width": 1920, + "Height": 1080, + "EmbeddedData": [3.14159, 23493,null, true ,false, -10], + "Thumb": { + "Url": "http://www.example.com/video/5678931", + "Width": 200, + "Height": 250 }, - "Animated" : false, - "IDs": [116, 943, 234, 38793, true ,false,null, -100], - "Latitude": 37.7668, - "Longitude": -122.3959 + "Subtitle" : false, + "Latitude": 46.2051, + "Longitude": 6.0723 } } '' == - { Image = - { Width = 800; - Height = 600; - Title = "View from 15th Floor"; - Thumbnail = - { Url = http://www.example.com/image/481989943; - Height = 125; - Width = 100; + { Video = + { Title = "The Penguin Chronicles"; + Width = 1920; + Height = 1080; + EmbeddedData = [ 3.14159 23493 null true false (0-10) ]; + Thumb = + { Url = "http://www.example.com/video/5678931"; + Width = 200; + Height = 250; }; - Animated = false; - IDs = [ 116 943 234 38793 true false null (0-100) ]; - Latitude = 37.7668; - Longitude = -122.3959; + Subtitle = false; + Latitude = 46.2051; + Longitude = 6.0723; }; } diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-functionargs.exp b/tvix/eval/src/tests/nix_tests/eval-okay-functionargs.exp new file mode 100644 index 0000000000..c1c9f8ffaf --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-functionargs.exp @@ -0,0 +1 @@ +[ "stdenv" "fetchurl" "aterm-stdenv" "aterm-stdenv2" "libX11" "libXv" "mplayer-stdenv2.libXv-libX11" "mplayer-stdenv2.libXv-libX11_2" "nix-stdenv-aterm-stdenv" "nix-stdenv2-aterm2-stdenv2" ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.exp b/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.exp new file mode 100644 index 0000000000..bfca5652a5 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.exp @@ -0,0 +1 @@ +{ "1" = [ 9 ]; "2" = [ 8 ]; "3" = [ 13 29 ]; "4" = [ 3 4 10 11 17 18 ]; "5" = [ 0 23 26 28 ]; "6" = [ 1 12 21 27 30 ]; "7" = [ 7 22 ]; "8" = [ 14 ]; "9" = [ 19 ]; b = [ 16 25 ]; c = [ 24 ]; d = [ 2 ]; e = [ 5 6 15 31 ]; f = [ 20 ]; } diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.nix b/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.nix new file mode 100644 index 0000000000..862d89dbd6 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.nix @@ -0,0 +1,5 @@ +with import ./lib.nix; + +builtins.groupBy (n: + builtins.substring 0 1 (builtins.hashString "sha256" (toString n)) +) (range 0 31) diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-ind-string.nix b/tvix/eval/src/tests/nix_tests/eval-okay-ind-string.nix index 1669dc0648..95d59b5083 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-ind-string.nix +++ b/tvix/eval/src/tests/nix_tests/eval-okay-ind-string.nix @@ -110,7 +110,7 @@ let And finally to interpret \n etc. as in a string: ''\n, ''\r, ''\t. ''; - # Regression test: antiquotation in '${x}' should work, but didn't. + # Regression test: string interpolation in '${x}' should work, but didn't. s15 = let x = "bla"; in '' foo '${x}' diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-intersectAttrs.exp b/tvix/eval/src/tests/nix_tests/eval-okay-intersectAttrs.exp new file mode 100644 index 0000000000..50445bc0ee --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-intersectAttrs.exp @@ -0,0 +1 @@ +[ { } { a = 1; } { a = 1; } { a = "a"; } { m = 1; } { m = "m"; } { n = 1; } { n = "n"; } { n = 1; p = 2; } { n = "n"; p = "p"; } { n = 1; p = 2; } { n = "n"; p = "p"; } { a = "a"; b = "b"; c = "c"; d = "d"; e = "e"; f = "f"; g = "g"; h = "h"; i = "i"; j = "j"; k = "k"; l = "l"; m = "m"; n = "n"; o = "o"; p = "p"; q = "q"; r = "r"; s = "s"; t = "t"; u = "u"; v = "v"; w = "w"; x = "x"; y = "y"; z = "z"; } true ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-intersectAttrs.nix b/tvix/eval/src/tests/nix_tests/eval-okay-intersectAttrs.nix new file mode 100644 index 0000000000..39d49938cc --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-intersectAttrs.nix @@ -0,0 +1,50 @@ +let + alphabet = + { a = "a"; + b = "b"; + c = "c"; + d = "d"; + e = "e"; + f = "f"; + g = "g"; + h = "h"; + i = "i"; + j = "j"; + k = "k"; + l = "l"; + m = "m"; + n = "n"; + o = "o"; + p = "p"; + q = "q"; + r = "r"; + s = "s"; + t = "t"; + u = "u"; + v = "v"; + w = "w"; + x = "x"; + y = "y"; + z = "z"; + }; + foo = { + inherit (alphabet) f o b a r z q u x; + aa = throw "aa"; + }; + alphabetFail = builtins.mapAttrs throw alphabet; +in +[ (builtins.intersectAttrs { a = abort "l1"; } { b = abort "r1"; }) + (builtins.intersectAttrs { a = abort "l2"; } { a = 1; }) + (builtins.intersectAttrs alphabetFail { a = 1; }) + (builtins.intersectAttrs { a = abort "laa"; } alphabet) + (builtins.intersectAttrs alphabetFail { m = 1; }) + (builtins.intersectAttrs { m = abort "lam"; } alphabet) + (builtins.intersectAttrs alphabetFail { n = 1; }) + (builtins.intersectAttrs { n = abort "lan"; } alphabet) + (builtins.intersectAttrs alphabetFail { n = 1; p = 2; }) + (builtins.intersectAttrs { n = abort "lan2"; p = abort "lap"; } alphabet) + (builtins.intersectAttrs alphabetFail { n = 1; p = 2; }) + (builtins.intersectAttrs { n = abort "lan2"; p = abort "lap"; } alphabet) + (builtins.intersectAttrs alphabetFail alphabet) + (builtins.intersectAttrs alphabet foo == builtins.intersectAttrs foo alphabet) +] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-path.exp b/tvix/eval/src/tests/nix_tests/eval-okay-path.exp new file mode 100644 index 0000000000..3ce7f82830 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-path.exp @@ -0,0 +1 @@ +"/nix/store/ya937r4ydw0l6kayq8jkyqaips9c75jm-output" diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220122.exp b/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220122.exp new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220122.exp @@ -0,0 +1 @@ +3 diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220122.nix b/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220122.nix new file mode 100644 index 0000000000..694e9a13b7 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220122.nix @@ -0,0 +1 @@ +((_: _) 1) + ((__: __) 2) diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220125.exp b/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220125.exp new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220125.exp @@ -0,0 +1 @@ +3 diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220125.nix b/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220125.nix new file mode 100644 index 0000000000..4855023739 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-regression-20220125.nix @@ -0,0 +1,2 @@ +((__curPosFoo: __curPosFoo) 1) + ((__curPosBar: __curPosBar) 2) + diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-replacestrings.exp b/tvix/eval/src/tests/nix_tests/eval-okay-replacestrings.exp deleted file mode 100644 index 72e8274d8c..0000000000 --- a/tvix/eval/src/tests/nix_tests/eval-okay-replacestrings.exp +++ /dev/null @@ -1 +0,0 @@ -[ "faabar" "fbar" "fubar" "faboor" "fubar" "XaXbXcX" "X" "a_b" ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-sort.exp b/tvix/eval/src/tests/nix_tests/eval-okay-sort.exp index 148b935163..899119e20e 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-sort.exp +++ b/tvix/eval/src/tests/nix_tests/eval-okay-sort.exp @@ -1 +1 @@ -[ [ 42 77 147 249 483 526 ] [ 526 483 249 147 77 42 ] [ "bar" "fnord" "foo" "xyzzy" ] [ { key = 1; value = "foo"; } { key = 1; value = "fnord"; } { key = 2; value = "bar"; } ] ] +[ [ 42 77 147 249 483 526 ] [ 526 483 249 147 77 42 ] [ "bar" "fnord" "foo" "xyzzy" ] [ { key = 1; value = "foo"; } { key = 1; value = "fnord"; } { key = 2; value = "bar"; } ] [ [ ] [ ] [ 1 ] [ 1 4 ] [ 1 5 ] [ 1 6 ] [ 2 ] [ 2 3 ] [ 3 ] [ 3 ] ] ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-sort.nix b/tvix/eval/src/tests/nix_tests/eval-okay-sort.nix index 8299c3a4a3..50aa78e403 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-sort.nix +++ b/tvix/eval/src/tests/nix_tests/eval-okay-sort.nix @@ -4,5 +4,17 @@ with builtins; (sort (x: y: y < x) [ 483 249 526 147 42 77 ]) (sort lessThan [ "foo" "bar" "xyzzy" "fnord" ]) (sort (x: y: x.key < y.key) - [ { key = 1; value = "foo"; } { key = 2; value = "bar"; } { key = 1; value = "fnord"; } ]) + [ { key = 1; value = "foo"; } { key = 2; value = "bar"; } { key = 1; value = "fnord"; } ]) + (sort lessThan [ + [ 1 6 ] + [ ] + [ 2 3 ] + [ 3 ] + [ 1 5 ] + [ 2 ] + [ 1 ] + [ ] + [ 1 4 ] + [ 3 ] + ]) ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-tail-call-1.exp-disabled b/tvix/eval/src/tests/nix_tests/eval-okay-tail-call-1.exp index f7393e847d..f7393e847d 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-tail-call-1.exp-disabled +++ b/tvix/eval/src/tests/nix_tests/eval-okay-tail-call-1.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-versions.nix b/tvix/eval/src/tests/nix_tests/eval-okay-versions.nix index e63c36586b..e9111f5f43 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-versions.nix +++ b/tvix/eval/src/tests/nix_tests/eval-okay-versions.nix @@ -4,6 +4,7 @@ let name2 = "hello"; name3 = "915resolution-0.5.2"; name4 = "xf86-video-i810-1.7.4"; + name5 = "name-that-ends-with-dash--1.0"; eq = 0; lt = builtins.sub 0 1; @@ -23,6 +24,8 @@ let ((builtins.parseDrvName name3).version == "0.5.2") ((builtins.parseDrvName name4).name == "xf86-video-i810") ((builtins.parseDrvName name4).version == "1.7.4") + ((builtins.parseDrvName name5).name == "name-that-ends-with-dash") + ((builtins.parseDrvName name5).version == "-1.0") (versionTest "1.0" "2.3" lt) (versionTest "2.1" "2.3" lt) (versionTest "2.3" "2.3" eq) diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-xml.exp.xml b/tvix/eval/src/tests/nix_tests/eval-okay-xml.exp.xml index 92b75e0b8b..20099326cc 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-xml.exp.xml +++ b/tvix/eval/src/tests/nix_tests/eval-okay-xml.exp.xml @@ -31,9 +31,9 @@ <attr name="f"> <function> <attrspat> - <attr name="z" /> <attr name="x" /> <attr name="y" /> + <attr name="z" /> </attrspat> </function> </attr> diff --git a/tvix/eval/src/tests/nix_tests/eval-fail-bad-antiquote-2.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-bad-antiquote-2.nix index 3745235ce9..3745235ce9 100644 --- a/tvix/eval/src/tests/nix_tests/eval-fail-bad-antiquote-2.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-bad-antiquote-2.nix diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-fromTOML-timestamps.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-fromTOML-timestamps.nix new file mode 100644 index 0000000000..74cff9470a --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-fromTOML-timestamps.nix @@ -0,0 +1,130 @@ +builtins.fromTOML '' + key = "value" + bare_key = "value" + bare-key = "value" + 1234 = "value" + + "127.0.0.1" = "value" + "character encoding" = "value" + "ʎǝʞ" = "value" + 'key2' = "value" + 'quoted "value"' = "value" + + name = "Orange" + + physical.color = "orange" + physical.shape = "round" + site."google.com" = true + + # This is legal according to the spec, but cpptoml doesn't handle it. + #a.b.c = 1 + #a.d = 2 + + str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF." + + int1 = +99 + int2 = 42 + int3 = 0 + int4 = -17 + int5 = 1_000 + int6 = 5_349_221 + int7 = 1_2_3_4_5 + + hex1 = 0xDEADBEEF + hex2 = 0xdeadbeef + hex3 = 0xdead_beef + + oct1 = 0o01234567 + oct2 = 0o755 + + bin1 = 0b11010110 + + flt1 = +1.0 + flt2 = 3.1415 + flt3 = -0.01 + flt4 = 5e+22 + flt5 = 1e6 + flt6 = -2E-2 + flt7 = 6.626e-34 + flt8 = 9_224_617.445_991_228_313 + + bool1 = true + bool2 = false + + odt1 = 1979-05-27T07:32:00Z + odt2 = 1979-05-27T00:32:00-07:00 + odt3 = 1979-05-27T00:32:00.999999-07:00 + odt4 = 1979-05-27 07:32:00Z + ldt1 = 1979-05-27T07:32:00 + ldt2 = 1979-05-27T00:32:00.999999 + ld1 = 1979-05-27 + lt1 = 07:32:00 + lt2 = 00:32:00.999999 + + arr1 = [ 1, 2, 3 ] + arr2 = [ "red", "yellow", "green" ] + arr3 = [ [ 1, 2 ], [3, 4, 5] ] + arr4 = [ "all", 'strings', """are the same""", ''''type''''] + arr5 = [ [ 1, 2 ], ["a", "b", "c"] ] + + arr7 = [ + 1, 2, 3 + ] + + arr8 = [ + 1, + 2, # this is ok + ] + + [table-1] + key1 = "some string" + key2 = 123 + + + [table-2] + key1 = "another string" + key2 = 456 + + [dog."tater.man"] + type.name = "pug" + + [a.b.c] + [ d.e.f ] + [ g . h . i ] + [ j . "ʞ" . 'l' ] + [x.y.z.w] + + name = { first = "Tom", last = "Preston-Werner" } + point = { x = 1, y = 2 } + animal = { type.name = "pug" } + + [[products]] + name = "Hammer" + sku = 738594937 + + [[products]] + + [[products]] + name = "Nail" + sku = 284758393 + color = "gray" + + [[fruit]] + name = "apple" + + [fruit.physical] + color = "red" + shape = "round" + + [[fruit.variety]] + name = "red delicious" + + [[fruit.variety]] + name = "granny smith" + + [[fruit]] + name = "banana" + + [[fruit.variety]] + name = "plantain" +'' diff --git a/tvix/eval/src/tests/nix_tests/eval-fail-antiquoted-path.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-nonexist-path.nix index f2f08107b5..f2f08107b5 100644 --- a/tvix/eval/src/tests/nix_tests/eval-fail-antiquoted-path.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-nonexist-path.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-fail-scope-5.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-scope-5.nix index f89a65a99b..f89a65a99b 100644 --- a/tvix/eval/src/tests/nix_tests/eval-fail-scope-5.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-scope-5.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-fail-undeclared-arg.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-undeclared-arg.nix index cafdf16362..cafdf16362 100644 --- a/tvix/eval/src/tests/nix_tests/eval-fail-undeclared-arg.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-fail-undeclared-arg.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-attrs6.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-attrs6.exp index b46938032e..b46938032e 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-attrs6.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-attrs6.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-attrs6.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-attrs6.nix index 2e5c85483b..2e5c85483b 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-attrs6.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-attrs6.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-autoargs.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-autoargs.exp index 7a8391786a..7a8391786a 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-autoargs.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-autoargs.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-autoargs.flags b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-autoargs.flags index 217c7a5ae2..217c7a5ae2 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-autoargs.flags +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-autoargs.flags diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-autoargs.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-autoargs.nix index 815f51b1d6..815f51b1d6 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-autoargs.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-autoargs.nix diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.exp new file mode 100644 index 0000000000..03b400cc88 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.exp @@ -0,0 +1 @@ +[ true true true true true true ] diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.nix new file mode 100644 index 0000000000..50a78d946e --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context-introspection.nix @@ -0,0 +1,41 @@ +let + drv = derivation { + name = "fail"; + builder = "/bin/false"; + system = "x86_64-linux"; + outputs = [ "out" "foo" ]; + }; + + path = "${./eval-okay-context-introspection.nix}"; + + desired-context = { + "${builtins.unsafeDiscardStringContext path}" = { + path = true; + }; + "${builtins.unsafeDiscardStringContext drv.drvPath}" = { + outputs = [ "foo" "out" ]; + allOutputs = true; + }; + }; + + combo-path = "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}"; + legit-context = builtins.getContext combo-path; + + reconstructed-path = builtins.appendContext + (builtins.unsafeDiscardStringContext combo-path) + desired-context; + + # Eta rule for strings with context. + etaRule = str: + str == builtins.appendContext + (builtins.unsafeDiscardStringContext str) + (builtins.getContext str); + +in [ + (legit-context == desired-context) + (reconstructed-path == combo-path) + (etaRule "foo") + (etaRule drv.drvPath) + (etaRule drv.foo.outPath) + (etaRule (builtins.unsafeDiscardOutputDependency drv.drvPath)) +] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-context.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context.exp index 2f535bdbc4..2f535bdbc4 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-context.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-context.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context.nix index 7b9531cfe9..7b9531cfe9 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-context.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-context.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-curpos.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-curpos.exp index 65fd65b4d0..65fd65b4d0 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-curpos.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-curpos.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-curpos.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-curpos.nix index b79553df0b..b79553df0b 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-curpos.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-curpos.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with.exp index 8e7c61ab8e..8e7c61ab8e 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with.nix index 3fb023e1cd..3fb023e1cd 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-delayed-with.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-delayed-with.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-eq-derivations.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-eq-derivations.exp index ec04aab6ae..ec04aab6ae 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-eq-derivations.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-eq-derivations.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-eq-derivations.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-eq-derivations.nix index d526cb4a21..d526cb4a21 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-eq-derivations.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-eq-derivations.nix diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-floor-ceil.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-floor-ceil.exp new file mode 100644 index 0000000000..81f80420b9 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-floor-ceil.exp @@ -0,0 +1 @@ +"23;24;23;23" diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-floor-ceil.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-floor-ceil.nix new file mode 100644 index 0000000000..d76a0d86ea --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-floor-ceil.nix @@ -0,0 +1,9 @@ +with import ./lib.nix; + +let + n1 = builtins.floor 23.5; + n2 = builtins.ceil 23.5; + n3 = builtins.floor 23; + n4 = builtins.ceil 23; +in + builtins.concatStringsSep ";" (map toString [ n1 n2 n3 n4 ]) diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML-timestamps.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML-timestamps.exp new file mode 100644 index 0000000000..08b3c69a6c --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML-timestamps.exp @@ -0,0 +1 @@ +{ "1234" = "value"; "127.0.0.1" = "value"; a = { b = { c = { }; }; }; arr1 = [ 1 2 3 ]; arr2 = [ "red" "yellow" "green" ]; arr3 = [ [ 1 2 ] [ 3 4 5 ] ]; arr4 = [ "all" "strings" "are the same" "type" ]; arr5 = [ [ 1 2 ] [ "a" "b" "c" ] ]; arr7 = [ 1 2 3 ]; arr8 = [ 1 2 ]; bare-key = "value"; bare_key = "value"; bin1 = 214; bool1 = true; bool2 = false; "character encoding" = "value"; d = { e = { f = { }; }; }; dog = { "tater.man" = { type = { name = "pug"; }; }; }; flt1 = 1; flt2 = 3.1415; flt3 = -0.01; flt4 = 5e+22; flt5 = 1e+06; flt6 = -0.02; flt7 = 6.626e-34; flt8 = 9.22462e+06; fruit = [ { name = "apple"; physical = { color = "red"; shape = "round"; }; variety = [ { name = "red delicious"; } { name = "granny smith"; } ]; } { name = "banana"; variety = [ { name = "plantain"; } ]; } ]; g = { h = { i = { }; }; }; hex1 = 3735928559; hex2 = 3735928559; hex3 = 3735928559; int1 = 99; int2 = 42; int3 = 0; int4 = -17; int5 = 1000; int6 = 5349221; int7 = 12345; j = { "ʞ" = { l = { }; }; }; key = "value"; key2 = "value"; ld1 = { _type = "timestamp"; value = "1979-05-27"; }; ldt1 = { _type = "timestamp"; value = "1979-05-27T07:32:00"; }; ldt2 = { _type = "timestamp"; value = "1979-05-27T00:32:00.999999"; }; lt1 = { _type = "timestamp"; value = "07:32:00"; }; lt2 = { _type = "timestamp"; value = "00:32:00.999999"; }; name = "Orange"; oct1 = 342391; oct2 = 493; odt1 = { _type = "timestamp"; value = "1979-05-27T07:32:00Z"; }; odt2 = { _type = "timestamp"; value = "1979-05-27T00:32:00-07:00"; }; odt3 = { _type = "timestamp"; value = "1979-05-27T00:32:00.999999-07:00"; }; odt4 = { _type = "timestamp"; value = "1979-05-27T07:32:00Z"; }; physical = { color = "orange"; shape = "round"; }; products = [ { name = "Hammer"; sku = 738594937; } { } { color = "gray"; name = "Nail"; sku = 284758393; } ]; "quoted \"value\"" = "value"; site = { "google.com" = true; }; str = "I'm a string. \"You can quote me\". Name\tJosé\nLocation\tSF."; table-1 = { key1 = "some string"; key2 = 123; }; table-2 = { key1 = "another string"; key2 = 456; }; x = { y = { z = { w = { animal = { type = { name = "pug"; }; }; name = { first = "Tom"; last = "Preston-Werner"; }; point = { x = 1; y = 2; }; }; }; }; }; "ʎǝʞ" = "value"; } diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML-timestamps.flags b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML-timestamps.flags new file mode 100644 index 0000000000..9ed39dc6ba --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML-timestamps.flags @@ -0,0 +1 @@ +--extra-experimental-features parse-toml-timestamps diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML-timestamps.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML-timestamps.nix new file mode 100644 index 0000000000..74cff9470a --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML-timestamps.nix @@ -0,0 +1,130 @@ +builtins.fromTOML '' + key = "value" + bare_key = "value" + bare-key = "value" + 1234 = "value" + + "127.0.0.1" = "value" + "character encoding" = "value" + "ʎǝʞ" = "value" + 'key2' = "value" + 'quoted "value"' = "value" + + name = "Orange" + + physical.color = "orange" + physical.shape = "round" + site."google.com" = true + + # This is legal according to the spec, but cpptoml doesn't handle it. + #a.b.c = 1 + #a.d = 2 + + str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF." + + int1 = +99 + int2 = 42 + int3 = 0 + int4 = -17 + int5 = 1_000 + int6 = 5_349_221 + int7 = 1_2_3_4_5 + + hex1 = 0xDEADBEEF + hex2 = 0xdeadbeef + hex3 = 0xdead_beef + + oct1 = 0o01234567 + oct2 = 0o755 + + bin1 = 0b11010110 + + flt1 = +1.0 + flt2 = 3.1415 + flt3 = -0.01 + flt4 = 5e+22 + flt5 = 1e6 + flt6 = -2E-2 + flt7 = 6.626e-34 + flt8 = 9_224_617.445_991_228_313 + + bool1 = true + bool2 = false + + odt1 = 1979-05-27T07:32:00Z + odt2 = 1979-05-27T00:32:00-07:00 + odt3 = 1979-05-27T00:32:00.999999-07:00 + odt4 = 1979-05-27 07:32:00Z + ldt1 = 1979-05-27T07:32:00 + ldt2 = 1979-05-27T00:32:00.999999 + ld1 = 1979-05-27 + lt1 = 07:32:00 + lt2 = 00:32:00.999999 + + arr1 = [ 1, 2, 3 ] + arr2 = [ "red", "yellow", "green" ] + arr3 = [ [ 1, 2 ], [3, 4, 5] ] + arr4 = [ "all", 'strings', """are the same""", ''''type''''] + arr5 = [ [ 1, 2 ], ["a", "b", "c"] ] + + arr7 = [ + 1, 2, 3 + ] + + arr8 = [ + 1, + 2, # this is ok + ] + + [table-1] + key1 = "some string" + key2 = 123 + + + [table-2] + key1 = "another string" + key2 = 456 + + [dog."tater.man"] + type.name = "pug" + + [a.b.c] + [ d.e.f ] + [ g . h . i ] + [ j . "ʞ" . 'l' ] + [x.y.z.w] + + name = { first = "Tom", last = "Preston-Werner" } + point = { x = 1, y = 2 } + animal = { type.name = "pug" } + + [[products]] + name = "Hammer" + sku = 738594937 + + [[products]] + + [[products]] + name = "Nail" + sku = 284758393 + color = "gray" + + [[fruit]] + name = "apple" + + [fruit.physical] + color = "red" + shape = "round" + + [[fruit.variety]] + name = "red delicious" + + [[fruit.variety]] + name = "granny smith" + + [[fruit]] + name = "banana" + + [[fruit.variety]] + name = "plantain" +'' diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-functionargs.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-functionargs.exp new file mode 100644 index 0000000000..7f9ac40e81 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-functionargs.exp @@ -0,0 +1 @@ +{ column = 11; file = "eval-okay-getattrpos-functionargs.nix"; line = 2; } diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-functionargs.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-functionargs.nix new file mode 100644 index 0000000000..11d6bb0e3a --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-functionargs.nix @@ -0,0 +1,4 @@ +let + fun = { foo }: {}; + pos = builtins.unsafeGetAttrPos "foo" (builtins.functionArgs fun); +in { inherit (pos) column line; file = baseNameOf pos.file; } diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-getattrpos-undefined.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-undefined.exp index 19765bd501..19765bd501 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-getattrpos-undefined.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-undefined.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-getattrpos-undefined.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-undefined.nix index 14dd38f773..14dd38f773 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-getattrpos-undefined.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos-undefined.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-getattrpos.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos.exp index 469249bbc6..469249bbc6 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-getattrpos.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-getattrpos.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos.nix index ca6b079615..ca6b079615 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-getattrpos.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-getattrpos.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-import.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-import.exp index c508125b55..c508125b55 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-import.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-import.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-import.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-import.nix index 0b18d94131..76213a9541 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-import.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-import.nix @@ -6,6 +6,6 @@ let scopedImport = attrs: fn: scopedImport (overrides // attrs) fn; builtins = builtins // overrides; - } // import ./lib.nix; + } // import ./../lib.nix; -in scopedImport overrides ./imported.nix +in scopedImport overrides ./../imported.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-overrides.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-overrides.exp index 0cfbf08886..0cfbf08886 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-overrides.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-overrides.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-overrides.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-overrides.nix index 358742b36e..358742b36e 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-overrides.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-overrides.nix diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-path-antiquotation.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-path-antiquotation.exp new file mode 100644 index 0000000000..5b8ea02438 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-path-antiquotation.exp @@ -0,0 +1 @@ +{ absolute = /foo; expr = /pwd/lang/foo/bar; home = /fake-home/foo; notfirst = /pwd/lang/bar/foo; simple = /pwd/lang/foo; slashes = /foo/bar; surrounded = /pwd/lang/a-foo-b; } diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-path-antiquotation.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-path-antiquotation.nix new file mode 100644 index 0000000000..497d7c1c75 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-path-antiquotation.nix @@ -0,0 +1,12 @@ +let + foo = "foo"; +in +{ + simple = ./${foo}; + surrounded = ./a-${foo}-b; + absolute = /${foo}; + expr = ./${foo + "/bar"}; + home = ~/${foo}; + notfirst = ./bar/${foo}; + slashes = /${foo}/${"bar"}; +} diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-path.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-path.nix index e67168cf3e..e67168cf3e 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-path.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-path.nix diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readDir.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readDir.exp new file mode 100644 index 0000000000..6413f6d4f9 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readDir.exp @@ -0,0 +1 @@ +{ bar = "regular"; foo = "directory"; ldir = "symlink"; linked = "symlink"; } diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-readDir.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readDir.nix.disabled index a7ec9292aa..a7ec9292aa 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-readDir.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readDir.nix.disabled diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readFileType.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readFileType.exp new file mode 100644 index 0000000000..6413f6d4f9 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readFileType.exp @@ -0,0 +1 @@ +{ bar = "regular"; foo = "directory"; ldir = "symlink"; linked = "symlink"; } diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readFileType.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readFileType.nix new file mode 100644 index 0000000000..174fb6c3a0 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-readFileType.nix @@ -0,0 +1,6 @@ +{ + bar = builtins.readFileType ./readDir/bar; + foo = builtins.readFileType ./readDir/foo; + linked = builtins.readFileType ./readDir/linked; + ldir = builtins.readFileType ./readDir/ldir; +} diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-replacestrings.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-replacestrings.exp new file mode 100644 index 0000000000..eac67c5fed --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-replacestrings.exp @@ -0,0 +1 @@ +[ "faabar" "fbar" "fubar" "faboor" "fubar" "XaXbXcX" "X" "a_b" "fubar" ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-replacestrings.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-replacestrings.nix index bd8031fc00..a803e65199 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-replacestrings.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-replacestrings.nix @@ -8,4 +8,5 @@ with builtins; (replaceStrings [""] ["X"] "abc") (replaceStrings [""] ["X"] "") (replaceStrings ["-"] ["_"] "a-b") + (replaceStrings ["oo" "XX"] ["u" (throw "unreachable")] "foobar") ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-search-path.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-search-path.exp index 4519bc406d..4519bc406d 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-search-path.exp +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-search-path.exp diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-search-path.flags b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-search-path.flags index a28e682100..a28e682100 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-search-path.flags +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-search-path.flags diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-search-path.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-search-path.nix index cca41f821f..6fe33decc0 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-search-path.nix +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-search-path.nix @@ -1,10 +1,9 @@ with import ./lib.nix; with builtins; -assert pathExists <nix/buildenv.nix>; +assert isFunction (import <nix/fetchurl.nix>); -assert length __nixPath == 6; -assert length (filter (x: x.prefix == "nix") __nixPath) == 1; +assert length __nixPath == 5; assert length (filter (x: baseNameOf x.path == "dir4") __nixPath) == 1; import <a.nix> + import <b.nix> + import <c.nix> + import <dir5/c.nix> diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-zipAttrsWith.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-zipAttrsWith.exp new file mode 100644 index 0000000000..9c0b15d22b --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-zipAttrsWith.exp @@ -0,0 +1 @@ +{ "0" = { n = "0"; v = [ 5 23 29 ]; }; "1" = { n = "1"; v = [ 7 30 ]; }; "2" = { n = "2"; v = [ 18 ]; }; "4" = { n = "4"; v = [ 10 ]; }; "5" = { n = "5"; v = [ 15 25 26 31 ]; }; "6" = { n = "6"; v = [ 3 14 ]; }; "7" = { n = "7"; v = [ 12 ]; }; "8" = { n = "8"; v = [ 2 6 8 9 ]; }; "9" = { n = "9"; v = [ 0 16 ]; }; a = { n = "a"; v = [ 17 21 22 27 ]; }; c = { n = "c"; v = [ 11 24 ]; }; d = { n = "d"; v = [ 4 13 28 ]; }; e = { n = "e"; v = [ 20 ]; }; f = { n = "f"; v = [ 1 19 ]; }; } diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-zipAttrsWith.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-zipAttrsWith.nix new file mode 100644 index 0000000000..e5d4cdccb7 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-zipAttrsWith.nix @@ -0,0 +1,9 @@ +with import ./../lib.nix; + +let + str = builtins.hashString "sha256" "test"; +in +builtins.zipAttrsWith + (n: v: { inherit n v; }) + (map (n: { ${builtins.substring n 1 str} = n; }) + (range 0 31)) diff --git a/tvix/eval/src/tests/nix_tests/readDir/bar b/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/bar index e69de29bb2..e69de29bb2 100644 --- a/tvix/eval/src/tests/nix_tests/readDir/bar +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/bar diff --git a/tvix/eval/src/tests/nix_tests/readDir/foo/git-hates-directories b/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/foo/git-hates-directories index e69de29bb2..e69de29bb2 100644 --- a/tvix/eval/src/tests/nix_tests/readDir/foo/git-hates-directories +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/foo/git-hates-directories diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/ldir b/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/ldir new file mode 120000 index 0000000000..1910281566 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/ldir @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/linked b/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/linked new file mode 120000 index 0000000000..c503f86a0c --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/notyetpassing/readDir/linked @@ -0,0 +1 @@ +foo/git-hates-directories \ No newline at end of file diff --git a/tvix/eval/src/tests/nix_tests/parse-fail-eof-in-string.nix b/tvix/eval/src/tests/nix_tests/parse-fail-eof-in-string.nix new file mode 100644 index 0000000000..19775d2ec8 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/parse-fail-eof-in-string.nix @@ -0,0 +1,3 @@ +# https://github.com/NixOS/nix/issues/6562 +# Note that this file must not end with a newline. +a 1"$ \ No newline at end of file diff --git a/tvix/eval/src/tests/nix_tests/parse-okay-url.nix b/tvix/eval/src/tests/nix_tests/parse-okay-url.nix index fce3b13ee6..08de27d0a4 100644 --- a/tvix/eval/src/tests/nix_tests/parse-okay-url.nix +++ b/tvix/eval/src/tests/nix_tests/parse-okay-url.nix @@ -3,5 +3,6 @@ http://www2.mplayerhq.hu/MPlayer/releases/fonts/font-arial-iso-8859-1.tar.bz2 http://losser.st-lab.cs.uu.nl/~armijn/.nix/gcc-3.3.4-static-nix.tar.gz http://fpdownload.macromedia.com/get/shockwave/flash/english/linux/7.0r25/install_flash_player_7_linux.tar.gz + https://ftp5.gwdg.de/pub/linux/archlinux/extra/os/x86_64/unzip-6.0-14-x86_64.pkg.tar.zst ftp://ftp.gtk.org/pub/gtk/v1.2/gtk+-1.2.10.tar.gz ] diff --git a/tvix/eval/src/tests/one_offs.rs b/tvix/eval/src/tests/one_offs.rs new file mode 100644 index 0000000000..21e9144baf --- /dev/null +++ b/tvix/eval/src/tests/one_offs.rs @@ -0,0 +1,36 @@ +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_pure(); + eval.src_builtins.push(("testSourceBuiltin", "42")); + + let result = eval.evaluate("builtins.testSourceBuiltin", None); + 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_pure().evaluate(/* code = */ "x", None); + + assert_eq!(result.errors.len(), 1); + + assert!(matches!( + result.errors[0].kind, + ErrorKind::UnknownStaticVariable + )); +} diff --git a/tvix/eval/src/tests/tvix_tests/directory/default.nix b/tvix/eval/src/tests/tvix_tests/directory/default.nix new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/directory/default.nix @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-substring-negative-start.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-substring-negative-start.nix new file mode 100644 index 0000000000..bc7a16ded8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-substring-negative-start.nix @@ -0,0 +1,3 @@ +# Negative start is illegal, but negative length works, see +# eval-okay-builtins-substring-negative-length.nix +builtins.substring (-1) 1 "Wiggly Donkers" diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-thunk-error.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-thunk-error.nix new file mode 100644 index 0000000000..6df79d13f4 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-thunk-error.nix @@ -0,0 +1 @@ +builtins.genList (_: { }.foo) 1 diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-tojson-tostring-notcallable.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-tojson-tostring-notcallable.nix new file mode 100644 index 0000000000..345b76fde0 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-tojson-tostring-notcallable.nix @@ -0,0 +1,5 @@ +# attribute sets with a non-callable `__toString` can not be +# serialised to JSON. +builtins.toJSON { + __toString = 42; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-tojson-tostring-strong.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-tojson-tostring-strong.nix new file mode 100644 index 0000000000..d1c72dc678 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-builtins-tojson-tostring-strong.nix @@ -0,0 +1,6 @@ +# String coercions when using builtins.toJSON on an attribute set with +# a `__toString` attribute should be weak. +builtins.toJSON { + __toString = self: self.x; + x = 42; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-closed-formals.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-closed-formals.nix new file mode 100644 index 0000000000..a0cd20c470 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-closed-formals.nix @@ -0,0 +1 @@ +({ x }: x) { x = 1; y = 2; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-deep-forced-thunk-error.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-deep-forced-thunk-error.nix new file mode 100644 index 0000000000..b7a7583022 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-deep-forced-thunk-error.nix @@ -0,0 +1 @@ +[ (throw "error!") ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-deepseq.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-deepseq.nix new file mode 100644 index 0000000000..9baa49b063 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-deepseq.nix @@ -0,0 +1 @@ +builtins.deepSeq { x = abort "foo"; } 456 diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-division-by-zero-float.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-division-by-zero-float.nix new file mode 100644 index 0000000000..82dd687321 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-division-by-zero-float.nix @@ -0,0 +1 @@ +1.0 / 0.0 diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-division-by-zero-int.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-division-by-zero-int.nix new file mode 100644 index 0000000000..72dca4d5e4 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-division-by-zero-int.nix @@ -0,0 +1 @@ +1 / 0 diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-foldlStrict-strict-op-application.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-foldlStrict-strict-op-application.nix new file mode 100644 index 0000000000..adc029b2f2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-foldlStrict-strict-op-application.nix @@ -0,0 +1,4 @@ +builtins.foldl' + (_: f: f null) + (throw "This doesn't explode") + [ (_: throw "Not the final value, but is still forced!") (_: 23) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-force-before-value-pointer-equality.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-force-before-value-pointer-equality.nix new file mode 100644 index 0000000000..a2182a508f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-force-before-value-pointer-equality.nix @@ -0,0 +1,5 @@ +let + x = throw "I have been forced"; +in + +x == x diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-function-formals-typecheck.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-function-formals-typecheck.nix new file mode 100644 index 0000000000..0108f958bf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-function-formals-typecheck.nix @@ -0,0 +1,2 @@ +# A function with formal set arguments forces its argument set and verifies its type. +({ ... }@args: 42) [ ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-getEnv-coercion.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-getEnv-coercion.nix new file mode 100644 index 0000000000..fe48a5690c --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-getEnv-coercion.nix @@ -0,0 +1 @@ +builtins.getEnv { var = "PATH"; __toString = self: self.var; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-infinite-recursion.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-infinite-recursion.nix new file mode 100644 index 0000000000..5e4fd3789c --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-infinite-recursion.nix @@ -0,0 +1 @@ +let x = x; in x diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-outer-value-never-pointer-equal.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-outer-value-never-pointer-equal.nix new file mode 100644 index 0000000000..a8c3cedf61 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-outer-value-never-pointer-equal.nix @@ -0,0 +1,7 @@ +# For an explanation of this behavior see //tvix/docs/value-pointer-equality.md +let + x = { foo = throw "foo"; }; +in + +# while `builtins.seq x null` would succeed, this fails! +x == x diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-parsedrvname-coerce.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-parsedrvname-coerce.nix new file mode 100644 index 0000000000..a1218de3fe --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-parsedrvname-coerce.nix @@ -0,0 +1 @@ +builtins.parseDrvName { outPath = "lol"; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-remove.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-remove.nix new file mode 100644 index 0000000000..93dd8ccd45 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-remove.nix @@ -0,0 +1,5 @@ +let { +attrs = { x = 123; y = 456; }; + +body = (removeAttrs attrs [ "x" ]).x; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-seq.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-seq.nix new file mode 100644 index 0000000000..cddbbfd326 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-seq.nix @@ -0,0 +1 @@ +builtins.seq (abort "foo") 2 diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-throw-abort-cannot-be-caught.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-throw-abort-cannot-be-caught.nix new file mode 100644 index 0000000000..10781cb4ea --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-throw-abort-cannot-be-caught.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.throw (builtins.abort "abc"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-abort-throw-can-be-caught.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-abort-throw-can-be-caught.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-abort-throw-can-be-caught.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-abort-throw-can-be-caught.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-abort-throw-can-be-caught.nix new file mode 100644 index 0000000000..aebeca1dad --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-abort-throw-can-be-caught.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.abort (builtins.throw "abc"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-access-strange-identifier.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-access-strange-identifier.nix index 8e282d1280..433f53dc56 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-access-strange-identifier.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-access-strange-identifier.nix @@ -2,7 +2,8 @@ let # There is no syntax for accessing this identifier in an ordinary # way. "foo bar" = 42; -in ({ +in +({ # but we *can* inherit it back out inherit "foo bar"; })."foo bar" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-add-paths.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-add-paths.exp new file mode 100644 index 0000000000..94ba9a881a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-add-paths.exp @@ -0,0 +1 @@ +[ /bin /binbar /binbar /binbar /binbar /bin/bar /bin/bin ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-add-paths.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-add-paths.nix new file mode 100644 index 0000000000..462f670882 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-add-paths.nix @@ -0,0 +1,9 @@ +[ + (/bin + "/") + (/bin + "bar") + (let name = "bar"; in /bin + name) + (let name = "bar"; in /bin + "${name}") + (let name = "bar"; in /bin + "/" + "${name}") + (let name = "bar"; in /bin + "/${name}") + (/bin + /bin) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-assert-thunk-condition.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-assert-thunk-condition.nix index 8934b3d8cf..ac65f5814d 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-assert-thunk-condition.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-assert-thunk-condition.nix @@ -3,5 +3,5 @@ let in # The function application here will become a thunk which verifies that -# assert forces the condition expression correctly. + # assert forces the condition expression correctly. assert condition 21 42; 21 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-attempt-to-call-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-attempt-to-call-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-attempt-to-call-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-attempt-to-call-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-attempt-to-call-catchable.nix new file mode 100644 index 0000000000..f4ef72a88b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-attempt-to-call-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (throw "fred" 5)).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-attr-key-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-attr-key-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-attr-key-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-attr-key-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-attr-key-catchable.nix new file mode 100644 index 0000000000..b9d835bcc5 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-attr-key-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval { "${builtins.throw "a"}" = "b"; }).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-inherit-literal.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-inherit-literal.nix index 587aec8933..9ecb4e9880 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-inherit-literal.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-inherit-literal.nix @@ -1,2 +1,2 @@ # the 'from' part of an `inherit` can be any expression. -{ inherit ({a = 15;}) a; }.a +{ inherit ({ a = 15; }) a; }.a diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-update-empty-lhs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-update-empty-lhs.nix index 9596be22b8..973170cdd5 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-update-empty-lhs.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-update-empty-lhs.nix @@ -1 +1 @@ -{} // { a = "ok"; } +{ } // { a = "ok"; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-update-empty-rhs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-update-empty-rhs.nix index 117c011413..f51b88e93a 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-update-empty-rhs.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-attrs-update-empty-rhs.nix @@ -1 +1 @@ -{ a = "ok"; } // {} +{ a = "ok"; } // { } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof-propagate-catchables.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof-propagate-catchables.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof-propagate-catchables.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof-propagate-catchables.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof-propagate-catchables.nix new file mode 100644 index 0000000000..240736b12a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof-propagate-catchables.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.baseNameOf (throw "jill"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.exp new file mode 100644 index 0000000000..60a773f4af --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.exp @@ -0,0 +1 @@ +[ "bar" "foo" "" "bar" "." "" "" "" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.nix new file mode 100644 index 0000000000..bc59613f54 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.nix @@ -0,0 +1,10 @@ +[ + (builtins.baseNameOf /foo/bar) + (builtins.baseNameOf "foo") + (builtins.baseNameOf "foo///") + (builtins.baseNameOf "foo/bar") + (builtins.baseNameOf "./.") + (builtins.baseNameOf "") + (builtins.baseNameOf /.) + (builtins.toString (builtins.baseNameOf /.)) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all-propagate-catchable.exp new file mode 100644 index 0000000000..48e341f4d8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all-propagate-catchable.nix new file mode 100644 index 0000000000..8902e27c45 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all-propagate-catchable.nix @@ -0,0 +1 @@ +map (e: (builtins.tryEval e).success) [ (builtins.all (builtins.throw "a") [ "" ]) (builtins.all (x: true) (builtins.throw "b")) (builtins.all (_: builtins.throw "x") [ "" ]) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all.exp new file mode 100644 index 0000000000..82ca7e6b6d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all.exp @@ -0,0 +1 @@ +[ true true false false false false true true false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all.nix new file mode 100644 index 0000000000..12d62632dd --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-all.nix @@ -0,0 +1,15 @@ +[ + (builtins.all (x: x) [ ]) + (builtins.all (x: x) [ true true true ]) + (builtins.all (x: x) [ false false false ]) + (builtins.all (x: x) [ true true false ]) + (builtins.all (x: x) [ false true true ]) + + # evaluation should short-circuit + (builtins.all (x: x) [ true false (builtins.abort "should be unreachable") ]) + + # arbitrary functions supported + (builtins.all (x: x * 2 == 42) [ ]) + (builtins.all (x: x * 2 == 42) [ 21 21 21 ]) + (builtins.all (x: x * 2 == 42) [ 1 2 3 ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any-propagate-catchable.exp new file mode 100644 index 0000000000..48e341f4d8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any-propagate-catchable.nix new file mode 100644 index 0000000000..8db5c0c6dc --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any-propagate-catchable.nix @@ -0,0 +1 @@ +map (e: (builtins.tryEval e).success) [ (builtins.any (builtins.throw "a") [ "" ]) (builtins.any (x: true) (builtins.throw "b")) (builtins.any (_: builtins.throw "a") [ "" ]) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any.exp new file mode 100644 index 0000000000..d6846ac3f7 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any.exp @@ -0,0 +1 @@ +[ false true false true true true false true false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any.nix new file mode 100644 index 0000000000..2c659f130b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-any.nix @@ -0,0 +1,15 @@ +[ + (builtins.any (x: x) [ ]) + (builtins.any (x: x) [ true true true ]) + (builtins.any (x: x) [ false false false ]) + (builtins.any (x: x) [ true true false ]) + (builtins.any (x: x) [ false true true ]) + + # evaluation should short-circuit + (builtins.any (x: x) [ false true (builtins.abort "should be unreachable") ]) + + # arbitrary functions supported + (builtins.any (x: x * 2 == 42) [ ]) + (builtins.any (x: x * 2 == 42) [ 7 21 42 ]) + (builtins.any (x: x * 2 == 42) [ 1 2 3 ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrnames.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrnames.nix index 67f7dcee56..82240a0647 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrnames.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrnames.nix @@ -1,5 +1,5 @@ [ - (builtins.attrNames {}) + (builtins.attrNames { }) (builtins.attrNames { foo = 1; bar = 2; baz = 3; }) (builtins.attrNames { Foo = 1; bar = 2; Baz = 3; }) (builtins.attrNames { diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues-propagate-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues-propagate-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues-propagate-catchable.nix new file mode 100644 index 0000000000..b8c15c8748 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues-propagate-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.attrValues (builtins.throw "a"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.nix index 5eced31f0d..ce6c5c3816 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.nix @@ -1,4 +1,4 @@ [ - (builtins.attrValues {}) + (builtins.attrValues { }) (builtins.attrValues { foo = 1; bar = 2; baz = 3; }) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-builtins.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-builtins.exp new file mode 100644 index 0000000000..27ba77ddaf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-builtins.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-builtins.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-builtins.nix new file mode 100644 index 0000000000..434ccf8049 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-builtins.nix @@ -0,0 +1 @@ +[ builtins ] == [ builtins.builtins ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-catattrs-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-catattrs-propagate-catchable.exp new file mode 100644 index 0000000000..c3bb809c9f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-catattrs-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-catattrs-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-catattrs-propagate-catchable.nix new file mode 100644 index 0000000000..5385591f77 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-catattrs-propagate-catchable.nix @@ -0,0 +1 @@ +map (e: (builtins.tryEval e).success) [ (builtins.catAttrs "a" (builtins.throw "b")) (builtins.catAttrs (builtins.throw "a") { a = 1; }) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-compareVersions.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-compareVersions.nix index cce554b449..40a90b5070 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-compareVersions.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-compareVersions.nix @@ -4,7 +4,7 @@ let ord1 = builtins.compareVersions a b; ord2 = builtins.compareVersions b a; in - assert ord1 == -ord2; ord1; + assert ord1 == -ord2; ord1; in [ diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists-propagate-catchable.exp new file mode 100644 index 0000000000..c82ddd8a80 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false true ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists-propagate-catchable.nix new file mode 100644 index 0000000000..8071daf7fb --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists-propagate-catchable.nix @@ -0,0 +1 @@ +map (e: (builtins.tryEval e).success) [ (builtins.concatLists (builtins.throw "a")) (builtins.concatLists [ [ ] (builtins.throw "a") ]) (builtins.concatLists [ [ ] [ ] [ builtins.throw "a" ] ]) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists.exp new file mode 100644 index 0000000000..64ae529ac2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists.exp @@ -0,0 +1 @@ +[ [ ] [ 1 2 3 4 5 6 ] [ [ 1 ] [ 2 ] [ 3 ] ] [ 1 2 3 4 5 6 ] ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists.nix new file mode 100644 index 0000000000..19ef5eba11 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-lists.nix @@ -0,0 +1,6 @@ +[ + (builtins.concatLists [ ]) + (builtins.concatLists [ [ 1 2 ] [ 3 4 ] [ 5 6 ] ]) + (builtins.concatLists [ [ [ 1 ] [ 2 ] ] [ [ 3 ] ] [ ] ]) + (builtins.concatLists [ [ 1 2 ] [ ] [ 3 4 ] [ ] [ 5 6 ] ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-map-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-map-propagate-catchable.exp new file mode 100644 index 0000000000..48e341f4d8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-map-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-map-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-map-propagate-catchable.nix new file mode 100644 index 0000000000..740f0d3fbc --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-map-propagate-catchable.nix @@ -0,0 +1 @@ +map (e: (builtins.tryEval e).success) [ (builtins.concatMap (builtins.throw "a") [ "" ]) (builtins.concatMap (_: builtins.throw "x") [ "" ]) (builtins.concatMap (_: [ ]) (builtins.throw "a")) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-strings-sep-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-strings-sep-propagate-catchable.exp new file mode 100644 index 0000000000..48e341f4d8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-strings-sep-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-strings-sep-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-strings-sep-propagate-catchable.nix new file mode 100644 index 0000000000..ce5ce4170f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-concat-strings-sep-propagate-catchable.nix @@ -0,0 +1 @@ +map (e: (builtins.tryEval e).success) [ (builtins.concatStringsSep (builtins.throw "a") [ "" ]) (builtins.concatStringsSep "," (builtins.throw "a")) (builtins.concatStringsSep "," [ "a" (builtins.throw "a") ]) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp index 73e9bc33b0..44154ba6a6 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp @@ -1 +1 @@ -[ 3 7 0 1 0 0.5 0.5 0.5 42 ] +[ 3 7 0 1 0 0.5 0.5 0.5 42 1 1 -1 -1 -1 1 1 -1 -1 -1 1 1 -1 -1 -1 -74711 -74711 -74711 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix index 98b8b74bdf..dc6ce27815 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix @@ -8,4 +8,27 @@ (builtins.div 1 2.0) (builtins.div 1.0 2.0) (builtins.div (builtins.div 84 4) 0.5) + + # builtins.div should truncate towards 0 + (builtins.div 3 2) + (builtins.div (-3) (-2)) + (builtins.div (-3) 2) + (builtins.div 3 (-2)) + (-(builtins.div 3 2)) + + (builtins.div 4 3) + (builtins.div (-4) (-3)) + (builtins.div (-4) 3) + (builtins.div 4 (-3)) + (-(builtins.div 4 3)) + + (builtins.div 5 3) + (builtins.div (-5) (-3)) + (builtins.div (-5) 3) + (builtins.div 5 (-3)) + (-(builtins.div 5 3)) + + (builtins.div 2147812578 (-28748)) + (builtins.div (-2147812578) 28748) + (-(builtins.div 2147812578 28748)) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.nix new file mode 100644 index 0000000000..97be4b013c --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.elemAt (throw "fred") 0)).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-catchable.nix new file mode 100644 index 0000000000..98d90b01bb --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.filter (_: throw "fred") [ 3 ])).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-propagate-catchable.exp new file mode 100644 index 0000000000..48e341f4d8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-propagate-catchable.nix new file mode 100644 index 0000000000..715a0ce34f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-filter-propagate-catchable.nix @@ -0,0 +1 @@ +map (e: (builtins.tryEval e).success) [ (builtins.filter (builtins.throw "a") [ "" ]) (builtins.filter (x: true) (builtins.throw "b")) (builtins.filter (_: builtins.throw "x") [ "" ]) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-foldl-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-foldl-propagate-catchable.exp new file mode 100644 index 0000000000..7bf6c63466 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-foldl-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false false true true ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-foldl-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-foldl-propagate-catchable.nix new file mode 100644 index 0000000000..c11a21ce1e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-foldl-propagate-catchable.nix @@ -0,0 +1,8 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.foldl' (builtins.throw "a") { } [{ } { } { }]) + (builtins.foldl' (x: y: x // y) { } (builtins.throw "b")) + (builtins.foldl' (_: _: builtins.throw "x") { } [{ }]) + (builtins.foldl' (x: y: x // y) (builtins.throw "x") [{ }]) + (builtins.foldl' (x: y: x // y) { } [{ } { a = builtins.throw "z"; } { }]) + (builtins.foldl' (x: y: x // y) { } [{ } { b = 3; a = builtins.throw "u"; } { }]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-from-json-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-from-json-propagate-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-from-json-propagate-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-from-json-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-from-json-propagate-catchable.nix new file mode 100644 index 0000000000..aa973c1352 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-from-json-propagate-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.fromJSON (builtins.throw "a"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-function-args-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-function-args-propagate-catchable.exp new file mode 100644 index 0000000000..bd52bff2fa --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-function-args-propagate-catchable.exp @@ -0,0 +1 @@ +[ true false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-function-args-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-function-args-propagate-catchable.nix new file mode 100644 index 0000000000..ca3e6772f2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-function-args-propagate-catchable.nix @@ -0,0 +1,4 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.functionArgs (_: builtins.throw "a")) + (builtins.functionArgs (builtins.throw "b")) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-gen-list-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-gen-list-propagate-catchable.exp new file mode 100644 index 0000000000..652df3d4da --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-gen-list-propagate-catchable.exp @@ -0,0 +1 @@ +[ true false true ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-gen-list-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-gen-list-propagate-catchable.nix new file mode 100644 index 0000000000..3d4739966e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-gen-list-propagate-catchable.nix @@ -0,0 +1,5 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.genList (builtins.throw "a") 10) + (builtins.genList (i: "") (builtins.throw "b")) + (builtins.genList (i: builtins.throw "x") 5) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genList-function-strictness.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genList-function-strictness.exp new file mode 100644 index 0000000000..06712ebc33 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genList-function-strictness.exp @@ -0,0 +1 @@ +[ <LAMBDA> 0 1 2 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genList-function-strictness.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genList-function-strictness.nix new file mode 100644 index 0000000000..e161e3b4af --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genList-function-strictness.nix @@ -0,0 +1,8 @@ +let + self = + let + l = builtins.genList (builtins.head self) 3; + in + [ (x: x) ] ++ l; +in +self diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-pointer-equality.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-pointer-equality.exp new file mode 100644 index 0000000000..87977137a5 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-pointer-equality.exp @@ -0,0 +1 @@ +[ { key = [ { foo = <LAMBDA>; } ]; val = null; } ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-pointer-equality.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-pointer-equality.nix new file mode 100644 index 0000000000..f6ca340c09 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-pointer-equality.nix @@ -0,0 +1,15 @@ +let + foo = x: x; +in + +# key needs to be a list since it uses comparison, not equality checks: + # lists are comparable in Nix if all non-comparable items in them are equal (e.g. + # functions, attribute sets). +builtins.genericClosure { + startSet = [ + { key = [{ inherit foo; }]; val = null; } + ]; + operator = { val, ... }: if val != null then [ ] else [ + { key = [{ inherit foo; }]; val = throw "no pointer equality? 🥺👉👈"; } + ]; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-propagate-catchable.exp new file mode 100644 index 0000000000..6c89e78fc4 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-propagate-catchable.exp @@ -0,0 +1 @@ +{ success = false; value = false; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-propagate-catchable.nix new file mode 100644 index 0000000000..1dfc0bb04f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-genericClosure-propagate-catchable.nix @@ -0,0 +1 @@ +builtins.tryEval (builtins.genericClosure { operator = (_: [{ key = throw "lol"; }]); startSet = [{ key = "lol"; }]; }) diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getAttr-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getAttr-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getAttr-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getAttr-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getAttr-catchable.nix new file mode 100644 index 0000000000..ef4a042ffb --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getAttr-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.getAttr (throw "fred") "bob")).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getContext-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getContext-propagate-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getContext-propagate-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getContext-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getContext-propagate-catchable.nix new file mode 100644 index 0000000000..70521665ca --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-getContext-propagate-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.getContext (builtins.throw "a"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-group-by-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-group-by-propagate-catchable.exp new file mode 100644 index 0000000000..48e341f4d8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-group-by-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-group-by-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-group-by-propagate-catchable.nix new file mode 100644 index 0000000000..182601abb1 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-group-by-propagate-catchable.nix @@ -0,0 +1,5 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.groupBy (builtins.throw "a") [ "" ]) + (builtins.groupBy (x: true) (builtins.throw "b")) + (builtins.groupBy (_: builtins.throw "x") [ "" ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-groupby-thunk.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-groupby-thunk.exp new file mode 100644 index 0000000000..94649819ca --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-groupby-thunk.exp @@ -0,0 +1 @@ +{ fred = [ { x = "fred"; y = "fred"; } ]; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-groupby-thunk.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-groupby-thunk.nix new file mode 100644 index 0000000000..eaf48045f2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-groupby-thunk.nix @@ -0,0 +1,5 @@ +builtins.groupBy + (v: v.x) + [ (rec { y = x; x = "fred"; }) ] + + diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasContext-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasContext-propagate-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasContext-propagate-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasContext-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasContext-propagate-catchable.nix new file mode 100644 index 0000000000..0c02a82730 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasContext-propagate-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.hasContext (builtins.throw "a"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasattr.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasattr.nix index e87e186b64..fb786b4f09 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasattr.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hasattr.nix @@ -3,7 +3,7 @@ (builtins.hasAttr "bar" { foo = 1; bar = 2; baz = 3; }) (builtins.hasAttr "baz" { foo = 1; bar = 2; baz = 3; }) (builtins.hasAttr "FOO" { foo = 1; bar = 2; baz = 3; }) - (builtins.hasAttr "foo" {}) + (builtins.hasAttr "foo" { }) (builtins.hasAttr ("f" + "o" + "o") { foo = 1; }) (builtins.hasAttr ("b" + "a" + "r") { foo = 1; }) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.exp new file mode 100644 index 0000000000..e00b80e561 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.exp @@ -0,0 +1 @@ +[ "8a0614b4eaa4cffb7515ec101847e198" "8bd218cf61321d8aa05b3602b99f90d2d8cef3d6" "80ac06d74cb6c5d14af718ce8c3c1255969a1a595b76a3cf92354a95331a879a" "0edac513b6b0454705b553deda4c9b055da0939d26d2f73548862817ebeac5378cf64ff7a752ce1a0590a736735d3bbd9e8a7f04d93617cdf514313f5ab5baa4" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.nix new file mode 100644 index 0000000000..aed723d367 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.nix @@ -0,0 +1,6 @@ +[ + (builtins.hashString "md5" "tvix") + (builtins.hashString "sha1" "tvix") + (builtins.hashString "sha256" "tvix") + (builtins.hashString "sha512" "tvix") +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-head-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-head-propagate-catchable.exp new file mode 100644 index 0000000000..c3bb809c9f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-head-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-head-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-head-propagate-catchable.nix new file mode 100644 index 0000000000..0e69f2f6fc --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-head-propagate-catchable.nix @@ -0,0 +1,4 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.head (builtins.throw "a")) + (builtins.head [ (builtins.throw "a") ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-isType-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-isType-propagate-catchable.exp new file mode 100644 index 0000000000..cefd8652b4 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-isType-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false false false false false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-isType-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-isType-propagate-catchable.nix new file mode 100644 index 0000000000..28cf2351f6 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-isType-propagate-catchable.nix @@ -0,0 +1,14 @@ +let + isTypeFns = [ + builtins.isAttrs + builtins.isBool + builtins.isFloat + builtins.isFunction + builtins.isInt + builtins.isList + builtins.isNull + builtins.isPath + builtins.isString + ]; +in +map (fn: (builtins.tryEval (fn (builtins.throw "is type"))).success) isTypeFns diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length-catchable.nix new file mode 100644 index 0000000000..037a4911ac --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.length (throw "fred"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length.nix index ef1f638cbb..6af6915f97 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-length.nix @@ -1,5 +1,5 @@ [ - (builtins.length []) + (builtins.length [ ]) (builtins.length [ 1 ]) (builtins.length [ "one" "two" "three" ]) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-list-to-attrs-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-list-to-attrs-propagate-catchable.exp new file mode 100644 index 0000000000..5ee59ced83 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-list-to-attrs-propagate-catchable.exp @@ -0,0 +1 @@ +[ false true true false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-list-to-attrs-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-list-to-attrs-propagate-catchable.nix new file mode 100644 index 0000000000..91b9f889bb --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-list-to-attrs-propagate-catchable.nix @@ -0,0 +1,7 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.listToAttrs [{ name = builtins.throw "a"; value = "b"; }]) + (builtins.listToAttrs [{ name = "a"; value = builtins.throw "b"; }]) + (builtins.listToAttrs [{ name = "a"; value = "b"; } { name = "c"; value = builtins.throw "d"; }]) + (builtins.listToAttrs [{ name = "a"; value = "b"; } (builtins.throw "e")]) + (builtins.listToAttrs (builtins.throw "f")) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-function-strictness.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-function-strictness.exp new file mode 100644 index 0000000000..050c2c4de5 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-function-strictness.exp @@ -0,0 +1 @@ +[ <LAMBDA> 2 "." 18 "https://github.com/NixOS/nix/issues/9779" "-.-" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-function-strictness.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-function-strictness.nix new file mode 100644 index 0000000000..932d3d0eae --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-function-strictness.nix @@ -0,0 +1,8 @@ +let + self = + let + l = builtins.map (builtins.head self) [ 2 "." 18 https://github.com/NixOS/nix/issues/9779 "-.-" ]; + in + [ (x: x) ] ++ l; +in +self diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-propagate-catchable.exp new file mode 100644 index 0000000000..652df3d4da --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-propagate-catchable.exp @@ -0,0 +1 @@ +[ true false true ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-propagate-catchable.nix new file mode 100644 index 0000000000..3ebb006c3f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map-propagate-catchable.nix @@ -0,0 +1,5 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.map (builtins.throw "a") [ "" ]) + (builtins.map (x: true) (builtins.throw "b")) + (builtins.map (_: builtins.throw "x") [ "" ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mapAttrs-function-strictness.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mapAttrs-function-strictness.exp new file mode 100644 index 0000000000..7e70748ffd --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mapAttrs-function-strictness.exp @@ -0,0 +1 @@ +{ a = 1; b = 2; f = <LAMBDA>; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mapAttrs-function-strictness.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mapAttrs-function-strictness.nix new file mode 100644 index 0000000000..2946d6de17 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-mapAttrs-function-strictness.nix @@ -0,0 +1,8 @@ +let + self = + let + s = builtins.mapAttrs self.f { a = 1; b = 2; }; + in + { f = _: x: x; } // s; +in +self diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.nix new file mode 100644 index 0000000000..8d00994b60 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.match (throw "foo") ".*")).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-parse-drv-name-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-parse-drv-name-propagate-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-parse-drv-name-propagate-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-parse-drv-name-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-parse-drv-name-propagate-catchable.nix new file mode 100644 index 0000000000..c718727e74 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-parse-drv-name-propagate-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.parseDrvName (builtins.throw "a"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition-propagate-catchable.exp new file mode 100644 index 0000000000..48e341f4d8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition-propagate-catchable.nix new file mode 100644 index 0000000000..1960b1790f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition-propagate-catchable.nix @@ -0,0 +1,5 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.partition (builtins.throw "a") [ "" ]) + (builtins.partition (x: true) (builtins.throw "b")) + (builtins.partition (_: builtins.throw "x") [ "" ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition.exp new file mode 100644 index 0000000000..d2390db4f5 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition.exp @@ -0,0 +1 @@ +[ { right = [ 1 2 3 4 5 ]; wrong = [ ]; } { right = [ ]; wrong = [ 1 2 3 4 5 ]; } { right = [ 2 ]; wrong = [ 1 3 4 5 ]; } { right = [ [ 1 2 ] [ 3 4 ] ]; wrong = [ [ 1 ] [ 2 ] [ 3 ] ]; } ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition.nix new file mode 100644 index 0000000000..44022a9e0c --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-partition.nix @@ -0,0 +1,13 @@ +[ + (builtins.partition (_: true) [ 1 2 3 4 5 ]) + (builtins.partition (_: false) [ 1 2 3 4 5 ]) + (builtins.partition (x: x == 2) [ 1 2 3 4 5 ]) + + (builtins.partition (x: (builtins.length x) > 1) [ + [ 1 ] + [ 1 2 ] + [ 2 ] + [ 3 ] + [ 3 4 ] + ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-remove-attrs-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-remove-attrs-propagate-catchable.exp new file mode 100644 index 0000000000..1e950b5aa2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-remove-attrs-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false true false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-remove-attrs-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-remove-attrs-propagate-catchable.nix new file mode 100644 index 0000000000..8ca8a414aa --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-remove-attrs-propagate-catchable.nix @@ -0,0 +1,6 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.removeAttrs (builtins.throw "a") [ "a" ]) + (builtins.removeAttrs { a = { }; } (builtins.throw "b")) + (builtins.removeAttrs { a = builtins.throw "b"; } [ "a" ]) + (builtins.removeAttrs { "${builtins.throw "c"}" = "b"; } [ "c" ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replace-strings-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replace-strings-propagate-catchable.exp new file mode 100644 index 0000000000..cefd8652b4 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replace-strings-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false false false false false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replace-strings-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replace-strings-propagate-catchable.nix new file mode 100644 index 0000000000..ad9734ba9a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replace-strings-propagate-catchable.nix @@ -0,0 +1,16 @@ +map (e: (builtins.tryEval e).success) [ + # This one may be hard to read for non-experts. + # Replace strings is a special built-in compared to others in the sense + # it might attempt to lazily evaluate things upon successful replacements, + # so it would not be surprising that some of the non-replacements which could throw + # could be ignored by laziness. It is not the case though. + (builtins.replaceStrings [ "a" (builtins.throw "b") ] [ "c" "d" ] "ab") + (builtins.replaceStrings [ "a" (builtins.throw "b") ] [ "c" "d" ] "a") + (builtins.replaceStrings [ "a" "b" ] [ "c" (builtins.throw "d") ] "a") + (builtins.replaceStrings [ "a" "b" ] [ "c" (builtins.throw "d") ] "ab") + (builtins.replaceStrings [ "" ] [ (builtins.throw "d") ] "ab") + (builtins.replaceStrings [ "a" "" ] [ "b" (builtins.throw "d") ] "ab") + (builtins.replaceStrings (builtins.throw "z") [ ] "ab") + (builtins.replaceStrings [ ] (builtins.throw "z") "ab") + (builtins.replaceStrings [ ] [ ] (builtins.throw "z")) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.exp new file mode 100644 index 0000000000..9f20496c7a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.exp @@ -0,0 +1 @@ +[ "fabir" "a" "1a1" "ABC" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.nix new file mode 100644 index 0000000000..eea3f87a2f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-replaceStrings.nix @@ -0,0 +1,6 @@ +[ + (builtins.replaceStrings [ "oo" "a" ] [ "a" "i" ] "foobar") + (builtins.replaceStrings [ "o" ] [ "a" ] "a") + (builtins.replaceStrings [ "" "" ] [ "1" "2" ] "a") + (builtins.replaceStrings [ "a" "b" "c" ] [ "A" "B" "C" ] "abc") +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-sort-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-sort-propagate-catchable.exp new file mode 100644 index 0000000000..1e950b5aa2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-sort-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false true false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-sort-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-sort-propagate-catchable.nix new file mode 100644 index 0000000000..66ca4b98ed --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-sort-propagate-catchable.nix @@ -0,0 +1,6 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.sort (builtins.throw "a") [ "" ]) + (builtins.sort (x: y: true) (builtins.throw "b")) + (builtins.sort (_: _: builtins.throw "x") [ "" ]) + (builtins.sort (_: _: builtins.throw "x") [ "" "" ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-split-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-split-propagate-catchable.exp new file mode 100644 index 0000000000..c3bb809c9f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-split-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-split-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-split-propagate-catchable.nix new file mode 100644 index 0000000000..1c86e9d6f8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-split-propagate-catchable.nix @@ -0,0 +1,4 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.split (builtins.throw "regex") "abc") + (builtins.split "[^/]" (builtins.throw "string")) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-splitversion-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-splitversion-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-splitversion-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-splitversion-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-splitversion-catchable.nix new file mode 100644 index 0000000000..0668ec7de2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-splitversion-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.splitVersion (throw "fred"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-string-length-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-string-length-propagate-catchable.exp new file mode 100644 index 0000000000..d181ebcff6 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-string-length-propagate-catchable.exp @@ -0,0 +1 @@ +[ false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-string-length-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-string-length-propagate-catchable.nix new file mode 100644 index 0000000000..0904acd114 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-string-length-propagate-catchable.nix @@ -0,0 +1,4 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.stringLength (builtins.throw "a")) + # FIXME(raitobezarius): test coercions too. +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-coerce.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-coerce.exp new file mode 100644 index 0000000000..192548e949 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-coerce.exp @@ -0,0 +1 @@ +"42" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-coerce.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-coerce.nix new file mode 100644 index 0000000000..626ae1d1be --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-coerce.nix @@ -0,0 +1,5 @@ +# builtins.substring uses string coercion internally + +builtins.substring 0 2 { + __toString = _: "4200"; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-negative-length.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-negative-length.exp new file mode 100644 index 0000000000..e614d49940 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-negative-length.exp @@ -0,0 +1 @@ +[ "SIP dial" "Lounge" " Lounge" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-negative-length.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-negative-length.nix new file mode 100644 index 0000000000..062e2c0581 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-substring-negative-length.nix @@ -0,0 +1,5 @@ +[ + (builtins.substring 0 (-1) "SIP dial") + (builtins.substring 13 (-1) "Nichtraucher Lounge") + (builtins.substring 12 (-2) "Nichtraucher Lounge") +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tail-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tail-propagate-catchable.exp new file mode 100644 index 0000000000..d4cd584d22 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tail-propagate-catchable.exp @@ -0,0 +1 @@ +[ false true true true ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tail-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tail-propagate-catchable.nix new file mode 100644 index 0000000000..b4e461e12b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tail-propagate-catchable.nix @@ -0,0 +1,6 @@ +map (e: (builtins.tryEval e).success) [ + (builtins.tail (builtins.throw "a")) + (builtins.tail [ (builtins.throw "a") ]) + (builtins.tail [ (builtins.throw "a") "a" ]) + (builtins.tail [ (builtins.throw "a") (builtins.throw "a") ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-thunked-function-calls.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-thunked-function-calls.exp new file mode 100644 index 0000000000..3d4204d5a8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-thunked-function-calls.exp @@ -0,0 +1 @@ +[ 2 [ "Hans" "James" "Joachim" ] 2 [ "Clawdia" "Mynheer" ] 981 3 2 2 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-thunked-function-calls.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-thunked-function-calls.nix new file mode 100644 index 0000000000..3a1c0b9821 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-thunked-function-calls.nix @@ -0,0 +1,31 @@ +[ + # This is independent of builtins + (builtins.length [ (builtins.throw "Ferge") (builtins.throw "Wehsal") ]) + (builtins.attrNames { + Hans = throw "Castorp"; + Joachim = throw "Ziemßen"; + James = "Tienappel"; + }) + + (builtins.length (builtins.map builtins.throw [ "Settembrini" "Naphta" ])) + + (builtins.attrNames (builtins.mapAttrs builtins.throw { + Clawdia = "Chauchat"; + Mynheer = "Peeperkorn"; + })) + + (builtins.length (builtins.genList (builtins.add "Marusja") 981)) + (builtins.length (builtins.genList builtins.throw 3)) + + # These are hard to get wrong since the outer layer needs to be forced anyways + (builtins.length (builtins.genericClosure { + startSet = [ + { key = 1; initial = true; } + ]; + operator = { key, initial, ... }: + if initial + then [{ key = key - 1; initial = false; value = throw "lol"; }] + else [ ]; + })) + (builtins.length (builtins.concatMap (m: [ m (builtins.throw m) ]) [ "Marusja" ])) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-json-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-json-propagate-catchable.exp new file mode 100644 index 0000000000..ca00e3c049 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-json-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-json-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-json-propagate-catchable.nix new file mode 100644 index 0000000000..8ae5e48e97 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-json-propagate-catchable.nix @@ -0,0 +1,14 @@ +map (e: (builtins.tryEval (builtins.toJSON e)).success) [ + (builtins.throw "a") + { + a = builtins.throw "attribute a"; + } + { + a.b.c.d.e.f.g.h.i = builtins.throw "deep i"; + } + { + x = 32; + y = builtins.throw "second argument"; + } + # FIXME(raitobezarius): we would like to test coercions, i.e. `toFile` and `derivation` containing throwables. +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-path-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-path-propagate-catchable.exp new file mode 100644 index 0000000000..c3bb809c9f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-path-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-path-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-path-propagate-catchable.nix new file mode 100644 index 0000000000..808fb8c46e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-path-propagate-catchable.nix @@ -0,0 +1,5 @@ +map (e: (builtins.tryEval (builtins.toPath e)).success) [ + (builtins.throw "a") + (./xyz + (builtins.throw "p")) + # FIXME: test derivations and files. +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-string-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-string-propagate-catchable.exp new file mode 100644 index 0000000000..ca00e3c049 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-string-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-string-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-string-propagate-catchable.nix new file mode 100644 index 0000000000..7b19ff53c3 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-string-propagate-catchable.nix @@ -0,0 +1,7 @@ +map (e: (builtins.tryEval (builtins.toString e)).success) [ + (builtins.throw "a") + [ (builtins.throw "a") ] + [ "abc" (builtins.throw "a") ] + "abc${builtins.throw "c"}" + # FIXME: test derivations and files. +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-xml-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-xml-propagate-catchable.exp new file mode 100644 index 0000000000..366f7adf0d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-xml-propagate-catchable.exp @@ -0,0 +1 @@ +[ false false false false true false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-xml-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-xml-propagate-catchable.nix new file mode 100644 index 0000000000..80d9e688be --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-to-xml-propagate-catchable.nix @@ -0,0 +1,15 @@ +map (e: (builtins.tryEval (builtins.toXML e)).success) [ + (builtins.throw "a") + [ (builtins.throw "a") ] + [ "abc" (builtins.throw "a") ] + "abc${builtins.throw "c"}" + (_: builtins.throw "d") + { + u = builtins.throw "x"; + v = "a"; + } + { + u.i.w.x.z = builtins.throw "n"; + } + # FIXME: test derivations and files. +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-toString.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-toString.exp index a148ebc3b5..cd5a6c0d54 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-toString.exp +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-toString.exp @@ -1 +1 @@ -[ "1" "4.200000" "" "" "1" "foo" "/etc" "Hello World" "Hello World" "1" "out" "2" "1 4.200000 1 foo /etc Hello World Hello World 1 out 2" ] +[ "" " " " /deep/thought" " 2 3" " flat" "1" "4.200000" "" "" "1" "foo" "/etc" "Hello World" "Hello World" "1" "out" "2" " /deep/thought 2 3 flat 1 4.200000 1 foo /etc Hello World Hello World 1 out 2" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-toString.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-toString.nix index e4dc18ac96..eb8011158f 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-toString.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-toString.nix @@ -5,19 +5,24 @@ let }; toStringExamples = [ - (toString 1) - (toString 4.2) - (toString null) - (toString false) - (toString true) - (toString "foo") - (toString /etc) - (toString toStringableSet) - (toString { __toString = _: toStringableSet; }) - (toString { __toString = _: true; }) - (toString { outPath = "out"; }) - (toString { outPath = { outPath = { __toString = _: 2; }; }; }) + null + [ null false ] + [ null /deep/thought ] + [ [ null 2 ] null 3 ] + [ false "flat" ] + 1 + 4.2 + null + false + true + "foo" + /etc + toStringableSet + { __toString = _: toStringableSet; } + { __toString = _: true; } + { outPath = "out"; } + { outPath = { outPath = { __toString = _: 2; }; }; } ]; in -toStringExamples ++ [ (toString toStringExamples) ] +(builtins.map toString toStringExamples) ++ [ (toString toStringExamples) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-literals.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-literals.exp new file mode 100644 index 0000000000..0a274c201f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-literals.exp @@ -0,0 +1 @@ +"[42,\"hello\",13.37,[],[1,2,3],{},{\"name\":\"foo\",\"value\":42},{\"foo\":42}]" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-literals.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-literals.nix new file mode 100644 index 0000000000..12e8c03b17 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-literals.nix @@ -0,0 +1,11 @@ +# tests serialisation of literal data +builtins.toJSON [ + 42 + "hello" + 13.37 + [ ] + [ 1 2 3 ] + { } + { name = "foo"; value = 42; } + { foo = 42; } +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath-nested.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath-nested.exp new file mode 100644 index 0000000000..69667de5a1 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath-nested.exp @@ -0,0 +1 @@ +"{\"a\":40,\"b\":2}" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath-nested.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath-nested.nix new file mode 100644 index 0000000000..70755c8c6d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath-nested.nix @@ -0,0 +1,8 @@ +# Attribute sets with an `outPath` can contain _any_ serialisable +# value in that field. +builtins.toJSON { + outPath = { + a = 40; + b = 2; + }; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath.exp new file mode 100644 index 0000000000..82dd081798 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath.exp @@ -0,0 +1 @@ +"\"/nix/store/jzka5ndnygkkfjfvpqwjipqp75lhz138-emacs-28.2\"" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath.nix new file mode 100644 index 0000000000..7f9d95ac60 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-outpath.nix @@ -0,0 +1,5 @@ +# Attribute sets with an `outPath` have that outPath itself serialised +# to string. +builtins.toJSON { + outPath = "/nix/store/jzka5ndnygkkfjfvpqwjipqp75lhz138-emacs-28.2"; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-thunks.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-thunks.exp new file mode 100644 index 0000000000..9ccd94224b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-thunks.exp @@ -0,0 +1 @@ +"[42,42,\"42\"]" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-thunks.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-thunks.nix new file mode 100644 index 0000000000..16234ab451 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-thunks.nix @@ -0,0 +1,9 @@ +let + a = b * 2; + b = 21; +in +builtins.toJSON [ + a + ((n: n * 2) 21) + (builtins.toJSON a) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-tostring.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-tostring.exp new file mode 100644 index 0000000000..2661fd257b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-tostring.exp @@ -0,0 +1 @@ +"\"it's 42\"" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-tostring.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-tostring.nix new file mode 100644 index 0000000000..ec6f8d947c --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-tojson-tostring.nix @@ -0,0 +1,8 @@ +# Attribute sets with a `__toString` attribute JSON-serialise with a +# string coercion of the function call result. + +builtins.toJSON { + __toString = self: "it's " + (builtins.toString (self.x * self.y)); + x = 21; + y = 2; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of-propagate-catchable.exp new file mode 100644 index 0000000000..41f22d3ee4 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of-propagate-catchable.exp @@ -0,0 +1 @@ +[ false true true false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of-propagate-catchable.nix new file mode 100644 index 0000000000..4b70609bbf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of-propagate-catchable.nix @@ -0,0 +1,9 @@ +map (e: (builtins.tryEval (builtins.typeOf e)).success) [ + (builtins.throw "a") + { + a = builtins.throw "b"; + } + [ (builtins.throw "c") ] + (./xyz + (builtins.throw "p")) + # FIXME: test derivations and files. +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of.exp index 0e22da8d56..1ea054fc2d 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of.exp +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of.exp @@ -1 +1 @@ -[ "null" "bool" "bool" "int" "int" "float" "string" "string" "set" "set" "set" "list" "lambda" "path" ] +[ "null" "bool" "bool" "int" "int" "float" "string" "string" "set" "set" "list" "lambda" "path" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of.nix index 38d7ffee61..fa42c6008e 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-of.nix @@ -3,20 +3,20 @@ let in fix (self: - [ - (builtins.typeOf null) - (builtins.typeOf true) - (builtins.typeOf (true && false)) - (builtins.typeOf 12) - (builtins.typeOf (builtins.add 21 21)) - (builtins.typeOf 1.2) - (builtins.typeOf "foo") - (builtins.typeOf "${"foo" + "bar"}baz") - (builtins.typeOf {}) - (builtins.typeOf { foo.bar = 32; }.foo) - (builtins.typeOf ({ name = "foo"; value = 13; } // { name = "bar"; })) - (builtins.typeOf self) - (builtins.typeOf fix) - (builtins.typeOf /nix/store) - ] +[ + (builtins.typeOf null) + (builtins.typeOf true) + (builtins.typeOf (true && false)) + (builtins.typeOf 12) + (builtins.typeOf (builtins.add 21 21)) + (builtins.typeOf 1.2) + (builtins.typeOf "foo") + (builtins.typeOf "${"foo" + "bar"}baz") + (builtins.typeOf { }) + # (builtins.typeOf { foo.bar = 32; }.foo) # TODO: re-enable when nested keys are done + (builtins.typeOf ({ name = "foo"; value = 13; } // { name = "bar"; })) + (builtins.typeOf self) + (builtins.typeOf fix) + (builtins.typeOf /nix/store) +] ) diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-predicates.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-predicates.nix index 3d688cb8bd..e67b219159 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-predicates.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-type-predicates.nix @@ -14,13 +14,13 @@ in (builtins.isFloat 1) (builtins.isFunction thunk) (builtins.isFunction (thunk thunk)) - (builtins.isFunction {}) + (builtins.isFunction { }) (builtins.isInt 1) (builtins.isInt (thunk 42)) (builtins.isInt 1.0) (builtins.isList [ (throw "oh no") (abort "it's over") ]) (builtins.isList (thunk [ 21 21 ])) - (builtins.isList (thunk {})) + (builtins.isList (thunk { })) (builtins.isNull null) (builtins.isNull (thunk null)) (builtins.isNull 42) diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-unsafe-discard-string-context-propagate-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-unsafe-discard-string-context-propagate-catchable.exp new file mode 100644 index 0000000000..d181ebcff6 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-unsafe-discard-string-context-propagate-catchable.exp @@ -0,0 +1 @@ +[ false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-unsafe-discard-string-context-propagate-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-unsafe-discard-string-context-propagate-catchable.nix new file mode 100644 index 0000000000..8ef5f35a17 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-unsafe-discard-string-context-propagate-catchable.nix @@ -0,0 +1,4 @@ +map (e: (builtins.tryEval (builtins.unsafeDiscardStringContext e)).success) [ + (builtins.throw "a") + # FIXME: test derivations with throwables. +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-double-throw.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-double-throw.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-double-throw.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-double-throw.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-double-throw.nix new file mode 100644 index 0000000000..7c2132b502 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-double-throw.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.throw (builtins.throw "a"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-attrNames.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-attrNames.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-attrNames.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-attrNames.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-attrNames.nix new file mode 100644 index 0000000000..75531d56a3 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-attrNames.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.attrNames (throw "fred"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-inequality.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-inequality.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-inequality.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-inequality.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-inequality.nix new file mode 100644 index 0000000000..93836bd8fe --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-inequality.nix @@ -0,0 +1 @@ +(builtins.tryEval (throw "bob" != 3)).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-intersectattrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-intersectattrs.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-intersectattrs.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-intersectattrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-intersectattrs.nix new file mode 100644 index 0000000000..a06a383342 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-intersectattrs.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.intersectAttrs (throw "fred") { })).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.nix new file mode 100644 index 0000000000..7a0cf16709 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.nix @@ -0,0 +1 @@ +(builtins.tryEval ("${toString 3} ${throw "bob"}")).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-update-attrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-update-attrs.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-update-attrs.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-update-attrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-update-attrs.nix new file mode 100644 index 0000000000..38a9169034 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-update-attrs.nix @@ -0,0 +1 @@ +(builtins.tryEval (throw "bob" // { })).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-passed-to-function-with-formals.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-passed-to-function-with-formals.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-passed-to-function-with-formals.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-passed-to-function-with-formals.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-passed-to-function-with-formals.nix new file mode 100644 index 0000000000..df6726db76 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-passed-to-function-with-formals.nix @@ -0,0 +1 @@ +(builtins.tryEval (({ fred }: "bob") (throw "3"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-ceil.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-ceil.exp new file mode 100644 index 0000000000..dffbbe59f0 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-ceil.exp @@ -0,0 +1 @@ +[ 4 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-ceil.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-ceil.nix new file mode 100644 index 0000000000..5835bf829b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-ceil.nix @@ -0,0 +1 @@ +[ (builtins.ceil 3.4) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-closure-pointer-compare.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-pointer-compare.exp new file mode 100644 index 0000000000..c3bb809c9f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-pointer-compare.exp @@ -0,0 +1 @@ +[ false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-closure-pointer-compare.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-pointer-compare.nix new file mode 100644 index 0000000000..639191be5d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-pointer-compare.nix @@ -0,0 +1,14 @@ +# For an explanation of this behavior see //tvix/docs/value-pointer-equality.md +let + g = x: + owo: "th" + x; +in +[ + ( + { q = g "ia"; } == { q = g ("i" + "a"); } + ) + + ( + [ (g "ia") ] == [ (g ("i" + "a")) ] + ) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-closure-self.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-self.nix index bda364f429..7be6660009 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-closure-self.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-self.nix @@ -1,4 +1,5 @@ let # self-recursive function should be able to close over itself f = n: if n <= 0 then "done" else f (n - 1); -in f 10 +in +f 10 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.nix index 3054637752..2c4de65e76 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.nix @@ -8,7 +8,7 @@ let in # introduce some closure depth to force both kinds of upvalue -# resolution, and introduce a dynamically known `a` within the -# closures + # resolution, and introduce a dynamically known `a` within the + # closures let f = b: with { a = 2; }; c: a + b + c; in f 0 0 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-coerce-opadd.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-coerce-opadd.exp new file mode 100644 index 0000000000..d874518a37 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-coerce-opadd.exp @@ -0,0 +1 @@ +[ "lordnikon" "zerocool" /tmp/31337h4x0r "fooblah" "blahfoo" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-coerce-opadd.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-coerce-opadd.nix new file mode 100644 index 0000000000..e79e521f8a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-coerce-opadd.nix @@ -0,0 +1,7 @@ +[ + ({ __toString = _: "lord"; } + "nikon") + ("zero" + { __toString = _: "cool"; }) + (/tmp/31337 + "h4x0r") + ("foo" + { outPath = "blah"; }) + ({ outPath = "blah"; } + "foo") +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-compare-lists.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-compare-lists.exp new file mode 100644 index 0000000000..3b7fd39819 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-compare-lists.exp @@ -0,0 +1 @@ +[ false true true true false true false false false true false false false true true ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-compare-lists.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-compare-lists.nix new file mode 100644 index 0000000000..1837f4d820 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-compare-lists.nix @@ -0,0 +1,17 @@ +[ + ([ 1 2 ] < [ 1 ]) + ([ 1 2 ] < [ 2 3 ]) + ([ 1 2 ] < [ 2 ]) + ([ 1 2 ] < [ 1 2 3 ]) + ([ 3 4 ] < [ 1 ]) + ([ 1 2 ] > [ 1 ]) + ([ 1 2 ] > [ 2 3 ]) + ([ 1 2 ] > [ 2 ]) + ([ 1 2 ] > [ 1 2 3 ]) + ([ 3 4 ] > [ 1 ]) + ([ 1 2 ] <= [ 1 ]) + ([ 1 2 ] >= [ 2 3 ]) + ([ 1 2 ] >= [ 2 ]) + ([ 1 2 ] <= [ 1 2 3 ]) + ([ 3 4 ] >= [ 1 ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-compare-ordering-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-compare-ordering-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-compare-ordering-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-compare-ordering-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-compare-ordering-catchable.nix new file mode 100644 index 0000000000..9000160e57 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-compare-ordering-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval ((throw "x") < 3)).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.exp new file mode 100644 index 0000000000..14d804aa22 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.exp @@ -0,0 +1 @@ +[ "a" "z" "b" "z" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.nix new file mode 100644 index 0000000000..cff39b05e6 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.nix @@ -0,0 +1 @@ +(builtins.concatMap (x: [ x ] ++ [ "z" ]) [ "a" "b" ]) diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-concatstringssep.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-concatstringssep.exp new file mode 100644 index 0000000000..93987647ff --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-concatstringssep.exp @@ -0,0 +1 @@ +[ "" "foobarxyzzy" "foo, bar, xyzzy" "foo" "" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-concatstringssep.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-concatstringssep.nix new file mode 100644 index 0000000000..cd94ca99b4 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-concatstringssep.nix @@ -0,0 +1,9 @@ +with builtins; + +[ + (concatStringsSep "" [ ]) + (concatStringsSep "" [ "foo" "bar" "xyzzy" ]) + (concatStringsSep ", " [ "foo" "bar" "xyzzy" ]) + (concatStringsSep ", " [ "foo" ]) + (concatStringsSep ", " [ ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with-closure.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with-closure.nix index 7f13f1f270..f65e8ee537 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with-closure.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with-closure.nix @@ -15,4 +15,7 @@ with { c = 3; d = 3; }; _: with { d = 4; }; -[ a b c d ]) null null null null +[ a b c d ]) null + null + null + null diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.exp new file mode 100644 index 0000000000..8d38505c16 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.exp @@ -0,0 +1 @@ +456 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.nix new file mode 100644 index 0000000000..53aa4b1dc2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.nix @@ -0,0 +1 @@ +builtins.deepSeq (let as = { x = 123; y = as; }; in as) 456 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-unary-formals.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-unary-formals.exp new file mode 100644 index 0000000000..5993db7ccc --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-unary-formals.exp @@ -0,0 +1 @@ +[ false -2 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-unary-formals.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-unary-formals.nix new file mode 100644 index 0000000000..1fbb3e853a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-unary-formals.nix @@ -0,0 +1,6 @@ +# Application of unary operators on deferred formals arguments (via +# defaulting), see also b/255. +[ + (({ b ? !a, a }: b) { a = true; }) + (({ b ? -a, a }: b) { a = 2; }) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.nix index af227ae28e..ccafdf74ce 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.nix @@ -5,4 +5,5 @@ let set = { value = 42; }; -in result +in +result diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-dirof.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-dirof.exp new file mode 100644 index 0000000000..ff464e4c30 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-dirof.exp @@ -0,0 +1 @@ +[ /foo "." "foo//" "foo" "." "." / "/" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-dirof.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-dirof.nix new file mode 100644 index 0000000000..13cf473205 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-dirof.nix @@ -0,0 +1,10 @@ +[ + (builtins.dirOf /foo/bar) + (builtins.dirOf "foo") + (builtins.dirOf "foo///") + (builtins.dirOf "foo/bar") + (builtins.dirOf "./.") + (builtins.dirOf "") + (builtins.dirOf /.) + (builtins.toString (builtins.dirOf /.)) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-elem.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-elem.exp new file mode 100644 index 0000000000..3cf6c0e962 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-elem.exp @@ -0,0 +1 @@ +[ true false 30 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-elem.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-elem.nix new file mode 100644 index 0000000000..71ea7a4ed0 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-elem.nix @@ -0,0 +1,6 @@ +with import ./lib.nix; + +let xs = range 10 40; in + +[ (builtins.elem 23 xs) (builtins.elem 42 xs) (builtins.elemAt xs 20) ] + diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.exp new file mode 100644 index 0000000000..27ba77ddaf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.nix new file mode 100644 index 0000000000..cc39e2415f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.nix @@ -0,0 +1 @@ +[ [ "f" "" ] ] == [ [ "f" "" ] ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-equality-tolerate-catchable-in-type-field.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-equality-tolerate-catchable-in-type-field.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-equality-tolerate-catchable-in-type-field.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-equality-tolerate-catchable-in-type-field.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-equality-tolerate-catchable-in-type-field.nix new file mode 100644 index 0000000000..6bd018b68d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-equality-tolerate-catchable-in-type-field.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.elem { type = rec { x = throw "fred"; }.x; } [{ type = 3; }])).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-escape-string-correct-char-boundaries.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-escape-string-correct-char-boundaries.exp new file mode 100644 index 0000000000..d889063f9a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-escape-string-correct-char-boundaries.exp @@ -0,0 +1 @@ +"💭(\":thonking:\")" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-escape-string-correct-char-boundaries.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-escape-string-correct-char-boundaries.nix new file mode 100644 index 0000000000..49f4b62731 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-escape-string-correct-char-boundaries.nix @@ -0,0 +1,6 @@ +# Regression test for a bug where tvix would crash in nix_escape_string +# because it counted the string position by unicode code point count, +# but then used it as a byte index for slicing. Consequently, it would +# try slicing 💭 in half, thinking the first element to be escaped was +# at byte index 2 (i.e. the quote). +"💭(\":thonking:\")" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-escapify-integer-keys.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-escapify-integer-keys.exp new file mode 100644 index 0000000000..aa98a082a8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-escapify-integer-keys.exp @@ -0,0 +1 @@ +{ "3" = 3; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-escapify-integer-keys.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-escapify-integer-keys.nix new file mode 100644 index 0000000000..aa98a082a8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-escapify-integer-keys.nix @@ -0,0 +1 @@ +{ "3" = 3; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-fib.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-fib.nix index 9a22d85ac5..04cb52e033 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-fib.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-fib.nix @@ -1,7 +1,9 @@ let - fib' = i: n: m: if i == 0 + fib' = i: n: m: + if i == 0 then n else fib' (i - 1) m (n + m); fib = n: fib' n 1 1; -in fib 10 +in +fib 10 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-fix.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-fix.nix index 27d2fae104..6069950194 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-fix.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-fix.nix @@ -1,6 +1,7 @@ let fix = f: let x = f x; in x; -in fix(self: { +in +fix (self: { a = 1; b = self.a + 20; c = self.b * 2; diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-floor.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-floor.exp new file mode 100644 index 0000000000..6f98a7f48f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-floor.exp @@ -0,0 +1 @@ +[ 3 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-floor.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-floor.nix new file mode 100644 index 0000000000..c6b79c91a1 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-floor.nix @@ -0,0 +1 @@ +[ (builtins.floor 3.4) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-elements.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-elements.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-elements.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-elements.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-elements.nix new file mode 100644 index 0000000000..fc4129a254 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-elements.nix @@ -0,0 +1,8 @@ +let + lst = builtins.foldl' + (acc: x: acc ++ [ x ]) + [ ] + [ 42 (throw "this shouldn't be evaluated") ]; +in + +builtins.head lst diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.nix new file mode 100644 index 0000000000..59fd29b552 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict-lazy-initial-accumulator.nix @@ -0,0 +1,4 @@ +builtins.foldl' + (_: x: x) + (throw "This is never forced") + [ "but the results of applying op are" 42 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict.exp new file mode 100644 index 0000000000..8d683a20fa --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict.exp @@ -0,0 +1 @@ +[ 6 [ 0 1 2 3 ] 2 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict.nix new file mode 100644 index 0000000000..aadf5e1121 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-foldlStrict.nix @@ -0,0 +1,5 @@ +[ + (builtins.foldl' builtins.add 0 [ 1 2 3 ]) + (builtins.foldl' (l1: l2: l1 ++ l2) [ 0 ] [ [ 1 ] [ 2 3 ] ]) + (builtins.foldl' (x: y: if x == 0 then y else x * y) 0 [ 1 2 ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-formals-miscompilation-b-261-regression.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-formals-miscompilation-b-261-regression.exp new file mode 100644 index 0000000000..721a052bcc --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-formals-miscompilation-b-261-regression.exp @@ -0,0 +1 @@ +[ true null ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-formals-miscompilation-b-261-regression.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-formals-miscompilation-b-261-regression.nix new file mode 100644 index 0000000000..772fa6f386 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-formals-miscompilation-b-261-regression.nix @@ -0,0 +1,20 @@ +# This is a regression test for https://b.tvl.fyi/261. +# +# The bug occurred when Tvix would unconditionally finalise the stack slot of +# `finalise` (as its default expression needs a finaliser): Finalising an +# manually provided, already forced thunk would cause the VM to crash. +let + thunk = x: x; + bomb = thunk true; + f = + { finalise ? later == null + , later ? null + }: + [ finalise later ]; +in + +# Note that the crash did not occur if the offending expression was the rhs + # argument to `builtins.seq`, hence we need to put the assert in between. +assert builtins.seq bomb true; + +f { finalise = bomb; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson-escapes.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson-escapes.exp new file mode 100644 index 0000000000..add5505a82 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson-escapes.exp @@ -0,0 +1 @@ +"quote \" reverse solidus \\ solidus / backspace formfeed newline \n carriage return \r horizontal tab \t 1 char unicode encoded backspace 1 char unicode encoded e with accent é 2 char unicode encoded s with caron š 3 char unicode encoded rightwards arrow →" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson-escapes.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson-escapes.nix new file mode 100644 index 0000000000..f007135077 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson-escapes.nix @@ -0,0 +1,3 @@ +# This string contains all supported escapes in a JSON string, per json.org +# \b and \f are not supported by Nix +builtins.fromJSON ''"quote \" reverse solidus \\ solidus \/ backspace \b formfeed \f newline \n carriage return \r horizontal tab \t 1 char unicode encoded backspace \u0008 1 char unicode encoded e with accent \u00e9 2 char unicode encoded s with caron \u0161 3 char unicode encoded rightwards arrow \u2192"'' diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson.exp new file mode 100644 index 0000000000..24aa21d78f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson.exp @@ -0,0 +1 @@ +[ { Image = { Animated = false; Height = 600; IDs = [ 116 943 234 38793 true false null -100 ]; Latitude = 37.7668; Longitude = -122.396; Thumbnail = { Height = 125; Url = "http://www.example.com/image/481989943"; Width = 100; }; Title = "View from 15th Floor"; Width = 800; }; } { name = "a"; value = "b"; } [ 1 2 3 4 ] ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson.nix new file mode 100644 index 0000000000..1083919af8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-fromjson.nix @@ -0,0 +1,24 @@ +[ + # RFC 7159, section 13. + (builtins.fromJSON + '' + { + "Image": { + "Width": 800, + "Height": 600, + "Title": "View from 15th Floor", + "Thumbnail": { + "Url": "http://www.example.com/image/481989943", + "Height": 125, + "Width": 100 + }, + "Animated" : false, + "IDs": [116, 943, 234, 38793, true ,false,null, -100], + "Latitude": 37.7668, + "Longitude": -122.396 + } + } + '') + (builtins.fromJSON ''{"name": "a", "value": "b"}'') + (builtins.fromJSON "[ 1, 2, 3, 4 ]") +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-functionargs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-functionargs.exp new file mode 100644 index 0000000000..c1c9f8ffaf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-functionargs.exp @@ -0,0 +1 @@ +[ "stdenv" "fetchurl" "aterm-stdenv" "aterm-stdenv2" "libX11" "libXv" "mplayer-stdenv2.libXv-libX11" "mplayer-stdenv2.libXv-libX11_2" "nix-stdenv-aterm-stdenv" "nix-stdenv2-aterm2-stdenv2" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-functionargs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-functionargs.nix new file mode 100644 index 0000000000..6db04c562c --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-functionargs.nix @@ -0,0 +1,83 @@ +let + + stdenvFun = {}: { name = "stdenv"; }; + stdenv2Fun = {}: { name = "stdenv2"; }; + fetchurlFun = { stdenv }: assert stdenv.name == "stdenv"; { name = "fetchurl"; }; + atermFun = { stdenv, fetchurl }: { name = "aterm-${stdenv.name}"; }; + aterm2Fun = { stdenv, fetchurl }: { name = "aterm2-${stdenv.name}"; }; + nixFun = { stdenv, fetchurl, aterm }: { name = "nix-${stdenv.name}-${aterm.name}"; }; + + mplayerFun = + { stdenv, fetchurl, enableX11 ? false, xorg ? null, enableFoo ? true, foo ? null }: + assert stdenv.name == "stdenv2"; + assert enableX11 -> xorg.libXv.name == "libXv"; + assert enableFoo -> foo != null; + { name = "mplayer-${stdenv.name}.${xorg.libXv.name}-${xorg.libX11.name}"; }; + + makeOverridable = f: origArgs: f origArgs // + { + override = newArgs: + makeOverridable f (origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs)); + }; + + callPackage_ = pkgs: f: args: + makeOverridable f ((builtins.intersectAttrs (builtins.functionArgs f) pkgs) // args); + + allPackages = + { overrides ? (pkgs: pkgsPrev: { }) }: + let + callPackage = callPackage_ pkgs; + pkgs = pkgsStd // (overrides pkgs pkgsStd); + pkgsStd = { + inherit pkgs; + stdenv = callPackage stdenvFun { }; + stdenv2 = callPackage stdenv2Fun { }; + fetchurl = callPackage fetchurlFun { }; + aterm = callPackage atermFun { }; + xorg = callPackage xorgFun { }; + mplayer = callPackage mplayerFun { stdenv = pkgs.stdenv2; enableFoo = false; }; + nix = callPackage nixFun { }; + }; + in + pkgs; + + libX11Fun = { stdenv, fetchurl }: { name = "libX11"; }; + libX11_2Fun = { stdenv, fetchurl }: { name = "libX11_2"; }; + libXvFun = { stdenv, fetchurl, libX11 }: { name = "libXv"; }; + + xorgFun = + { pkgs }: + let callPackage = callPackage_ (pkgs // pkgs.xorg); in + { + libX11 = callPackage libX11Fun { }; + libXv = callPackage libXvFun { }; + }; + +in + +let + + pkgs = allPackages { }; + + pkgs2 = allPackages { + overrides = pkgs: pkgsPrev: { + stdenv = pkgs.stdenv2; + nix = pkgsPrev.nix.override { aterm = aterm2Fun { inherit (pkgs) stdenv fetchurl; }; }; + xorg = pkgsPrev.xorg // { libX11 = libX11_2Fun { inherit (pkgs) stdenv fetchurl; }; }; + }; + }; + +in + +[ + pkgs.stdenv.name + pkgs.fetchurl.name + pkgs.aterm.name + pkgs2.aterm.name + pkgs.xorg.libX11.name + pkgs.xorg.libXv.name + pkgs.mplayer.name + pkgs2.mplayer.name + pkgs.nix.name + pkgs2.nix.name +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-functor-call.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-functor-call.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-functor-call.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-functor-call.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-functor-call.nix new file mode 100644 index 0000000000..80ae345d83 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-functor-call.nix @@ -0,0 +1 @@ +{ x = 21; __functor = self: y: self.x * y; } 2 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-genlist.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-genlist.exp new file mode 100644 index 0000000000..cd4ca34f14 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-genlist.exp @@ -0,0 +1 @@ +[ 0 1 4 9 16 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-genlist.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-genlist.nix new file mode 100644 index 0000000000..2c4dfba203 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-genlist.nix @@ -0,0 +1 @@ +builtins.genList (x: x * x) 5 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-hasattr-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-hasattr-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-hasattr-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-hasattr-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-hasattr-catchable.nix new file mode 100644 index 0000000000..ba85d6b776 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-hasattr-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval ((throw "fred") ? bob)).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.exp new file mode 100644 index 0000000000..9800c675fc --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.exp @@ -0,0 +1 @@ +{ "'quoted'" = false; "-20°" = false; "2normal" = false; "45 44 43-'3 2 1" = false; "9front" = false; Very2Normal = true; VeryNormal = true; _'12 = true; "_'12.5" = false; __internal = true; _internal = true; abort = true; "assert" = false; "attr.path" = false; "else" = false; false = true; foldl' = true; "if" = false; "in" = false; "inherit" = false; "let" = false; normal = true; normal2 = true; null = true; or = true; "rec" = false; "then" = false; throw = true; true = true; "with" = false; x = true; x' = true; x'' = true; "😀" = false; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.nix new file mode 100644 index 0000000000..58af3d6d16 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-identifier-formatting.nix @@ -0,0 +1,42 @@ +# Note: the attribute values in this set aren't just dummies! They +# are booleans which indicate whether or not the corresponding +# attrname is valid without quotification. +{ + __internal = true; + _internal = true; + normal = true; + VeryNormal = true; + normal2 = true; + Very2Normal = true; + _'12 = true; + foldl' = true; + x = true; + x' = true; + x'' = true; + + true = true; + false = true; + null = true; + or = true; + "assert" = false; + throw = true; + abort = true; + + "9front" = false; + "2normal" = false; + "-20°" = false; + "45 44 43-'3 2 1" = false; + "attr.path" = false; + "'quoted'" = false; + "_'12.5" = false; + "😀" = false; + + "if" = false; + "then" = false; + "else" = false; + "with" = false; + "let" = false; + "in" = false; + "rec" = false; + "inherit" = false; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-import-display.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-import-display.exp new file mode 100644 index 0000000000..15d838950e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-import-display.exp @@ -0,0 +1 @@ +<PRIMOP> diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-import-display.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-import-display.nix new file mode 100644 index 0000000000..411f3cd6ef --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-import-display.nix @@ -0,0 +1,2 @@ +# In C++ Nix 2.3 this used to be <PRIMOP-APP> +import diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-import.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-import.exp new file mode 100644 index 0000000000..5ba7f64d78 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-import.exp @@ -0,0 +1 @@ +[ 42 42 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-import.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-import.nix new file mode 100644 index 0000000000..49cd244f06 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-import.nix @@ -0,0 +1,4 @@ +[ + (import ./directory) + (import ./directory/default.nix) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-inherit-string-ident.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-inherit-string-ident.nix index dde81e5a7c..75794d3337 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-inherit-string-ident.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-inherit-string-ident.nix @@ -4,4 +4,5 @@ let set = { inherit ({ value = 42; }) "value"; }; -in set.value +in +set.value diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals-deferred.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals-deferred.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals-deferred.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals-deferred.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals-deferred.nix new file mode 100644 index 0000000000..5c6702120f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals-deferred.nix @@ -0,0 +1,3 @@ +# Tests formals which have internal default values that must be deferred. + +({ optional ? defaultValue, defaultValue }: optional) { defaultValue = 42; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals.nix new file mode 100644 index 0000000000..c6dd5e9d54 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-internal-formals.nix @@ -0,0 +1,3 @@ +# Tests formals which have internal default values. + +({ defaultValue, optional ? defaultValue }: optional) { defaultValue = 42; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-intersectattrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-intersectattrs.exp new file mode 100644 index 0000000000..25001b211f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-intersectattrs.exp @@ -0,0 +1 @@ +{ a = 100; b = 200; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-intersectattrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-intersectattrs.nix new file mode 100644 index 0000000000..f02d963226 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-intersectattrs.nix @@ -0,0 +1,3 @@ +builtins.intersectAttrs +{ a = 1; b = 2; c = 3; } +{ a = 100; b = 200; d = 5; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-late-binding-closure.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-late-binding-closure.nix index dae170b06b..4312ec9a52 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-late-binding-closure.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-late-binding-closure.nix @@ -1,4 +1,5 @@ let f = n: n + a; a = 2; -in f 40 +in +f 40 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-late-binding.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-late-binding.nix index 41c4c53ea2..6b6875cf1a 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-late-binding.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-late-binding.nix @@ -1,4 +1,5 @@ let a = b; b = 42; -in a +in +a diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-equality.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-equality.exp index e6f2d1aaad..1c70d1bcf1 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-equality.exp +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-equality.exp @@ -1 +1 @@ -[ true true false ] +[ true true false true true ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-equality.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-equality.nix index b0ec8593a4..92363245f8 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-equality.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-equality.nix @@ -4,8 +4,13 @@ let list1 = [ (1 + 2) ]; list2 = [ (2 + 1) ]; list3 = [ (2 + 2) ]; -in [ + list4 = [ (2 + 2) ]; + list5 = [ (2 + 2) ]; +in +[ (attrs1 == attrs2) (list1 == list2) (list3 == list2) + (list4 == [ 4 ]) + ([ 4 ] == list5) ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with-nested.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with-nested.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with-nested.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with-nested.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with-nested.nix new file mode 100644 index 0000000000..22ac14b3f1 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with-nested.nix @@ -0,0 +1,5 @@ +# The 'namespace' of a with should only be evaluated if an identifier +# from it is actually accessed. + +with (abort "should not be evaluated"); +let a = dynamic; in 42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with.nix index e4377df97e..8b1a0191dc 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-lazy-with.nix @@ -1,6 +1,6 @@ # The 'namespace' of a with should only be evaluated if an identifier # from it is actually accessed. -with (builtins.throw "should not occur"); +with (abort "should not be evaluated"); 42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-fix.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-fix.nix index 87fcffadee..a411b1c4a4 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-fix.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-fix.nix @@ -1,9 +1,9 @@ let { - a = 21; - b = body.one; +a = 21; +b = body.one; - body = { - one = a * 2; - two = b; - }; +body = { + one = a * 2; + two = b; +}; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-in-with.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-in-with.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-in-with.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-in-with.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-in-with.nix new file mode 100644 index 0000000000..7d95efa5c3 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let-in-with.nix @@ -0,0 +1 @@ +with { }; let { body = 42; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let.nix index 850e0252c2..faabe25457 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-legacy-let.nix @@ -1,4 +1,4 @@ let { - a = 21; - body = a * 2; +a = 21; +body = a * 2; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-let-identifiers.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-let-identifiers.nix index b6c37c34f9..ce588be069 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-let-identifiers.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-let-identifiers.nix @@ -2,4 +2,5 @@ let a = 1; "b" = 2; ${"c"} = 3; -in [ a b c ] +in +[ a b c ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-let-inherit.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-let-inherit.nix index 4ec270e3bf..3aa7c0f8d2 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-let-inherit.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-let-inherit.nix @@ -3,10 +3,11 @@ let a = 1; }; in - let - set2 = { - b = 1; - }; - inherit (set) a; - inherit (set2) b; - in a + b +let + set2 = { + b = 1; + }; + inherit (set) a; + inherit (set2) b; +in +a + b diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-let-sibling-access.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-let-sibling-access.nix index 7a65a5b1cc..faad81a213 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-let-sibling-access.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-let-sibling-access.nix @@ -2,4 +2,5 @@ let a = 1; b = 2; c = a + b; -in c +in +c diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-list-comparison.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-list-comparison.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-list-comparison.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-list-comparison.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-list-comparison.nix new file mode 100644 index 0000000000..7796fe4cbb --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-list-comparison.nix @@ -0,0 +1 @@ +[ 1 2 ] > [ ((rec{ x = 1; }).x) 2 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-listtoattrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-listtoattrs.exp new file mode 100644 index 0000000000..74abef7bc6 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-listtoattrs.exp @@ -0,0 +1 @@ +"AAbar" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-listtoattrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-listtoattrs.nix new file mode 100644 index 0000000000..551db72cb0 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-listtoattrs.nix @@ -0,0 +1,16 @@ +with builtins; +let + fold = op: nul: list: + if list == [ ] + then nul + else op (head list) (fold op nul (tail list)); + concat = + fold (x: y: x + y) ""; + asi = name: value: { inherit name value; }; + list = [ (asi "a" "A") (asi "b" "B") ]; + a = builtins.listToAttrs list; + b = builtins.listToAttrs (list ++ list); + r = builtins.listToAttrs [ (asi "result" [ a b ]) (asi "throw" (throw "this should not be thrown")) ]; + x = builtins.listToAttrs [ (asi "foo" "bar") (asi "foo" "bla") ]; +in +concat (map (x: x.a) r.result) + x.foo diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.nix new file mode 100644 index 0000000000..dd2a9baa75 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval ((throw "fred") && (throw "jill"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-logical-or-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-or-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-or-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-logical-or-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-or-catchable.nix new file mode 100644 index 0000000000..3adccfa441 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-or-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval ((throw "fred") || (throw "jill"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.nix index 8e1256d764..23459e384a 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.nix @@ -6,4 +6,5 @@ let a = 21; b = a * 2; }; -in set.b +in +set.b diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-attrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-attrs.exp new file mode 100644 index 0000000000..911ab51de5 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-attrs.exp @@ -0,0 +1 @@ +{ set = { a = 1; b = 2; }; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-attrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-attrs.nix new file mode 100644 index 0000000000..78b28909a2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-attrs.nix @@ -0,0 +1,9 @@ +{ + set = { + a = 1; + }; + + set = { + b = 2; + }; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-rec-attrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-rec-attrs.exp new file mode 100644 index 0000000000..768eaae61c --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-rec-attrs.exp @@ -0,0 +1 @@ +{ set = { a = 21; b = 42; }; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-rec-attrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-rec-attrs.nix new file mode 100644 index 0000000000..cea4cb1b4f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-merge-nested-rec-attrs.nix @@ -0,0 +1,12 @@ +{ + set = rec { + a = 21; + }; + + set = { + # Fun fact: This might be the only case in Nix where a lexical + # resolution of an identifier can only be resolved by looking at + # *siblings* in the AST. + b = 2 * a; + }; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.nix new file mode 100644 index 0000000000..b0397e268e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.nix @@ -0,0 +1 @@ +(builtins.tryEval (assert (assert false; true); true)).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-deferred-upvalue.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-deferred-upvalue.nix index 358925e992..3fa1d3ed05 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-deferred-upvalue.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-deferred-upvalue.nix @@ -1,6 +1,10 @@ let doubler = n: outer n; - outer = let inner = n: a * n; - a = 2; - in inner; -in doubler 10 + outer = + let + inner = n: a * n; + a = 2; + in + inner; +in +doubler 10 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-let.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-let.exp new file mode 100644 index 0000000000..6db47b033e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-let.exp @@ -0,0 +1 @@ +{ a = { b = 42; }; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-let.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-let.nix new file mode 100644 index 0000000000..c99ac748e6 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-let.nix @@ -0,0 +1,5 @@ +let + inner = 21; + set.a.b = inner * 2; +in +set diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-rec.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-rec.exp new file mode 100644 index 0000000000..77eb325dde --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-rec.exp @@ -0,0 +1 @@ +{ a = { b = { c = 42; }; }; outer = 21; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-rec.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-rec.nix new file mode 100644 index 0000000000..797d11108f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-keys-rec.nix @@ -0,0 +1,4 @@ +rec { + outer = 21; + a.b.c = outer * 2; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-let-slots.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-let-slots.nix index 811bb4361b..eec5940875 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-let-slots.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-let-slots.nix @@ -6,12 +6,17 @@ let a = 1; b = 2; - outer = let - c = 3; - d = 4; - inner = let - e = 5; - f = 6; - in g: [ a b c d e f g ]; - in inner; -in outer 7 + outer = + let + c = 3; + d = 4; + inner = + let + e = 5; + f = 6; + in + g: [ a b c d e f g ]; + in + inner; +in +outer 7 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-let.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-let.nix index caaa202119..f40c04b139 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-let.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-let.nix @@ -1,7 +1,10 @@ let - a = let - b = 1; - c = 2; - in b + c; + a = + let + b = 1; + c = 2; + in + b + c; b = 4; -in a + b +in +a + b diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-poisoning.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-poisoning.nix index 8d0280bb89..0fd22a671c 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-poisoning.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-poisoning.nix @@ -1,4 +1,5 @@ let null = 1; f = n: n + null; -in f 41 +in +f 41 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-siblings.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-siblings.exp new file mode 100644 index 0000000000..d757cae1f5 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-siblings.exp @@ -0,0 +1 @@ +{ outer = 42; sibling = 42; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-siblings.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-siblings.nix new file mode 100644 index 0000000000..31111d8081 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-siblings.nix @@ -0,0 +1,7 @@ +rec { + outer = + let inner = sibling; + in inner; + + sibling = 42; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-thunks.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-thunks.nix index 133929dd19..2519221e97 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-thunks.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-thunks.nix @@ -4,4 +4,5 @@ let a = b; b = c; c = 42; -in a +in +a diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-with.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-with.nix index ea5ef568ed..fa832b2099 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-with.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-with.nix @@ -1,4 +1,5 @@ let set1 = { a = 1; }; set2 = { a = 2; }; -in with set1; with set2; a +in +with set1; with set2; a diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nix-version-cmp.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-nix-version-cmp.exp new file mode 100644 index 0000000000..3a2e3f4984 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nix-version-cmp.exp @@ -0,0 +1 @@ +-1 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nix-version-cmp.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nix-version-cmp.nix new file mode 100644 index 0000000000..6f35305612 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nix-version-cmp.nix @@ -0,0 +1,5 @@ +# nixpkgs checks against the `builtins.nixVersion` and fails if it +# doesn't like what it sees. To work around this we have a "user-agent +# style" version (see cl/6858) that ensures compatibility. + +builtins.compareVersions "2.3" builtins.nixVersion diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-observable-eval-cache.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-observable-eval-cache.exp new file mode 100644 index 0000000000..aaa53b6025 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-observable-eval-cache.exp @@ -0,0 +1 @@ +[ true true false false true ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-observable-eval-cache.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-observable-eval-cache.nix new file mode 100644 index 0000000000..24003d0637 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-observable-eval-cache.nix @@ -0,0 +1,7 @@ +[ + (import ./observable-eval-cache1.nix == import ./observable-eval-cache1.nix) + (import ./observable-eval-cache1.nix == import ./observable-eval-cache2.nix) + (import ./observable-eval-cache1.nix == import ./observable-eval-cache3.nix) + (import ./observable-eval-cache2.nix == import ./observable-eval-cache3.nix) + (import ./observable-eval-cache3.nix == import ./observable-eval-cache3.nix) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-observe-infinite-attrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-observe-infinite-attrs.exp new file mode 100644 index 0000000000..bbb332a5ee --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-observe-infinite-attrs.exp @@ -0,0 +1 @@ +[ "x" "y" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-observe-infinite-attrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-observe-infinite-attrs.nix new file mode 100644 index 0000000000..684c88f800 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-observe-infinite-attrs.nix @@ -0,0 +1,4 @@ +# The below attribute set is infinitely large, but we should be able +# to observe it as long as we don't access its entire value. + +let as = { x = 123; y = as; }; in builtins.attrNames as.y.y diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-optimised-bools.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-optimised-bools.exp new file mode 100644 index 0000000000..9d9185fcd1 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-optimised-bools.exp @@ -0,0 +1 @@ +[ true true false false true true false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-optimised-bools.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-optimised-bools.nix new file mode 100644 index 0000000000..650d7f028d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-optimised-bools.nix @@ -0,0 +1,21 @@ +let + makeTrue = _: true; + makeFalse = _: false; +in +[ + # useless `false` + (false || makeTrue null) # true + (makeTrue null || false) # true + + # useless `true` + (true && makeFalse null) # false + (makeFalse null && true) # false + + # useless `||` + (true || makeFalse null) # true + (makeFalse null || true) # true + + # useless `&&` + (false && makeTrue null) # false + (makeTrue null && false) # false +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-parsedrvname.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-parsedrvname.exp new file mode 100644 index 0000000000..27ba77ddaf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-parsedrvname.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-parsedrvname.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-parsedrvname.nix new file mode 100644 index 0000000000..5997c99b47 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-parsedrvname.nix @@ -0,0 +1,11 @@ +# the first dash followed by a non-alphabetic character separates +# the "name" from the "version" + +assert builtins.parseDrvName "ripgrep-1.2" == { name = "ripgrep"; version = "1.2"; }; +assert builtins.parseDrvName "rip-grep-1.2" == { name = "rip-grep"; version = "1.2"; }; +assert builtins.parseDrvName "7zip_archiver-0.2" == { name = "7zip_archiver"; version = "0.2"; }; +assert builtins.parseDrvName "gcc-1-2" == { name = "gcc"; version = "1-2"; }; +assert builtins.parseDrvName "bash--1-2" == { name = "bash"; version = "-1-2"; }; +assert builtins.parseDrvName "xvidtune-?1-2" == { name = "xvidtune"; version = "?1-2"; }; + +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.exp new file mode 100644 index 0000000000..27ba77ddaf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.nix new file mode 100644 index 0000000000..c9eedb44ff --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.nix @@ -0,0 +1,2 @@ +builtins.pathExists ./lib.nix + && !builtins.pathExists ./bla.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-readDir.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-readDir.exp index bf8d2c14ea..bf8d2c14ea 100644 --- a/tvix/eval/src/tests/nix_tests/eval-okay-readDir.exp +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-readDir.exp diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-readDir.nix.disabled b/tvix/eval/src/tests/tvix_tests/eval-okay-readDir.nix.disabled new file mode 100644 index 0000000000..a7ec9292aa --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-readDir.nix.disabled @@ -0,0 +1 @@ +builtins.readDir ./readDir diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-readfile.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-readfile.exp new file mode 100644 index 0000000000..a2c87d0c43 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-readfile.exp @@ -0,0 +1 @@ +"builtins.readFile ./eval-okay-readfile.nix\n" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-readfile.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-readfile.nix new file mode 100644 index 0000000000..82f7cb1743 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-readfile.nix @@ -0,0 +1 @@ +builtins.readFile ./eval-okay-readfile.nix diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-rec-dynamic-keys.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-dynamic-keys.exp new file mode 100644 index 0000000000..ac8d062a69 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-dynamic-keys.exp @@ -0,0 +1 @@ +{ barbaz = 42; foobar = 42; val = 21; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-rec-dynamic-keys.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-dynamic-keys.nix new file mode 100644 index 0000000000..8d7a8cef8e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-dynamic-keys.nix @@ -0,0 +1,5 @@ +rec { + val = 21; + ${"foo" + "bar"} = 42; + ${"bar" + "baz"} = val * 2; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.exp new file mode 100644 index 0000000000..a1dca9bb68 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.exp @@ -0,0 +1 @@ +{ a = { b = 1; c = 2; }; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.nix new file mode 100644 index 0000000000..7d037c6b37 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.nix @@ -0,0 +1,4 @@ +rec { + a.b = 1; + a.c = a.b * 2; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-regex-match.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-regex-match.exp new file mode 100644 index 0000000000..9501035391 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-regex-match.exp @@ -0,0 +1 @@ +[ true true false true true true true false false true false [ "foobar" ] [ "FOO" ] [ "/path/to/" "/path/to" "foobar" "nix" ] [ null null "foobar" "cc" ] ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-regex-match.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-regex-match.nix new file mode 100644 index 0000000000..f774e00a21 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-regex-match.nix @@ -0,0 +1,29 @@ +with builtins; + +let + + matches = pat: s: match pat s != null; + + splitFN = match "((.*)/)?([^/]*)\\.(nix|cc)"; + +in + +[ + (matches "foobar" "foobar") + (matches "fo*" "f") + (matches "fo+" "f") + (matches "fo*" "fo") + (matches "fo*" "foo") + (matches "fo+" "foo") + (matches "fo{1,2}" "foo") + (matches "fo{1,2}" "fooo") + (matches "fo*" "foobar") + (matches "[[:space:]]+([^[:space:]]+)[[:space:]]+" " foo ") + (matches "[[:space:]]+([[:upper:]]+)[[:space:]]+" " foo ") + + (match "(.*)\\.nix" "foobar.nix") + (match "[[:space:]]+([[:upper:]]+)[[:space:]]+" " FOO ") + + (splitFN "/path/to/foobar.nix") + (splitFN "foobar.cc") +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-remove.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-remove.exp new file mode 100644 index 0000000000..8d38505c16 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-remove.exp @@ -0,0 +1 @@ +456 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-remove.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-remove.nix new file mode 100644 index 0000000000..62c5aa1fd4 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-remove.nix @@ -0,0 +1,5 @@ +let { +attrs = { x = 123; y = 456; }; + +body = (removeAttrs attrs [ "x" ]).y; +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.exp new file mode 100644 index 0000000000..b4a1e66d6b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.exp @@ -0,0 +1 @@ +[ 1 2 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.nix new file mode 100644 index 0000000000..ed819d76c7 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-repeated-list-to-attrs.nix @@ -0,0 +1,14 @@ +# Ensure that builtins.listToAttrs returns the first instance of a key. + +let + inherit (builtins) foldl' listToAttrs; + + input = [{ name = "result"; value = 1; } { name = "result"; value = 2; }]; + + # foldl-based version of listToAttrs with the _opposite_ behaviour. + listToAttrs' = list: foldl' (acc: elem: acc // { ${elem.name} = elem.value; }) { } list; +in +[ + (listToAttrs input).result + (listToAttrs' input).result +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-seq.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-seq.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-seq.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-seq.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-seq.nix new file mode 100644 index 0000000000..fd0806c199 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-seq.nix @@ -0,0 +1 @@ +(builtins.seq 1 2) + (builtins.seq [ (throw "list") ] 20) + (builtins.seq { boing = throw "set"; } 20) diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-simple-let.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-let.nix index b440a220ff..b4da0f824a 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-simple-let.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-let.nix @@ -1,4 +1,5 @@ let a = 1; b = 2; -in a + b +in +a + b diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-simple-with.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-with.nix index 64962b50ff..3d375be4f9 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-simple-with.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-simple-with.nix @@ -2,4 +2,5 @@ let set = { a = 1; }; -in with set; a +in +with set; a diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.exp new file mode 100644 index 0000000000..9d78376214 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.exp @@ -0,0 +1 @@ +[ { index = 7; key = 0; } { index = 0; key = 1; } { index = 13; key = 1; } { index = 1; key = 2; } { index = 3; key = 2; } { index = 4; key = 2; } { index = 5; key = 2; } { index = 12; key = 2; } { index = 14; key = 2; } { index = 2; key = 3; } { index = 11; key = 3; } { index = 15; key = 3; } { index = 10; key = 4; } { index = 6; key = 5; } { index = 8; key = 5; } { index = 9; key = 5; } { index = 16; key = 22; } ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.nix new file mode 100644 index 0000000000..9969e0a294 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.nix @@ -0,0 +1,7 @@ +let + keys = [ 1 2 3 2 2 2 5 0 5 5 4 3 2 1 2 3 22 ]; +in + +builtins.sort + (a: b: a.key < b.key) + (builtins.genList (index: { inherit index; key = builtins.elemAt keys index; }) (builtins.length keys)) diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-substring-propagate-catchables.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-substring-propagate-catchables.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-substring-propagate-catchables.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-substring-propagate-catchables.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-substring-propagate-catchables.nix new file mode 100644 index 0000000000..78d5dda38e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-substring-propagate-catchables.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.substring 0 4 (throw "jill"))).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-default-args.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-default-args.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-default-args.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-default-args.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-default-args.nix new file mode 100644 index 0000000000..0523cf864c --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-default-args.nix @@ -0,0 +1 @@ +(builtins.tryEval (({ foo ? throw "up" }: if foo then 1 else 2) { })).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.nix new file mode 100644 index 0000000000..126738d883 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.nix @@ -0,0 +1 @@ +(builtins.tryEval (({ foo ? throw "up" }: foo -> true) { })).success diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-functor.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-functor.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-functor.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-functor.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-functor.nix new file mode 100644 index 0000000000..568a5c5413 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-functor.nix @@ -0,0 +1,8 @@ +let + __functor = f; + f = self: x: self.out * x; +in +{ + inherit __functor; + out = 21; +} 2 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-if.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-if.exp new file mode 100644 index 0000000000..ffcd4415b0 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-if.exp @@ -0,0 +1 @@ +{ } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-if.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-if.nix new file mode 100644 index 0000000000..3810ebe784 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-if.nix @@ -0,0 +1,8 @@ +let + a = { }; +in +let + c = if builtins.isFunction a then a b else a; + b = { }; +in +c diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-with.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-with.nix index 6f32660c4c..799408b2e6 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-with.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-thunked-with.nix @@ -4,4 +4,5 @@ let set = { a = with { b = 42; }; b; }; -in set.a +in +set.a diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-toplevel-finaliser.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-toplevel-finaliser.nix index 4c6884bec3..5f25f80671 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-toplevel-finaliser.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-toplevel-finaliser.nix @@ -5,6 +5,7 @@ let a = 1; b = 2; c = 3; -in { +in +{ inherit a b c; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-toxml-empty.exp.xml b/tvix/eval/src/tests/tvix_tests/eval-okay-toxml-empty.exp.xml new file mode 100644 index 0000000000..468972b2f8 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-toxml-empty.exp.xml @@ -0,0 +1,5 @@ +<?xml version='1.0' encoding='utf-8'?> +<expr> + <attrs> + </attrs> +</expr> diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-toxml-empty.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-toxml-empty.nix new file mode 100644 index 0000000000..ffcd4415b0 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-toxml-empty.nix @@ -0,0 +1 @@ +{ } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-toxml.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-toxml.exp new file mode 100644 index 0000000000..9ae16de526 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-toxml.exp @@ -0,0 +1 @@ +"<?xml version='1.0' encoding='utf-8'?>\n<expr>\n <attrs>\n <attr name=\"&-{\">\n <string value=\";&"\" />\n </attr>\n <attr name=\"a\">\n <string value=\"s\" />\n </attr>\n </attrs>\n</expr>\n" diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-toxml.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-toxml.nix new file mode 100644 index 0000000000..7d074048dd --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-toxml.nix @@ -0,0 +1,2 @@ +# Check some corner cases regarding escaping. +builtins.toXML { a = "s"; "&-{" = ";&\""; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval-thunk-twice.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval-thunk-twice.exp new file mode 100644 index 0000000000..b5ba0757c1 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval-thunk-twice.exp @@ -0,0 +1 @@ +[ { success = false; value = false; } { success = false; value = false; } ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval-thunk-twice.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval-thunk-twice.nix new file mode 100644 index 0000000000..1749643f82 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval-thunk-twice.nix @@ -0,0 +1 @@ +let x = throw "lol"; in builtins.map (f: f x) [ builtins.tryEval builtins.tryEval ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.exp new file mode 100644 index 0000000000..8b6ed7dbac --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.exp @@ -0,0 +1 @@ +{ v = false; w = { success = false; value = false; }; x = { success = true; value = "x"; }; y = { success = false; value = false; }; z = { success = false; value = false; }; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.nix new file mode 100644 index 0000000000..e2357c7987 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.nix @@ -0,0 +1,7 @@ +{ + v = (builtins.tryEval (toString <oink>)).value; + w = builtins.tryEval <nope>; + x = builtins.tryEval "x"; + y = builtins.tryEval (assert false; "y"); + z = builtins.tryEval (throw "bla"); +} diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-unpoison-scope.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-unpoison-scope.nix index 30e9667da8..539735a8ef 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-unpoison-scope.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-unpoison-scope.nix @@ -1,7 +1,10 @@ let - poisoned = let - true = 1; - false = 2; - null = 3; - in [ true false null ]; -in [ true false null ] ++ poisoned + poisoned = + let + true = 1; + false = 2; + null = 3; + in + [ true false null ]; +in +[ true false null ] ++ poisoned diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-useless-inherit-with.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-useless-inherit-with.nix index d335e53630..dd768c1aca 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-useless-inherit-with.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-useless-inherit-with.nix @@ -3,13 +3,14 @@ # provide the value. # Provide a dynamic `x` identifier in the scope. -with ({ x = 1;}); +with ({ x = 1; }); # inherit this `x` as a static identifier let inherit x; -# Provide another dynamic `x` identifier -in with ({ x = 3; }); + # Provide another dynamic `x` identifier +in +with ({ x = 3; }); # Inherited static identifier should have precedence x diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-value-display.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-value-display.exp new file mode 100644 index 0000000000..c7e3fc6503 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-value-display.exp @@ -0,0 +1 @@ +[ null true false 42 42 "foo\t\nbar" /home/arthur [ 1 2 3 ] <LAMBDA> <PRIMOP> <PRIMOP-APP> { hello = "world"; } ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-value-display.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-value-display.nix new file mode 100644 index 0000000000..d34ed1697e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-value-display.nix @@ -0,0 +1,16 @@ +# Sanity check of how values are rendered by tvix vs. nix-instantiate(1). +# Ensures that we can use this test suite to compare against C++ Nix. +[ + null + true + false + 42 + 42.0 + "foo\t\nbar" + /home/arthur + [ 1 2 3 ] + (x: x) + builtins.add + (builtins.substring 0 1) + { hello = "world"; } +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-compare.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-compare.exp new file mode 100644 index 0000000000..27ba77ddaf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-compare.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-compare.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-compare.nix new file mode 100644 index 0000000000..c2ca913af2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-compare.nix @@ -0,0 +1,6 @@ +# For an explanation of this behavior see //tvix/docs/value-pointer-equality.md +let + f = owo: "thia"; +in + +[ f 42 ] > [ f 21 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.exp new file mode 100644 index 0000000000..aec30f297a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.exp @@ -0,0 +1 @@ +[ true true true true false false false true true true true true true true true true false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.nix new file mode 100644 index 0000000000..b5cfbeb12e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.nix @@ -0,0 +1,46 @@ +# For an explanation of this behavior see //tvix/docs/value-pointer-equality.md +let + # Some incomparable values + f = MC: "Boing"; + t = [ (throw "is a little blue man") ]; + a = { "with" = abort "headphones and a big smile."; }; + + # Aliases + f' = f; + t' = t; + a' = a; + + peq1 = a: b: [ a ] == [ b ]; + peq2 = a: b: { x = a; } == { x = b; }; +in + +[ + # pointer equality of functions + (peq1 f f) + (peq2 f f) + (peq1 f f') + (peq2 f f') + + # encapsulation is necessary for pointer equality + (f == f) + (f == f') + # works with != + ([ f ] != [ f' ]) + + # thunks that fail to evaluated wrapped in sets/lists + (peq1 t t) + (peq2 t t) + (peq1 a a) + (peq2 a a) + (peq1 t t') + (peq2 t t') + (peq1 a' a) + (peq2 a' a) + + # function equality with builtins.elem + (builtins.elem f [ 21 f 42 ]) + + # pointer inequality + (peq1 f (x: x)) + (peq2 (x: x) f) +] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-with-in-dynamic-key.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-with-in-dynamic-key.nix index c44455a5bf..bf221746c0 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-with-in-dynamic-key.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-with-in-dynamic-key.nix @@ -9,4 +9,5 @@ let ${with set1; key} = 20; ${with { key = "c"; }; key} = 2; }; -in set2.a + set2.b + set2.c +in +set2.a + set2.b + set2.c diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-with-in-list.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-with-in-list.nix index bb62fdf31c..3e85cbee45 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-with-in-list.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-with-in-list.nix @@ -6,7 +6,8 @@ let set = { value = 2; }; -in [ +in +[ 1 (with set; value) 3 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-xml.exp.xml b/tvix/eval/src/tests/tvix_tests/eval-okay-xml.exp.xml new file mode 100644 index 0000000000..1521bcc97a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-xml.exp.xml @@ -0,0 +1,41 @@ +<?xml version='1.0' encoding='utf-8'?> +<expr> + <attrs> + <attr name="attrspat"> + <function> + <attrspat name="args"> + <attr name="x" /> + <attr name="y" /> + <attr name="z" /> + </attrspat> + </function> + </attr> + <attr name="attrspat-ellipsis"> + <function> + <attrspat ellipsis="1" name="args"> + <attr name="x" /> + <attr name="y" /> + <attr name="z" /> + </attrspat> + </function> + </attr> + <attr name="noattrspat"> + <function> + <attrspat> + <attr name="x" /> + <attr name="y" /> + <attr name="z" /> + </attrspat> + </function> + </attr> + <attr name="noattrspat-ellipsis"> + <function> + <attrspat ellipsis="1"> + <attr name="x" /> + <attr name="y" /> + <attr name="z" /> + </attrspat> + </function> + </attr> + </attrs> +</expr> diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-xml.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-xml.nix new file mode 100644 index 0000000000..3cc5acf430 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-xml.nix @@ -0,0 +1,7 @@ +{ + attrspat = args@{ x, y, z }: x; + attrspat-ellipsis = args@{ x, y, z, ... }: x; + + noattrspat = { x, y, z }: x; + noattrspat-ellipsis = { x, y, z, ... }: x; +} diff --git a/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-assert.nix b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-assert.nix new file mode 100644 index 0000000000..575b1af588 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-assert.nix @@ -0,0 +1 @@ +{ "assert" = true; } diff --git a/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-else.nix b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-else.nix new file mode 100644 index 0000000000..7601f14b32 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-else.nix @@ -0,0 +1 @@ +{ "else" = true; } diff --git a/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-if.nix b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-if.nix new file mode 100644 index 0000000000..1c391fc9a3 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-if.nix @@ -0,0 +1 @@ +{ "if" = true; } diff --git a/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-in.nix b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-in.nix new file mode 100644 index 0000000000..b4f238651d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-in.nix @@ -0,0 +1 @@ +{ "in" = true; } diff --git a/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-inherit.nix b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-inherit.nix new file mode 100644 index 0000000000..e62ed32b04 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-inherit.nix @@ -0,0 +1 @@ +{ "inherit" = true; } diff --git a/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-let.nix b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-let.nix new file mode 100644 index 0000000000..196ec7cc88 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-let.nix @@ -0,0 +1 @@ +{ "let" = true; } diff --git a/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-rec.nix b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-rec.nix new file mode 100644 index 0000000000..d2c4f93a2a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-rec.nix @@ -0,0 +1 @@ +{ "rec" = true; } diff --git a/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-then.nix b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-then.nix new file mode 100644 index 0000000000..f2af8d6970 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-then.nix @@ -0,0 +1 @@ +{ "then" = true; } diff --git a/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-with.nix b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-with.nix new file mode 100644 index 0000000000..cbcfa970c2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/identity-quoted-attrname-with.nix @@ -0,0 +1 @@ +{ "with" = true; } diff --git a/tvix/eval/src/tests/tvix_tests/lib.nix b/tvix/eval/src/tests/tvix_tests/lib.nix new file mode 100644 index 0000000000..ab509bc85f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/lib.nix @@ -0,0 +1,64 @@ +with builtins; + +rec { + + fold = op: nul: list: + if list == [ ] + then nul + else op (head list) (fold op nul (tail list)); + + concat = + fold (x: y: x + y) ""; + + and = fold (x: y: x && y) true; + + flatten = x: + if isList x + then fold (x: y: (flatten x) ++ y) [ ] x + else [ x ]; + + sum = foldl' (x: y: add x y) 0; + + hasSuffix = ext: fileName: + let + lenFileName = stringLength fileName; + lenExt = stringLength ext; + in + !(lessThan lenFileName lenExt) && + substring (sub lenFileName lenExt) lenFileName fileName == ext; + + # Split a list at the given position. + splitAt = pos: list: + if pos == 0 then { first = [ ]; second = list; } else + if list == [ ] then { first = [ ]; second = [ ]; } else + let res = splitAt (sub pos 1) (tail list); + in { first = [ (head list) ] ++ res.first; second = res.second; }; + + # Stable merge sort. + sortBy = comp: list: + if lessThan 1 (length list) + then + let + split = splitAt (div (length list) 2) list; + first = sortBy comp split.first; + second = sortBy comp split.second; + in + mergeLists comp first second + else list; + + mergeLists = comp: list1: list2: + if list1 == [ ] then list2 else + if list2 == [ ] then list1 else + if comp (head list2) (head list1) then [ (head list2) ] ++ mergeLists comp list1 (tail list2) else + [ (head list1) ] ++ mergeLists comp (tail list1) list2; + + id = x: x; + + const = x: y: x; + + range = first: last: + if first > last + then [ ] + else genList (n: first + n) (last - first + 1); + +} diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-fail-builtins-genericClosure-uncomparable-keys.nix b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-fail-builtins-genericClosure-uncomparable-keys.nix new file mode 100644 index 0000000000..d4e93e1f28 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-fail-builtins-genericClosure-uncomparable-keys.nix @@ -0,0 +1,9 @@ +# Attribute sets can't be compared, only checked for equality +builtins.genericClosure { + startSet = [ + { key = { foo = 21; }; } + ]; + operator = _: [ + { key = { bar = 21; }; } + ]; +} diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-fail-builtins-genericClosure-uncomparable-keys2.nix b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-fail-builtins-genericClosure-uncomparable-keys2.nix new file mode 100644 index 0000000000..0589a3ab59 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-fail-builtins-genericClosure-uncomparable-keys2.nix @@ -0,0 +1,12 @@ +let + id = x: x; +in + +builtins.genericClosure { + startSet = [{ key = id; first = true; }]; + operator = + { first, ... }: + if first then [ + { key = id; first = false; } + ] else [ ]; +} diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-builtins-set-pointer-equality.exp b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-builtins-set-pointer-equality.exp new file mode 100644 index 0000000000..097eb2033a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-builtins-set-pointer-equality.exp @@ -0,0 +1 @@ +[ true true true true true true true true true true ] diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-builtins-set-pointer-equality.nix b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-builtins-set-pointer-equality.nix new file mode 100644 index 0000000000..aa2a0a1e19 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-builtins-set-pointer-equality.nix @@ -0,0 +1,25 @@ +let + alias = builtins; +in + +[ + (builtins == builtins) + (alias == builtins) + (builtins == builtins.builtins) + (builtins.builtins == builtins.builtins) + (builtins.builtins == builtins.builtins.builtins) + (alias == alias) + (alias == builtins.builtins) + ([ builtins ] == [ builtins ]) + + # Surprisingly the following expressions don't work. They are + # here for documentation purposes and covered only + # by eval-okay-select-pointer-inequality.nix. Reasoning is that + # we may not want / be able to replicate this behavior at all. + # ([ builtins.add ] == [ builtins.add ]) + # ({ inherit (builtins) import; } == { inherit (builtins) import; }) + + # These expressions work as expected, however: + (let x = { inherit (builtins) add; }; in x == x) + (let inherit (builtins) add; in [ add ] == [ add ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-cycle-display-cpp-nix-2.13.exp b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-cycle-display-cpp-nix-2.13.exp new file mode 100644 index 0000000000..9c44023f02 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-cycle-display-cpp-nix-2.13.exp @@ -0,0 +1 @@ +[ { car = 42; cdr = «repeated»; } [ «repeated» «repeated» «repeated» ] { val = 42; wal = «repeated»; xal = «repeated»; } { tail1 = «repeated»; tail2 = «repeated»; val = 42; } { tail1 = «repeated»; tail2 = «repeated»; val = 21; } ] diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-cycle-display-cpp-nix-2.13.nix b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-cycle-display-cpp-nix-2.13.nix new file mode 100644 index 0000000000..ac849a58fe --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-cycle-display-cpp-nix-2.13.nix @@ -0,0 +1,34 @@ +let + linkedList = { + car = 42; + cdr = linkedList; + }; + + list = [ + linkedList + linkedList + linkedList + ]; + + set = { + val = 42; + wal = set; + xal = set; + }; + + multiTail = { + val = 42; + tail1 = multiTail; + tail2 = multiTail; + }; +in + +[ + linkedList + list + set + + # In C++ Nix 2.3 these would be displayed differently + multiTail + (let multiTail = { val = 21; tail1 = multiTail; tail2 = multiTail; }; in multiTail) +] diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-minimal-2.3-builtins.exp b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-minimal-2.3-builtins.exp new file mode 100644 index 0000000000..967fc858bc --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-minimal-2.3-builtins.exp @@ -0,0 +1 @@ +[ "abort" "add" "addErrorContext" "all" "any" "appendContext" "attrNames" "attrValues" "baseNameOf" "bitAnd" "bitOr" "bitXor" "builtins" "catAttrs" "compareVersions" "concatLists" "concatMap" "concatStringsSep" "currentSystem" "currentTime" "deepSeq" "derivation" "derivationStrict" "dirOf" "div" "elem" "elemAt" "false" "fetchGit" "fetchMercurial" "fetchTarball" "fetchurl" "filter" "filterSource" "findFile" "foldl'" "fromJSON" "fromTOML" "functionArgs" "genList" "genericClosure" "getAttr" "getContext" "getEnv" "hasAttr" "hasContext" "hashFile" "hashString" "head" "import" "intersectAttrs" "isAttrs" "isBool" "isFloat" "isFunction" "isInt" "isList" "isNull" "isPath" "isString" "langVersion" "length" "lessThan" "listToAttrs" "map" "mapAttrs" "match" "mul" "nixPath" "nixVersion" "null" "parseDrvName" "partition" "path" "pathExists" "placeholder" "readDir" "readFile" "removeAttrs" "replaceStrings" "scopedImport" "seq" "sort" "split" "splitVersion" "storeDir" "storePath" "stringLength" "sub" "substring" "tail" "throw" "toFile" "toJSON" "toPath" "toString" "toXML" "trace" "true" "tryEval" "typeOf" "unsafeDiscardOutputDependency" "unsafeDiscardStringContext" "unsafeGetAttrPos" ] diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-minimal-2.3-builtins.nix b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-minimal-2.3-builtins.nix new file mode 100644 index 0000000000..4480daecd9 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-minimal-2.3-builtins.nix @@ -0,0 +1,122 @@ +# This tests verifies that the Nix implementation evaluating this has at least +# all the builtins given in `minimalBuiltins`. We don't test a precise list of +# builtins since we accept that there will always be difference between the +# builtins sets of Tvix, C++ Nix 2.3 and newer C++ Nix versions, as new builtins +# are added. +# +# Tvix also may choose never to implement some builtins if they are only useful +# for flakes or perform well enough via the shims nixpkgs usually provides. + +let + # C++ Nix 2.3 builtins except valueSize which is removed in later versions + minimalBuiltins = [ + "abort" + "add" + "addErrorContext" + "all" + "any" + "appendContext" + "attrNames" + "attrValues" + "baseNameOf" + "bitAnd" + "bitOr" + "bitXor" + "builtins" + "catAttrs" + "compareVersions" + "concatLists" + "concatMap" + "concatStringsSep" + "currentSystem" + "currentTime" + "deepSeq" + "derivation" + "derivationStrict" + "dirOf" + "div" + "elem" + "elemAt" + "false" + "fetchGit" + "fetchMercurial" + "fetchTarball" + "fetchurl" + "filter" + "filterSource" + "findFile" + "foldl'" + "fromJSON" + "fromTOML" + "functionArgs" + "genList" + "genericClosure" + "getAttr" + "getContext" + "getEnv" + "hasAttr" + "hasContext" + "hashFile" + "hashString" + "head" + "import" + "intersectAttrs" + "isAttrs" + "isBool" + "isFloat" + "isFunction" + "isInt" + "isList" + "isNull" + "isPath" + "isString" + "langVersion" + "length" + "lessThan" + "listToAttrs" + "map" + "mapAttrs" + "match" + "mul" + "nixPath" + "nixVersion" + "null" + "parseDrvName" + "partition" + "path" + "pathExists" + "placeholder" + "readDir" + "readFile" + "removeAttrs" + "replaceStrings" + "scopedImport" + "seq" + "sort" + "split" + "splitVersion" + "storeDir" + "storePath" + "stringLength" + "sub" + "substring" + "tail" + "throw" + "toFile" + "toJSON" + "toPath" + "toString" + "toXML" + "trace" + "true" + "tryEval" + "typeOf" + "unsafeDiscardOutputDependency" + "unsafeDiscardStringContext" + "unsafeGetAttrPos" + ]; + + intersectLists = as: bs: builtins.filter (a: builtins.elem a bs) as; +in + +intersectLists minimalBuiltins (builtins.attrNames builtins) diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-non-identifier-pointer-inequality.exp b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-non-identifier-pointer-inequality.exp new file mode 100644 index 0000000000..69fd1d0847 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-non-identifier-pointer-inequality.exp @@ -0,0 +1 @@ +[ false false false false false true false false ] diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-non-identifier-pointer-inequality.nix b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-non-identifier-pointer-inequality.nix new file mode 100644 index 0000000000..821aa47a0d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-non-identifier-pointer-inequality.nix @@ -0,0 +1,28 @@ +# C++ Nix frequently creates copies of Value structs when evaluating +# a variety of expressions. As a result, pointer equality doesn't +# work for many (all?) expressions that go beyond simple identifier +# access from the scope: Even if the inner representation of the +# value still has the same memory location, C++ Nix has created +# a copy of the struct that holds the pointer to this memory. +# Since pointer equality is established via the location of +# the latter, not the former, the values are no longer equal +# by pointer. +let + foo = { bar = x: x; }; + + id = x: x; +in + +[ + ({ inherit (foo) bar; } == { inherit (foo) bar; }) + ([ foo.bar ] == [ foo.bar ]) + + ([ builtins.add ] == [ builtins.add ]) + ({ inherit (builtins) import; } == { inherit (builtins) import; }) + + ([ (id id) ] == [ (id id) ]) + ([ id ] == [ id ]) + + (with foo; [ bar ] == [ bar ]) + (with builtins; [ add ] == [ add ]) +] diff --git a/tvix/eval/src/tests/tvix_tests/observable-eval-cache1.nix b/tvix/eval/src/tests/tvix_tests/observable-eval-cache1.nix new file mode 100644 index 0000000000..b5f3f59a79 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/observable-eval-cache1.nix @@ -0,0 +1 @@ +let id = x: x; in { inherit id; } diff --git a/tvix/eval/src/tests/tvix_tests/observable-eval-cache2.nix b/tvix/eval/src/tests/tvix_tests/observable-eval-cache2.nix new file mode 120000 index 0000000000..7f69c0eb47 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/observable-eval-cache2.nix @@ -0,0 +1 @@ +observable-eval-cache1.nix \ No newline at end of file diff --git a/tvix/eval/src/tests/tvix_tests/observable-eval-cache3.nix b/tvix/eval/src/tests/tvix_tests/observable-eval-cache3.nix new file mode 100644 index 0000000000..b5f3f59a79 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/observable-eval-cache3.nix @@ -0,0 +1 @@ +let id = x: x; in { inherit id; } diff --git a/tvix/eval/src/tests/tvix_tests/readDir/bar b/tvix/eval/src/tests/tvix_tests/readDir/bar new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/readDir/bar diff --git a/tvix/eval/src/tests/tvix_tests/readDir/foo/.keep b/tvix/eval/src/tests/tvix_tests/readDir/foo/.keep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/readDir/foo/.keep |