goreduce
Reduce a program to its simplest form as long as it produces a compiler
error or any output (such as a panic) matching a regular expression.
go get -u mvdan.cc/goreduce
Example
func main() {
a := []int{1, 2, 3}
if true {
a = append(a, 4)
}
a[1] = -2
println(a[10])
}
goreduce -match 'index out of range' .
func main() {
a := []int{}
println(a[0])
}
For more usage information, see goreduce -h
.
Design
- The tool should be reproducible, giving the same output for an input
program as long as external factors don't modify its behavior - The rules should be as simple and composable as possible
- Rules should avoid generating changes that they can know won't compile