| 1 |
|
| 2 |
# This test is intended to verify that when a user does "go run -cover ..." |
| 3 |
# or "go build -cover ...", packages named on the command line are |
| 4 |
# always instrumented (but not their dependencies). This rule applies |
| 5 |
# inside and outside the standard library. |
| 6 |
|
| 7 |
[short] skip |
| 8 |
|
| 9 |
# Compile an object. |
| 10 |
go tool compile -p tiny tiny/tiny.go tiny/tiny2.go |
| 11 |
|
| 12 |
# Build a stdlib command with coverage. |
| 13 |
go build -o $WORK/nm.exe -cover cmd/nm |
| 14 |
|
| 15 |
# Save off old GOCOVERDIR setting |
| 16 |
env SAVEGOCOVERDIR=$GOCOVERDIR |
| 17 |
|
| 18 |
# Collect a coverage profile from running 'cmd/nm' on the object. |
| 19 |
mkdir $WORK/covdata |
| 20 |
env GOCOVERDIR=$WORK/covdata |
| 21 |
exec $WORK/nm.exe tiny.o |
| 22 |
|
| 23 |
# Restore previous GOCOVERDIR setting |
| 24 |
env GOCOVERDIR=$SAVEGOCOVERDIR |
| 25 |
|
| 26 |
# Check to make sure we instrumented just the main package, not |
| 27 |
# any dependencies. |
| 28 |
go tool covdata pkglist -i=$WORK/covdata |
| 29 |
stdout cmd/nm |
| 30 |
! stdout cmd/internal/goobj pkglist.txt |
| 31 |
|
| 32 |
# ... now collect a coverage profile from a Go file |
| 33 |
# listed on the command line. |
| 34 |
go build -cover -o $WORK/another.exe testdata/another.go |
| 35 |
mkdir $WORK/covdata2 |
| 36 |
env GOCOVERDIR=$WORK/covdata2 |
| 37 |
exec $WORK/another.exe |
| 38 |
|
| 39 |
# Restore previous GOCOVERDIR setting |
| 40 |
env GOCOVERDIR=$SAVEGOCOVERDIR |
| 41 |
|
| 42 |
# Check to make sure we instrumented just the main package. |
| 43 |
go tool covdata pkglist -i=$WORK/covdata2 |
| 44 |
stdout command-line-arguments |
| 45 |
! stdout fmt |
| 46 |
|
| 47 |
-- go.mod -- |
| 48 |
|
| 49 |
module example.prog |
| 50 |
|
| 51 |
-- testdata/another.go -- |
| 52 |
|
| 53 |
package main |
| 54 |
|
| 55 |
import "fmt" |
| 56 |
|
| 57 |
func main() { |
| 58 |
fmt.Println("Hi dad") |
| 59 |
} |
| 60 |
|
| 61 |
-- tiny/tiny.go -- |
| 62 |
|
| 63 |
package tiny |
| 64 |
|
| 65 |
var Tvar int |
| 66 |
|
| 67 |
-- tiny/tiny2.go -- |
| 68 |
|
| 69 |
package tiny |
| 70 |
|
| 71 |
var Tvar2 bool |
| 72 |
|