Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect ignored fields for mutatable structs #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lain_derive/src/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,16 @@ fn mutatable_enum_visitor(variants: &[Variant], cont_ident: &syn::Ident) -> Vec<
fn mutatable_struct_visitor(fields: &[Field]) -> Vec<TokenStream> {
fields
.iter()
.map(|field| {
.filter_map(|field| {
if field.attrs.ignore() {
return None;
}
let (_field_ident, _field_ident_string, initializer) =
field_mutator(field, "self.", false);

quote! {
Some(quote! {
#initializer
}
})
})
.collect()
}
Expand Down
7 changes: 5 additions & 2 deletions testsuite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,20 @@ mod test {

#[test]
fn test_ignored_fields() {
#[derive(NewFuzzed, BinarySerialize, Clone)]
#[derive(NewFuzzed, BinarySerialize, Clone, Mutatable)]
struct IgnoredFieldsStruct {
#[lain(ignore)]
ignored: u8,
}

let mut mutator = get_mutator();

let initialized_struct = IgnoredFieldsStruct::new_fuzzed(&mut mutator, None);
let mut initialized_struct = IgnoredFieldsStruct::new_fuzzed(&mut mutator, None);

assert_eq!(initialized_struct.ignored, 0);

initialized_struct.mutate(&mut mutator, None);
assert_eq!(initialized_struct.ignored, 0);
}

#[test]
Expand Down