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

View as plain text