From 78d19ff3e91a3cb712ac32a984d6dd7959daa96b Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 18 Sep 2022 13:20:48 -0400 Subject: test(tvix/eval): Allow passing ProptestConfig to generated props Add an optional config argument to the `_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 Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/properties.rs | 55 ++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'tvix') 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; -- cgit 1.4.1