Home > Back-end >  how to run multi fuzz test cases wirtten in one source file with go1.18?
how to run multi fuzz test cases wirtten in one source file with go1.18?

Time:03-26

go 1.18 has released serveral days ago.It supports fuzzing in its standard toolchain beginning in Go 1.18

but while i'm trying to write my cases , it can not run multi cases in one package(or one file?). code:

package xxx
func FuzzReverse(f *testing.F) {
    testcases := []string{"Hello, world", " ", "!12345"}
    for _, tc := range testcases {
        f.Add(tc) // Use f.Add to provide a seed corpus
    }
    f.Fuzz(func(t *testing.T, orig string) {
        Reverse(orig)
    })
}

func FuzzReverse2(f *testing.F) {
    testcases := []string{"Hello, world", " ", "!12345"}
    for _, tc := range testcases {
        f.Add(tc) // Use f.Add to provide a seed corpus
    }
    f.Fuzz(func(t *testing.T, orig string) {
        Reverse(orig)
    })
}

and i run cmd:

go test  -fuzz .

or

go test  -fuzz=Fuzz

but the result is:

testing: will not fuzz, -fuzz matches more than one fuzz test: [FuzzReverse FuzzReverse2]

like this: enter image description here

the tutorial didn't tips about it, thx for help.(my first question in stackoverflow, thx a lot!!!!)

I try to wirte multi fuzz cases in one source file,then run cmd: go test -fuzz . expecting it work fuzz-testing,but got an error:\

testing: will not fuzz, -fuzz matches more than one fuzz test: [FuzzReverse FuzzReverse2]

CodePudding user response:

all right,I've read the source of Go-fuzz module, it's a fact that it not support multi cases for each execution.

code in :\Go\src\testing\fuzz.go

if len(matched) > 1 {
    fmt.Fprintf(os.Stderr, "testing: will not fuzz, -fuzz matches more than one fuzz test: %v\n", matched)
    return false
}

I hope that multi cases execution could be supported in the future.

  • Related