...
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.
10go tool compile -p tiny tiny/tiny.go tiny/tiny2.go
11
12# Build a stdlib command with coverage.
13go build -o $WORK/nm.exe -cover cmd/nm
14
15# Save off old GOCOVERDIR setting
16env SAVEGOCOVERDIR=$GOCOVERDIR
17
18# Collect a coverage profile from running 'cmd/nm' on the object.
19mkdir $WORK/covdata
20env GOCOVERDIR=$WORK/covdata
21exec $WORK/nm.exe tiny.o
22
23# Restore previous GOCOVERDIR setting
24env GOCOVERDIR=$SAVEGOCOVERDIR
25
26# Check to make sure we instrumented just the main package, not
27# any dependencies.
28go tool covdata pkglist -i=$WORK/covdata
29stdout 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.
34go build -cover -o $WORK/another.exe testdata/another.go
35mkdir $WORK/covdata2
36env GOCOVERDIR=$WORK/covdata2
37exec $WORK/another.exe
38
39# Restore previous GOCOVERDIR setting
40env GOCOVERDIR=$SAVEGOCOVERDIR
41
42# Check to make sure we instrumented just the main package.
43go tool covdata pkglist -i=$WORK/covdata2
44stdout command-line-arguments
45! stdout fmt
46
47-- go.mod --
48
49module example.prog
50
51-- testdata/another.go --
52
53package main
54
55import "fmt"
56
57func main() {
58 fmt.Println("Hi dad")
59}
60
61-- tiny/tiny.go --
62
63package tiny
64
65var Tvar int
66
67-- tiny/tiny2.go --
68
69package tiny
70
71var Tvar2 bool
72
View as plain text