diff options
author | Griffin Smith <root@gws.fyi> | 2022-09-18T17·20-0400 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-09-18T17·55+0000 |
commit | 78d19ff3e91a3cb712ac32a984d6dd7959daa96b (patch) | |
tree | c8b277c886a0ac42943f4ebff8ed89404cf01858 /tvix/eval | |
parent | f8b380672043e9b870c4303ce47205a1435de8ee (diff) |
test(tvix/eval): Allow passing ProptestConfig to generated props r/4903
Add an optional config argument to the `<trait>_laws` macros, to allow configuring the generated tests with a ProptestConfig struct (to limit the number of cases run) Change-Id: I2143ddb72c6a870e8be4a9058135b6f9a703039e Reviewed-on: https://cl.tvl.fyi/c/depot/+/6646 Autosubmit: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval')
-rw-r--r-- | tvix/eval/src/properties.rs | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/tvix/eval/src/properties.rs b/tvix/eval/src/properties.rs index 72a2fe29ef55..8ca11d6729c0 100644 --- a/tvix/eval/src/properties.rs +++ b/tvix/eval/src/properties.rs @@ -5,28 +5,37 @@ macro_rules! eq_laws { ($ty: ty) => { eq_laws!( #[strategy(::proptest::arbitrary::any::<$ty>())] - $ty + $ty, + Default::default() ); }; - (#[$meta: meta] $ty: ty) => { + ($ty: ty, $config: expr) => { + eq_laws!( + #[strategy(::proptest::arbitrary::any::<$ty>())] + $ty, + $config + ); + }; + (#[$meta: meta] $ty: ty, $config: expr) => { #[allow(clippy::eq_op)] mod eq { use test_strategy::proptest; use super::*; - #[proptest] + #[proptest($config)] fn reflexive(#[$meta] x: $ty) { assert!(x == x); } - #[proptest] + #[proptest($config)] fn symmetric(#[$meta] x: $ty, #[$meta] y: $ty) { assert_eq!(x == y, y == x); } - #[proptest] + #[proptest($config)] fn transitive(#[$meta] x: $ty, #[$meta] y: $ty, #[$meta] z: $ty) { + dbg!(&x, &y, &z); if x == y && y == z { assert!(x == z); } @@ -40,21 +49,29 @@ macro_rules! ord_laws { ($ty: ty) => { ord_laws!( #[strategy(::proptest::arbitrary::any::<$ty>())] - $ty + $ty, + Default::default() + ); + }; + ($ty: ty, $config: expr) => { + ord_laws!( + #[strategy(::proptest::arbitrary::any::<$ty>())] + $ty, + $config ); }; - (#[$meta: meta] $ty: ty) => { + (#[$meta: meta] $ty: ty, $config: expr) => { mod ord { use test_strategy::proptest; use super::*; - #[proptest] + #[proptest($config)] fn partial_cmp_matches_cmp(#[$meta] x: $ty, #[$meta] y: $ty) { assert_eq!(x.partial_cmp(&y), Some(x.cmp(&y))); } - #[proptest] + #[proptest($config)] fn dual(#[$meta] x: $ty, #[$meta] y: $ty) { if x < y { assert!(y > x); @@ -64,21 +81,21 @@ macro_rules! ord_laws { } } - #[proptest] + #[proptest($config)] fn le_transitive(#[$meta] x: $ty, #[$meta] y: $ty, #[$meta] z: $ty) { if x < y && y < z { assert!(x < z) } } - #[proptest] + #[proptest($config)] fn gt_transitive(#[$meta] x: $ty, #[$meta] y: $ty, #[$meta] z: $ty) { if x > y && y > z { assert!(x > z) } } - #[proptest] + #[proptest($config)] fn trichotomy(#[$meta] x: $ty, #[$meta] y: $ty) { let less = x < y; let greater = x > y; @@ -108,16 +125,24 @@ macro_rules! hash_laws { ($ty: ty) => { hash_laws!( #[strategy(::proptest::arbitrary::any::<$ty>())] - $ty + $ty, + Default::default() + ); + }; + ($ty: ty, $config: expr) => { + hash_laws!( + #[strategy(::proptest::arbitrary::any::<$ty>())] + $ty, + $config ); }; - (#[$meta: meta] $ty: ty) => { + (#[$meta: meta] $ty: ty, $config: expr) => { mod hash { use test_strategy::proptest; use super::*; - #[proptest] + #[proptest($config)] fn matches_eq(#[$meta] x: $ty, #[$meta] y: $ty) { let hash = |x: &$ty| { use std::hash::Hasher; |