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 -c is used,
    10  # since we know for sure that no test binary will run at all.
    11  ! go test -c -custom
    12  stderr '^go: unknown flag -custom cannot be used with -c$'
    13  
    14  # The same should apply even if -c comes after a custom flag.
    15  ! go test -custom -c
    16  stderr '^go: unknown flag -custom cannot be used with -c$'
    17  
    18  -- go.mod --
    19  module m
    20  -- flag_test.go --
    21  package flag_test
    22  
    23  import (
    24  	"flag"
    25  	"log"
    26  	"testing"
    27  )
    28  
    29  var v = flag.Int("v", 0, "v flag")
    30  
    31  var custom = flag.Bool("custom", false, "")
    32  
    33  // Run this as go test pkg -v=7
    34  func TestVFlagIsSet(t *testing.T) {
    35  	if *v != 7 {
    36  		log.Fatal("v flag not set")
    37  	}
    38  }
    39  

View as plain text