github.com/please-build/go-rules/tools/please_go@v0.0.0-20240319165128-ea27d6f5caba/test/gotest.go (about) 1 package test 2 3 import ( 4 "log" 5 6 "github.com/please-build/go-rules/tools/please_go/install/toolchain" 7 ) 8 9 // PleaseGoTest will generate the test main for the provided sources 10 func PleaseGoTest(goTool, dir, testPackage, output string, sources, exclude []string, isBenchmark, external bool) { 11 tc := toolchain.Toolchain{GoTool: goTool} 12 minor, err := tc.GoMinorVersion() 13 if err != nil { 14 log.Fatalf("Failed to determine Go version: %s", err) 15 } 16 if minor >= 20 { 17 if err := WriteTestMain(testPackage, sources, output, dir != "", nil, isBenchmark, true, true); err != nil { 18 log.Fatalf("Error writing test main: %s", err) 19 } 20 return 21 } 22 coverVars, err := FindCoverVars(dir, testPackage, external, exclude) 23 if err != nil { 24 log.Fatalf("Error scanning for coverage: %s", err) 25 } 26 if err := WriteTestMain(testPackage, sources, output, dir != "", coverVars, isBenchmark, minor >= 18, false); err != nil { 27 log.Fatalf("Error writing test main: %s", err) 28 } 29 }