@@ -20,6 +20,10 @@ pub mod prelude;
2020pub mod tip5;
2121pub mod util_types;
2222
23+ #[ cfg( test) ]
24+ #[ cfg_attr( coverage_nightly, feature( coverage_attribute) ) ]
25+ mod proptest_arbitrary_interop;
26+
2327// This is needed for `#[derive(BFieldCodec)]` macro to work consistently across crates.
2428// Specifically:
2529// From inside the `twenty-first` crate, we need to refer to `twenty-first` by `crate`.
@@ -40,6 +44,64 @@ pub(crate) mod tests {
4044
4145 use super :: * ;
4246
47+ /// A crate-specific replacement of the `#[test]` attribute for tests that
48+ /// should also be executed on `wasm` targets (which is almost all tests).
49+ ///
50+ /// If you specifically want to exclude a test from `wasm` targets, use the
51+ /// usual `#[test]` attribute instead.
52+ ///
53+ /// # Usage
54+ ///
55+ /// ```
56+ /// #[macro_rules_attr::apply(test)]
57+ /// fn foo() {
58+ /// assert_eq!(4, 2 + 2);
59+ /// }
60+ /// ```
61+ macro_rules! test {
62+ ( $item: item) => {
63+ #[ test]
64+ #[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test:: wasm_bindgen_test) ]
65+ $item
66+ } ;
67+ }
68+ pub ( crate ) use test;
69+
70+ /// A crate-specific replacement of the `#[test_strategy::proptest]`
71+ /// attribute for tests that should also be executed on `wasm` targets
72+ /// (which is almost all tests).
73+ ///
74+ /// If you specifically want to exclude a test from `wasm` targets, use the
75+ /// usual `#[test_strategy::proptest]` attribute instead.
76+ ///
77+ /// # Usage
78+ ///
79+ /// ```
80+ /// # use proptest::prop_assert_eq;
81+ /// #[macro_rules_attr::apply(proptest)]
82+ /// fn foo(#[strategy(0..=42)] x: i32) {
83+ /// prop_assert_eq!(2 * x, x + x);
84+ /// }
85+ /// ```
86+ ///
87+ /// If you want to configure the test, use the usual syntax defined by
88+ /// [`test_strategy`]:
89+ /// ```
90+ /// # use proptest::prop_assert_eq;
91+ /// #[macro_rules_attr::apply(proptest(cases = 10, max_local_rejects = 5))]
92+ /// fn foo(#[strategy(0..=42)] x: i32) {
93+ /// prop_assert_eq!(2 * x, x + x);
94+ /// }
95+ /// ```
96+ macro_rules! proptest {
97+ ( $item: item $( ( $( $config: tt) * ) ) ?) => {
98+ #[ test_strategy:: proptest $( ( $( $config) * ) ) ?]
99+ #[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test:: wasm_bindgen_test) ]
100+ $item
101+ } ;
102+ }
103+ pub ( crate ) use proptest;
104+
43105 /// The compiler automatically adds any applicable auto trait (all of which are
44106 /// marker traits) to self-defined types. This implies that these trait bounds
45107 /// might vanish if the necessary pre-conditions are no longer met. That'd be a
@@ -55,7 +117,7 @@ pub(crate) mod tests {
55117 /// Inspired by “Rust for Rustaceans” by Jon Gjengset.
56118 pub fn implements_usual_auto_traits < T : Sized + Send + Sync + Unpin > ( ) { }
57119
58- #[ test]
120+ #[ macro_rules_attr :: apply ( test) ]
59121 fn types_in_prelude_implement_the_usual_auto_traits ( ) {
60122 implements_usual_auto_traits :: < BFieldElement > ( ) ;
61123 implements_usual_auto_traits :: < Polynomial < BFieldElement > > ( ) ;
@@ -68,7 +130,7 @@ pub(crate) mod tests {
68130 implements_usual_auto_traits :: < MmrMembershipProof > ( ) ;
69131 }
70132
71- #[ test]
133+ #[ macro_rules_attr :: apply ( test) ]
72134 fn public_types_implement_the_usual_auto_traits ( ) {
73135 implements_usual_auto_traits :: < math:: lattice:: CyclotomicRingElement > ( ) ;
74136 implements_usual_auto_traits :: < math:: lattice:: ModuleElement < 42 > > ( ) ;
@@ -85,7 +147,7 @@ pub(crate) mod tests {
85147 > ( ) ;
86148 }
87149
88- #[ test]
150+ #[ macro_rules_attr :: apply ( test) ]
89151 fn errors_implement_the_usual_auto_traits ( ) {
90152 implements_usual_auto_traits :: < error:: BFieldCodecError > ( ) ;
91153 implements_usual_auto_traits :: < error:: PolynomialBFieldCodecError > ( ) ;
0 commit comments