github.com/please-build/go-rules/tools/please_go@v0.0.0-20240319165128-ea27d6f5caba/covervars/cover_vars.go (about) 1 package covervars 2 3 import ( 4 "fmt" 5 "io" 6 "log" 7 "path/filepath" 8 "strings" 9 ) 10 11 // GenCoverVars writes the coverage variable information to w 12 func GenCoverVars(w io.Writer, importPath string, srcs []string) { 13 for _, src := range srcs { 14 if _, err := w.Write([]byte(coverVar(src, importPath))); err != nil { 15 log.Fatalf("%v", err) 16 } 17 } 18 } 19 20 func coverVar(src, importPath string) string { 21 baseName := filepath.Base(src) 22 varname := strings.ReplaceAll(baseName, ".", "_") 23 varname = strings.ReplaceAll(varname, "-", "_") 24 return fmt.Sprintf("%s=GoCover_%s\n", importPath, varname) 25 }