about summary refs log tree commit diff
path: root/tvix/eval/src/value/attrs/tests.rs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2022-09-18T18·04-0400
committerclbot <clbot@tvl.fyi>2022-09-18T22·03+0000
commit915ff5ac2a180cbd736ce8404c46566a14d484ba (patch)
tree678073b71f03f67c7c7294a949f0177f5987b167 /tvix/eval/src/value/attrs/tests.rs
parent0e5baae7ad16ca2a5a70ba34d922cabcaa68d45e (diff)
refactor(tvix/eval): Don't (ab)use PartialEq for Nix equality r/4908
Using rust's PartialEq trait to implement Nix equality semantics is
reasonably fraught with peril, both because the actual laws are
different than what nix expects, and (more importantly) because certain
things actually require extra context to compare for equality (for
example, thunks need to be forced). This converts the manual PartialEq
impl for Value (and all its descendants) to a *derived* PartialEq
impl (which requires a lot of extra PartialEq derives on miscellanious
other types within the codebase), and converts the previous
nix-semantics equality comparison into a new `nix_eq` method. This
returns an EvalResult, even though it can't currently return an error,
to allow it to fail when eg forcing thunks (which it will do soon).

Since the PartialEq impls for Value and NixAttrs are now quite boring,
this converts the generated proptests for those into handwritten ones
that cover `nix_eq` instead

Change-Id: If3da7171f88c22eda5b7a60030d8b00c3b76f672
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6650
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval/src/value/attrs/tests.rs')
-rw-r--r--tvix/eval/src/value/attrs/tests.rs30
1 files changed, 21 insertions, 9 deletions
diff --git a/tvix/eval/src/value/attrs/tests.rs b/tvix/eval/src/value/attrs/tests.rs
index e25b362d2565..e96d50855b84 100644
--- a/tvix/eval/src/value/attrs/tests.rs
+++ b/tvix/eval/src/value/attrs/tests.rs
@@ -1,15 +1,27 @@
-use proptest::prelude::ProptestConfig;
-
 use super::*;
-use crate::properties::eq_laws;
 
-eq_laws!(
-    NixAttrs,
-    ProptestConfig {
-        cases: 5,
-        ..Default::default()
+mod nix_eq {
+    use super::*;
+    use proptest::prelude::ProptestConfig;
+    use test_strategy::proptest;
+
+    #[proptest(ProptestConfig { cases: 5, ..Default::default() })]
+    fn reflexive(x: NixAttrs) {
+        assert!(x.nix_eq(&x).unwrap())
+    }
+
+    #[proptest(ProptestConfig { cases: 5, ..Default::default() })]
+    fn symmetric(x: NixAttrs, y: NixAttrs) {
+        assert_eq!(x.nix_eq(&y).unwrap(), y.nix_eq(&x).unwrap())
     }
-);
+
+    #[proptest(ProptestConfig { cases: 5, ..Default::default() })]
+    fn transitive(x: NixAttrs, y: NixAttrs, z: NixAttrs) {
+        if x.nix_eq(&y).unwrap() && y.nix_eq(&z).unwrap() {
+            assert!(x.nix_eq(&z).unwrap())
+        }
+    }
+}
 
 #[test]
 fn test_empty_attrs() {