From bbc1efdb0e252eacd0ccb660b66c002fc7534f4b Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 7 May 2025 15:03:46 +0300 Subject: [PATCH] test(eval): add test for deep force key order This tests deep forcing happens in lexicographic key order, by comparing the returned error from the evaluator. It's not possible to observe this from inside nixlang, which is why we use one_offs.rs here. Change-Id: I73085addca3a4df20bc23f9fced458758af5b391 Reviewed-on: https://cl.snix.dev/c/snix/+/30488 Reviewed-by: Bence Nemes Tested-by: besadii Autosubmit: Florian Klink --- snix/Cargo.nix | 1 + snix/eval/Cargo.toml | 2 +- snix/eval/src/tests/one_offs.rs | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/snix/Cargo.nix b/snix/Cargo.nix index 8074f37ab..d3c65be17 100644 --- a/snix/Cargo.nix +++ b/snix/Cargo.nix @@ -14281,6 +14281,7 @@ rec { { name = "pretty_assertions"; packageId = "pretty_assertions"; + features = [ "unstable" ]; } { name = "rstest"; diff --git a/snix/eval/Cargo.toml b/snix/eval/Cargo.toml index 2e41bf477..d16971332 100644 --- a/snix/eval/Cargo.toml +++ b/snix/eval/Cargo.toml @@ -41,7 +41,7 @@ thiserror.workspace = true criterion.workspace = true itertools.workspace = true mimalloc.workspace = true -pretty_assertions.workspace = true +pretty_assertions = { workspace = true, features = ["unstable"] } rstest.workspace = true tempfile.workspace = true diff --git a/snix/eval/src/tests/one_offs.rs b/snix/eval/src/tests/one_offs.rs index 49ed713fc..7550f4e7a 100644 --- a/snix/eval/src/tests/one_offs.rs +++ b/snix/eval/src/tests/one_offs.rs @@ -1,4 +1,5 @@ use crate::*; +use pretty_assertions::assert_matches; #[test] fn test_source_builtin() { @@ -37,3 +38,26 @@ fn skip_broken_bytecode() { ErrorKind::UnknownStaticVariable )); } + +/// Checks that deep forcing happens in lexicographic key order +/// See https://cl.snix.dev/c/snix/+/30309/comment/a7c9c6d5_bacf7332/ for +/// details. +#[test] +fn key_order_deep_force() { + let result = Evaluation::builder_pure().build().evaluate( + /* code = */ + r#"builtins.toXML { + c = throw "ccc"; + a = throw "aaa"; + b = throw "bbb"; + d = throw "dd"; + }"#, + None, + ); + assert_eq!(result.errors.len(), 1); + + assert_matches!( + &result.errors[0].kind, + ErrorKind::CatchableError(CatchableErrorKind::Throw(s)) if s.as_ref() == "\"aaa\"" + ); +}