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

min/max fields are not always applied #1

Open
sadeli413 opened this issue May 13, 2024 · 0 comments
Open

min/max fields are not always applied #1

sadeli413 opened this issue May 13, 2024 · 0 comments

Comments

@sadeli413
Copy link

On initialization, the min or max derives do not necessarily work. They don't work on mutation either, which is a related but separate issue.

use lain::prelude::*;
use lain::rand;

#[derive(Debug, Mutatable, NewFuzzed, BinarySerialize)]
struct MyStruct {
    #[lain(min = 5, max = 7)]
    field_1: u32,

    #[lain(min = 5, max = 7)]
    field_2: Vec<u8>,
}

fn main() {
    // Min/max does not necessarily work on initialization
    for _ in 0..1000 {
        let mut mutator = Mutator::new(rand::thread_rng());
        let instance = MyStruct::new_fuzzed(&mut mutator, None);

        assert!((5..7).contains(&instance.field_1), "Got invalid field_1 value {}", instance.field_1);
        assert!((5..7).contains(&instance.field_2.len()), "Got invalid field_2 length {}", instance.field_2.len());
    }
}
    Finished release [optimized] target(s) in 0.22s
     Running `target/release/tmp_vendor`
thread 'main' panicked at src/main.rs:20:9:
Got invalid field_1 value 3141465631
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant