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

     1  [!fuzz] skip
     2  [short] skip
     3  env GOCACHE=$WORK/cache
     4  
     5  # The fuzz function should be able to detect whether -timeout
     6  # was set with T.Deadline. Note there is no F.Deadline, and
     7  # there is no timeout while fuzzing, even if -fuzztime is set.
     8  go test -run=FuzzDeadline -wantdeadline=true # -timeout defaults to 10m
     9  go test -run=FuzzDeadline -timeout=0 -wantdeadline=false
    10  ! go test -run=FuzzDeadline -timeout=1s -wantdeadline=false
    11  go test -run=FuzzDeadline -timeout=1s -wantdeadline=true
    12  go test -fuzz=FuzzDeadline -timeout=0 -fuzztime=1s -wantdeadline=false
    13  go test -fuzz=FuzzDeadline -timeout=0 -fuzztime=100x -wantdeadline=false
    14  
    15  -- go.mod --
    16  module fuzz
    17  
    18  go 1.16
    19  -- fuzz_deadline_test.go --
    20  package fuzz_test
    21  
    22  import (
    23  	"flag"
    24  	"testing"
    25  )
    26  
    27  var wantDeadline = flag.Bool("wantdeadline", false, "whether the test should have a deadline")
    28  
    29  func FuzzDeadline(f *testing.F) {
    30  	f.Add("run once")
    31  	f.Fuzz(func (t *testing.T, _ string) {
    32  		if _, hasDeadline := t.Deadline(); hasDeadline != *wantDeadline {
    33  			t.Fatalf("function got %v; want %v", hasDeadline, *wantDeadline)
    34  		}
    35  	})
    36  }
    37  

View as plain text