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

     1  [short] skip
     2  
     3  go test flag_test.go -v -args -v=7 # Two distinct -v flags
     4  go test -v flag_test.go -args -v=7 # Two distinct -v flags
     5  
     6  # Using a custom flag mixed with regular 'go test' flags should be OK.
     7  go test -count=1 -custom -args -v=7
     8  
     9  # However, it should be an error to use custom flags when -i or -c are used,
    10  # since we know for sure that no test binary will run at all.
    11  ! go test -i -custom
    12  stderr '^go: unknown flag -custom cannot be used with -i$'
    13  ! go test -c -custom
    14  stderr '^go: unknown flag -custom cannot be used with -c$'
    15  
    16  # The same should apply even if -c or -i come after a custom flag.
    17  ! go test -custom -c
    18  stderr '^go: unknown flag -custom cannot be used with -c$'
    19  
    20  -- go.mod --
    21  module m
    22  -- flag_test.go --
    23  package flag_test
    24  
    25  import (
    26  	"flag"
    27  	"log"
    28  	"testing"
    29  )
    30  
    31  var v = flag.Int("v", 0, "v flag")
    32  
    33  var custom = flag.Bool("custom", false, "")
    34  
    35  // Run this as go test pkg -v=7
    36  func TestVFlagIsSet(t *testing.T) {
    37  	if *v != 7 {
    38  		log.Fatal("v flag not set")
    39  	}
    40  }
    41  

View as plain text