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

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

View as plain text