...

Text file src/cmd/go/testdata/script/cover_build_cmdline_pkgs.txt

Documentation: cmd/go/testdata/script

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

View as plain text