github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/go/test/internal/genflags/testflag.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package genflags
     6  
     7  import (
     8  	"flag"
     9  	"strings"
    10  	"testing"
    11  )
    12  
    13  // ShortTestFlags returns the set of "-test." flag shorthand names that end
    14  // users may pass to 'go test'.
    15  func ShortTestFlags() []string {
    16  	testing.Init()
    17  
    18  	var names []string
    19  	flag.VisitAll(func(f *flag.Flag) {
    20  		var name string
    21  		var found bool
    22  		if name, found = strings.CutPrefix(f.Name, "test."); !found {
    23  			return
    24  		}
    25  
    26  		switch name {
    27  		case "testlogfile", "paniconexit0", "fuzzcachedir", "fuzzworker", "gocoverdir":
    28  			// These flags are only for use by cmd/go.
    29  		default:
    30  			names = append(names, name)
    31  		}
    32  	})
    33  
    34  	return names
    35  }