camshaft / bolero

property testing and verification front-end for Rust
https://camshaft.github.io/bolero
MIT License
185 stars 17 forks source link

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

Closed camshaft closed 4 months ago

camshaft commented 4 months ago

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
                }
            }
        }
    }
}