diff options
author | Ryan Lahfa <tvl@lahfa.xyz> | 2023-12-25T21·07+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-01-03T23·24+0000 |
commit | 556e52c9cb8aa7b2af8bae75cd3365318e5d08c2 (patch) | |
tree | ab7c18bd41d27711039812fb182e4e89b0d66311 /tvix/glue/src/builtins/mod.rs | |
parent | 099ca6b7c0b95d1e7d5134ac465b50bbd86660c5 (diff) |
feat(tvix/eval): impl `unsafeDiscardStringContext` r/7339
Change-Id: I7f0cc42cbebfe5cd27bf6d4f58a4af927b83646a Reviewed-on: https://cl.tvl.fyi/c/depot/+/10423 Autosubmit: raitobezarius <tvl@lahfa.xyz> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/glue/src/builtins/mod.rs')
-rw-r--r-- | tvix/glue/src/builtins/mod.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tvix/glue/src/builtins/mod.rs b/tvix/glue/src/builtins/mod.rs index c70edceb3ebd..6ae99ba14759 100644 --- a/tvix/glue/src/builtins/mod.rs +++ b/tvix/glue/src/builtins/mod.rs @@ -143,6 +143,51 @@ mod tests { ); } + /// Construct two derivations with the same parameters except + /// one of them lost a context string for a dependency, causing + /// the loss of an element in the `inputDrvs` derivation. + /// Therefore, making `outPath` different. + #[test] + fn test_unsafe_discard_string_context() { + let code = r#" + let + dep = builtins.derivation { name = "foo"; builder = "/bin/sh"; system = "x86_64-linux"; }; + in + (builtins.derivation { name = "foo"; builder = "/bin/sh"; system = "x86_64-linux"; env = "${dep}"; }).outPath != + (builtins.derivation { name = "foo"; builder = "/bin/sh"; system = "x86_64-linux"; env = "${builtins.unsafeDiscardStringContext dep}"; }).outPath + "#; + + let value = eval(code).value.expect("must succeed"); + match value { + tvix_eval::Value::Bool(v) => { + assert!(v); + } + _ => panic!("unexpected value type: {:?}", value), + } + } + + /// Construct an attribute set + /// that coerces to a derivation + /// and verify that the return type is a string. + #[test] + fn test_unsafe_discard_string_context_of_coercible() { + let code = r#" + let + dep = builtins.derivation { name = "foo"; builder = "/bin/sh"; system = "x86_64-linux"; }; + attr = { __toString = _: dep; }; + in + builtins.typeOf (builtins.unsafeDiscardStringContext attr) == "string" + "#; + + let value = eval(code).value.expect("must succeed"); + match value { + tvix_eval::Value::Bool(v) => { + assert!(v); + } + _ => panic!("unexpected value type: {:?}", value), + } + } + #[test] fn builtins_placeholder_hashes() { assert_eq!( |