github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/standalone_testmain_flag_test.go (about) 1 // Copyright 2019 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 standalone_testmain_flag_test 6 7 import ( 8 "flag" 9 "fmt" 10 "os" 11 "testing" 12 ) 13 14 func TestMain(m *testing.M) { 15 // A TestMain should be able to access testing flags if it calls 16 // flag.Parse without needing to use testing.Init. 17 flag.Parse() 18 found := false 19 flag.VisitAll(func(f *flag.Flag) { 20 if f.Name == "test.count" { 21 found = true 22 } 23 }) 24 if !found { 25 fmt.Println("testing flags not registered") 26 os.Exit(1) 27 } 28 os.Exit(m.Run()) 29 }