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

feat(bolero-generator): add trace utility #240

Merged
merged 2 commits into from
Jul 2, 2024
Merged

feat(bolero-generator): add trace utility #240

merged 2 commits into from
Jul 2, 2024

Conversation

camshaft
Copy link
Owner

@camshaft camshaft commented Jul 2, 2024

This change adds a utility to bolero-generator for tracing/debugging generated inputs. This can be enabled on any type that implements ValueGenerator:

#[derive(Debug, TypeGenerator)]
struct MyType {
    field: u8,
}

check!().with_generator(gen::<MyType>().trace()).for_each(|_| { });

Running this will write all of the generated values to stderr:

product MyType {
    u8 -> 23
}
product MyType {
    u8 -> 23
}
product MyType {
    u8 -> 242
}
product MyType {
    u8 -> 242
}
product MyType {
    u8 -> 139
}
product MyType {
    u8 -> 139
}
product MyType {
    u8 -> 137
}
product MyType {
    u8 -> 137
}
product MyType {
    u8 -> 164
}
product MyType {
    u8 -> 164
}
...

It will also log any values that failed to return Some from generate:

sum EvenTree {
    variant Pair {
        sum EvenTree {
            variant Leaf {
                product Even {
                    u8 -> 74
                }
            }
        }
        sum EvenTree {
            variant Leaf {
                product Even {
                    u8 -> 137
                } -> <None>
            } -> <None>
        } -> <None>
    } -> <None>
} -> <None>
sum EvenTree {
    variant Leaf {
        product Even {
            u8 -> 10
        }
    }
}
sum EvenTree {
    variant Leaf {
        product Even {
            u8 -> 10
        }
    }
}
sum EvenTree {
    variant Pair {
        sum EvenTree {
            variant Leaf {
                product Even {
                    u8 -> 74
                }
            }
        }
        sum EvenTree {
            variant Leaf {
                product Even {
                    u8 -> 60
                }
            }
        }
    }
}

@camshaft camshaft marked this pull request as ready for review July 2, 2024 21:55
@camshaft camshaft merged commit 429a416 into master Jul 2, 2024
9 checks passed
@camshaft camshaft deleted the gen-trace branch July 2, 2024 21:56
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

Successfully merging this pull request may close these issues.

1 participant