...

Text file src/cmd/go/testdata/script/test_fuzz_mutate_fail.txt

Documentation: cmd/go/testdata/script

     1[!fuzz] skip
     2
     3# Check that if a worker does not call F.Fuzz or calls F.Fail first,
     4# 'go test' exits non-zero and no crasher is recorded.
     5
     6[short] skip
     7env GOCACHE=$WORK/cache
     8
     9! go test -fuzz=FuzzReturn
    10! exists testdata
    11
    12! go test -fuzz=FuzzSkip
    13! exists testdata
    14
    15! go test -fuzz=FuzzFail
    16! exists testdata
    17
    18! go test -fuzz=FuzzPanic
    19! exists testdata
    20
    21! go test -fuzz=FuzzNilPanic
    22! exists testdata
    23
    24! go test -fuzz=FuzzGoexit
    25! exists testdata
    26
    27! go test -fuzz=FuzzExit
    28! exists testdata
    29
    30-- go.mod --
    31module m
    32
    33go 1.17
    34-- fuzz_fail_test.go --
    35package fuzz_fail
    36
    37import (
    38	"flag"
    39	"os"
    40	"runtime"
    41	"testing"
    42)
    43
    44func isWorker() bool {
    45	f := flag.Lookup("test.fuzzworker")
    46	if f == nil {
    47		return false
    48	}
    49	get, ok := f.Value.(flag.Getter)
    50	if !ok {
    51		return false
    52	}
    53	return get.Get() == interface{}(true)
    54}
    55
    56func FuzzReturn(f *testing.F) {
    57	if isWorker() {
    58		return
    59	}
    60	f.Fuzz(func(*testing.T, []byte) {})
    61}
    62
    63func FuzzSkip(f *testing.F) {
    64	if isWorker() {
    65		f.Skip()
    66	}
    67	f.Fuzz(func(*testing.T, []byte) {})
    68}
    69
    70func FuzzFail(f *testing.F) {
    71	if isWorker() {
    72		f.Fail()
    73	}
    74	f.Fuzz(func(*testing.T, []byte) {})
    75}
    76
    77func FuzzPanic(f *testing.F) {
    78	if isWorker() {
    79		panic("nope")
    80	}
    81	f.Fuzz(func(*testing.T, []byte) {})
    82}
    83
    84func FuzzNilPanic(f *testing.F) {
    85	if isWorker() {
    86		panic(nil)
    87	}
    88	f.Fuzz(func(*testing.T, []byte) {})
    89}
    90
    91func FuzzGoexit(f *testing.F) {
    92	if isWorker() {
    93		runtime.Goexit()
    94	}
    95	f.Fuzz(func(*testing.T, []byte) {})
    96}
    97
    98func FuzzExit(f *testing.F) {
    99	if isWorker() {
   100		os.Exit(99)
   101	}
   102	f.Fuzz(func(*testing.T, []byte) {})
   103}

View as plain text