var pkgconfig coverage.CoverPkgConfig
-var outputfiles []string // set whe -pkgcfg is in use
+var outputfiles []string // set when -pkgcfg is in use
var profile string // The profile to read; the value of -html or -func
ppath := pkgconfig.PkgPath
filename := ppath + "/" + filepath.Base(fnpos.Filename)
+ // The convention for cmd/cover is that if the go command that
+ // kicks off coverage specifies a local import path (e.g. "go test
+ // -cover ./thispackage"), the tool will capture full pathnames
+ // for source files instead of relative paths, which tend to work
+ // more smoothly for "go tool cover -html". See also issue #56433
+ // for more details.
+ if pkgconfig.Local {
+ filename = f.name
+ }
+
// Hand off function to meta-data builder.
fd := coverage.FuncDesc{
Funcname: funcname,
// depending on user demand.
Granularity: "perblock",
OutConfig: p.Internal.CoverageCfg,
+ Local: p.Internal.Local,
}
if a.Package.Module != nil {
pcfg.ModulePath = a.Package.Module.Path
--- /dev/null
+
+[short] skip
+
+# collect coverage profile in text format
+go test -coverprofile=blah.prof prog.go prog_test.go
+
+# should not contain cmd-line pseudo-import-path
+grep prog.go blah.prof
+grep $PWD blah.prof
+! grep command-line-arguments blah.prof
+
+-- prog.go --
+package main
+
+func Mumble(x int) int {
+ if x < 0 {
+ return -x
+ }
+ return 42
+}
+
+func Grumble(y int) int {
+ return -y
+}
+
+func main() {
+}
+
+-- prog_test.go --
+package main
+
+import (
+ "testing"
+)
+
+func TestMumble(t *testing.T) {
+ if x := Mumble(10); x != 42 {
+ t.Errorf("Mumble(%d): got %d want %d", 10, x, 42)
+ }
+}
// Module path for this package (empty if no go.mod in use)
ModulePath string
+
+ // Local mode indicates we're doing a coverage build or test of a
+ // package selected via local import path, e.g. "./..." or
+ // "./foo/bar" as opposed to a non-relative import path. See the
+ // corresponding field in cmd/go's PackageInternal struct for more
+ // info.
+ Local bool
}
// CoverFixupConfig contains annotations/notes generated by the