! stdout 'no targets to fuzz'
# Matches more than one fuzz target for fuzzing.
-go test -fuzz Fuzz -fuzztime 1x multiple_fuzz_test.go
-# The tests should run, but not be fuzzed
+! go test -fuzz Fuzz -fuzztime 1x multiple_fuzz_test.go
! stdout 'no tests to run'
! stdout 'no targets to fuzz'
-stdout ok
+stdout FAIL
stdout 'will not fuzz, -fuzz matches more than one target'
-- standalone_fuzz_test.go --
//
// If fuzzing is disabled (-test.fuzz is not set), runFuzzing
// returns immediately.
-func runFuzzing(deps testDeps, fuzzTargets []InternalFuzzTarget) (ran bool, matched int, ok bool) {
+func runFuzzing(deps testDeps, fuzzTargets []InternalFuzzTarget) (ok bool) {
// TODO(katiehockman,jayconrod): Should we do something special to make sure
// we don't print f.Log statements again with runFuzzing, since we already
// would have printed them when we ran runFuzzTargets (ie. seed corpus run)?
if len(fuzzTargets) == 0 || *matchFuzz == "" {
- return false, 0, true
+ return true
}
m := newMatcher(deps.MatchString, *matchFuzz, "-test.fuzz")
tctx := newTestContext(1, m)
}
var target *InternalFuzzTarget
var targetName string
+ var matched []string
for i := range fuzzTargets {
name, ok, _ := tctx.match.fullName(nil, fuzzTargets[i].Name)
if !ok {
continue
}
- matched++
+ matched = append(matched, name)
target = &fuzzTargets[i]
targetName = name
}
- if matched != 1 {
- return false, matched, true
+ if len(matched) == 0 {
+ fmt.Fprintln(os.Stderr, "testing: warning: no targets to fuzz")
+ return true
+ }
+ if len(matched) > 1 {
+ fmt.Fprintf(os.Stderr, "testing: will not fuzz, -fuzz matches more than one target: %v\n", matched)
+ return false
}
f := &F{
}
go fRunner(f, target.Fn)
<-f.signal
- return f.ran, matched, !f.failed
+ return !f.failed
}
// fRunner wraps a call to a fuzz target and ensures that cleanup functions are
}
}
- fuzzingRan, fuzzingMatched, fuzzingOk := runFuzzing(m.deps, m.fuzzTargets)
- if *matchFuzz != "" && !fuzzingRan {
- if fuzzingMatched == 0 {
- fmt.Fprintln(os.Stderr, "testing: warning: no targets to fuzz")
- } else {
- fmt.Fprintln(os.Stderr, "testing: warning: will not fuzz, -fuzz matches more than one target")
- }
- }
+ fuzzingOk := runFuzzing(m.deps, m.fuzzTargets)
if !*isFuzzWorker && !fuzzingOk {
fmt.Println("FAIL")
if *isFuzzWorker {