No public description PiperOrigin-RevId: 989650365
diff --git a/rust/e2e_tests/testdata/fuzz_tests.rs b/rust/e2e_tests/testdata/fuzz_tests.rs index 9b827a9..e2f9afd 100644 --- a/rust/e2e_tests/testdata/fuzz_tests.rs +++ b/rust/e2e_tests/testdata/fuzz_tests.rs
@@ -72,7 +72,7 @@ Ok(()) } - fn get_user_value<'a>( + fn corpus_to_user_value<'a>( &self, val: &'a Self::CorpusValue, ) -> anyhow::Result<Self::UserValue<'a>> { @@ -173,7 +173,7 @@ anyhow::bail!("Intentional mutate failure") } - fn get_user_value<'a>( + fn corpus_to_user_value<'a>( &self, val: &'a Self::CorpusValue, ) -> anyhow::Result<Self::UserValue<'a>> {
diff --git a/rust/fuzztest_macro/src/helpers/fuzztest_domain.rs b/rust/fuzztest_macro/src/helpers/fuzztest_domain.rs index 6cb6b58..5ee045d 100644 --- a/rust/fuzztest_macro/src/helpers/fuzztest_domain.rs +++ b/rust/fuzztest_macro/src/helpers/fuzztest_domain.rs
@@ -93,9 +93,9 @@ Ok(()) } - fn get_user_value<'a>(&self, corpus_value: &'a Self::CorpusValue) -> ::fuzztest::reexports::anyhow::Result<Self::UserValue<'a>> { + fn corpus_to_user_value<'a>(&self, corpus_value: &'a Self::CorpusValue) -> ::fuzztest::reexports::anyhow::Result<Self::UserValue<'a>> { Ok(#domain_struct_name { - #(#field_names: self.#field_names.get_user_value(&corpus_value.#field_names)?),* + #(#field_names: self.#field_names.corpus_to_user_value(&corpus_value.#field_names)?),* }) } } @@ -162,10 +162,10 @@ Ok(()) } - fn get_user_value<'a>(&self, corpus_value: &'a Self::CorpusValue) -> ::fuzztest::reexports::anyhow::Result<Self::UserValue<'a>> { + fn corpus_to_user_value<'a>(&self, corpus_value: &'a Self::CorpusValue) -> ::fuzztest::reexports::anyhow::Result<Self::UserValue<'a>> { Ok(__FuzzTestTestFuzzStateWrapper { - a: self.a.get_user_value(&corpus_value.a)?, - b: self.b.get_user_value(&corpus_value.b)? + a: self.a.corpus_to_user_value(&corpus_value.a)?, + b: self.b.corpus_to_user_value(&corpus_value.b)? }) } }
diff --git a/rust/fuzztest_macro/src/helpers/test_registration.rs b/rust/fuzztest_macro/src/helpers/test_registration.rs index 3806469..60e73f5 100644 --- a/rust/fuzztest_macro/src/helpers/test_registration.rs +++ b/rust/fuzztest_macro/src/helpers/test_registration.rs
@@ -44,7 +44,8 @@ } /// A context struct holding the pre-computed information and token streams required -/// to generate the fuzz test registration, struct definitions, and integration with the test framework. +/// to generate the fuzz test registration, struct definitions, and integration with the test +/// framework. /// /// This context is created once per property function. pub struct FuzzTestRegistrationCtx<'a> { @@ -60,7 +61,8 @@ } impl<'a> FuzzTestRegistrationCtx<'a> { - /// Creates a new registration context from a property function signature and its domain constructors. + /// Creates a new registration context from a property function signature and its domain + /// constructors. /// /// This method analyzes the inputs, derives necessary identifiers and lifetime generics, and /// pre-computes the tokenstream for the fuzz test struct instance. @@ -248,7 +250,7 @@ .downcast_ref::<#domain_struct_name<#(#corpus_generics),*>>() .expect("Attempt to recover user value before testing failed."); - let user_value = self.domain.get_user_value(wrapper).expect("Failed to get user value from corpus value"); + let user_value = self.domain.corpus_to_user_value(wrapper).expect("Failed to get user value from corpus value"); let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| (self.test_fn)(#(user_value.#fuzz_test_domain_field_names),* ) )); @@ -324,7 +326,7 @@ .downcast_ref::<__FuzzTestTestFuzzStateWrapper<T0::CorpusValue, T1::CorpusValue>>() .expect("Attempt to recover user value before testing failed."); - let user_value = self.domain.get_user_value(wrapper).expect("Failed to get user value from corpus value"); + let user_value = self.domain.corpus_to_user_value(wrapper).expect("Failed to get user value from corpus value"); // Safety: Data is not reused after the test. let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| (self.test_fn)(user_value.a, user_value.b) ));
diff --git a/rust/src/domains.rs b/rust/src/domains.rs index a873c59..550fa2f 100644 --- a/rust/src/domains.rs +++ b/rust/src/domains.rs
@@ -90,9 +90,9 @@ /// internal representation of the value and they are not directly usable by the fuzz property /// function. /// -/// The `get_user_value` method is used to retrieve the user value from the corpus value. For +/// The `corpus_to_user_value` method is used to retrieve the user value from the corpus value. For /// example, if the domain outputs an `&str` then the CorpusValue could be a `String` and the -/// `get_user_value` method would be used to retrieve the `&str` from the `String`. +/// `corpus_to_user_value` method would be used to retrieve the `&str` from the `String`. /// /// The `parse_corpus` (resp. `serialize_corpus`) method is used deserialize (resp. serialize) /// the corpus value from (to) a slice of bytes (resp. a vector of bytes). @@ -103,13 +103,13 @@ /// serialized representation of `CorpusValue`. Here's a quick overview: /// /// ```text -/// +-- get_user_value() <---+ +-- parse_corpus() <---+ -/// | | | | -/// v | v | -/// UserValue<'a> CorpusValue &[u8] -/// | ^ -/// | | -/// +-> serialize_corpus() + +/// +-- corpus_to_user_value() <---+ +-- parse_corpus() <---+ +/// | | | | +/// v | v | +/// UserValue<'a> CorpusValue &[u8] +/// | ^ +/// | | +/// +-> serialize_corpus() + /// ``` pub trait Domain { /// The type of the values that the domain outputs. This should of the same type as the @@ -136,14 +136,33 @@ only_shrink: bool, ) -> anyhow::Result<()>; + /// Deprecated alias of `corpus_to_user_value`. + /// + /// `get_user_value` and `corpus_to_user_value` have default implementations that delegate to + /// each other, so implementors can provide either one during the migration. Implementors + /// MUST override at least one of them; otherwise calling either will recurse infinitely. + #[deprecated(note = "Use `corpus_to_user_value` instead")] + fn get_user_value<'a>( + &self, + val: &'a Self::CorpusValue, + ) -> anyhow::Result<Self::UserValue<'a>> { + self.corpus_to_user_value(val) + } + /// Retrieves a UserValue from a given CorpusValue. /// /// This is used to convert the corpus value into the user value that can then be passed to the /// fuzz property function. - fn get_user_value<'a>( + /// + /// The default implementation delegates to the deprecated `get_user_value` for backwards + /// compatibility. New implementors should override this method instead. + fn corpus_to_user_value<'a>( &self, corpus_value: &'a Self::CorpusValue, - ) -> anyhow::Result<Self::UserValue<'a>>; + ) -> anyhow::Result<Self::UserValue<'a>> { + #[allow(deprecated)] + self.get_user_value(corpus_value) + } /// Turns a slice of bytes into `CorpusValue`. ///
diff --git a/rust/src/domains/arbitrary.rs b/rust/src/domains/arbitrary.rs index e2167bf..303d751 100644 --- a/rust/src/domains/arbitrary.rs +++ b/rust/src/domains/arbitrary.rs
@@ -95,7 +95,7 @@ Ok(()) } - fn get_user_value<'a>( + fn corpus_to_user_value<'a>( &self, corpus_value: &'a Self::CorpusValue, ) -> anyhow::Result<Self::UserValue<'a>> { @@ -138,7 +138,7 @@ Ok(()) } - fn get_user_value<'a>( + fn corpus_to_user_value<'a>( &self, corpus_value: &'a Self::CorpusValue, ) -> anyhow::Result<Self::UserValue<'a>> { @@ -209,7 +209,7 @@ Ok(()) } - fn get_user_value<'a>( + fn corpus_to_user_value<'a>( &self, corpus_value: &'a Self::CorpusValue, ) -> anyhow::Result<Self::UserValue<'a>> { @@ -294,7 +294,7 @@ Ok(()) } - fn get_user_value<'a>( + fn corpus_to_user_value<'a>( &self, corpus_value: &'a Self::CorpusValue, ) -> anyhow::Result<Self::UserValue<'a>> { @@ -320,7 +320,7 @@ Ok(()) } - fn get_user_value<'a>( + fn corpus_to_user_value<'a>( &self, _corpus_value: &'a Self::CorpusValue, ) -> anyhow::Result<Self::UserValue<'a>> { @@ -492,7 +492,8 @@ domain.mutate(&mut value, &mut rng, true).unwrap(); if value.is_at_shrink_target() { - // Ensure that once the shrink target is reached, further shrinking doesn't change it. + // Ensure that once the shrink target is reached, further shrinking doesn't change + // it. domain.mutate(&mut value, &mut rng, true).unwrap(); assert!( value.is_at_shrink_target(),
diff --git a/rust/src/domains/containers.rs b/rust/src/domains/containers.rs index a15e28c..30bc1e9 100644 --- a/rust/src/domains/containers.rs +++ b/rust/src/domains/containers.rs
@@ -183,13 +183,13 @@ Ok(()) } - fn get_user_value<'a>( + fn corpus_to_user_value<'a>( &self, corpus_value: &'a Self::CorpusValue, ) -> anyhow::Result<Self::UserValue<'a>> { let mut user_values = Vec::with_capacity(corpus_value.len()); for item in corpus_value { - user_values.push(self.inner.get_user_value(item)?); + user_values.push(self.inner.corpus_to_user_value(item)?); } Ok(user_values) } @@ -427,10 +427,10 @@ } #[gtest] - fn test_vec_of_get_user_value() { + fn test_vec_of_corpus_to_user_value() { let domain = VecOf::new(Arbitrary::<u32>::default()); let corpus_val = vec![1u32, 2u32, 3u32]; - let user_val = domain.get_user_value(&corpus_val).unwrap(); + let user_val = domain.corpus_to_user_value(&corpus_val).unwrap(); expect_that!(user_val, container_eq(vec![1u32, 2u32, 3u32])); } }
diff --git a/rust/src/domains/range.rs b/rust/src/domains/range.rs index 3bf413b..1794146 100644 --- a/rust/src/domains/range.rs +++ b/rust/src/domains/range.rs
@@ -75,7 +75,7 @@ Ok(()) } - fn get_user_value<'a>( + fn corpus_to_user_value<'a>( &self, corpus_value: &'a Self::CorpusValue, ) -> anyhow::Result<Self::UserValue<'a>> {