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

fix(Unstructured)!: don't produce meaningless data if exhausted #108

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
tests: add test for unbounded recursion on exhaustion
Because the enum variant is decided based on an integer, and integers'
Arbitrary implementations always returned 0 if the Unstructured was
exhausted, an enum with a recursing first variant would lead to
unbounded recursion.
Xiretza committed Jun 9, 2022
commit 7bfd6847c3738104905174d2e9488375f7d82452
11 changes: 11 additions & 0 deletions tests/derive.rs
Original file line number Diff line number Diff line change
@@ -135,6 +135,17 @@ fn recursive() {
);
}

#[test]
fn recursive_first_variant() {
#[derive(PartialEq, Eq, Debug, Arbitrary)]
enum Nat {
Succ(Box<Nat>),
Zero,
}

assert!(Nat::arbitrary(&mut Unstructured::new(&[])).is_err());
}

#[derive(Arbitrary, Debug)]
struct Generic<T> {
inner: T,