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 <nemes.bence1@gmail.com>
Tested-by: besadii
Autosubmit: Florian Klink <flokli@flokli.de>
This commit is contained in:
Florian Klink 2025-05-07 15:03:46 +03:00 committed by clbot
parent e97cf628a3
commit bbc1efdb0e
3 changed files with 26 additions and 1 deletions

View file

@ -14281,6 +14281,7 @@ rec {
{ {
name = "pretty_assertions"; name = "pretty_assertions";
packageId = "pretty_assertions"; packageId = "pretty_assertions";
features = [ "unstable" ];
} }
{ {
name = "rstest"; name = "rstest";

View file

@ -41,7 +41,7 @@ thiserror.workspace = true
criterion.workspace = true criterion.workspace = true
itertools.workspace = true itertools.workspace = true
mimalloc.workspace = true mimalloc.workspace = true
pretty_assertions.workspace = true pretty_assertions = { workspace = true, features = ["unstable"] }
rstest.workspace = true rstest.workspace = true
tempfile.workspace = true tempfile.workspace = true

View file

@ -1,4 +1,5 @@
use crate::*; use crate::*;
use pretty_assertions::assert_matches;
#[test] #[test]
fn test_source_builtin() { fn test_source_builtin() {
@ -37,3 +38,26 @@ fn skip_broken_bytecode() {
ErrorKind::UnknownStaticVariable 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\""
);
}