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

     1  
     2  # This test is intended to verify that "go list" accepts coverage related
     3  # build arguments (such as -cover, -covermode). See issue #57785.
     4  
     5  [short] skip
     6  
     7  env GOBIN=$WORK/bin
     8  
     9  # Install a target and then do an ordinary staleness check on it.
    10  go install m/example
    11  ! stale m/example
    12  
    13  # Run a second staleness check with "-cover" as a build flag. The
    14  # installed target should indeed be stale, since we didn't build it
    15  # with -cover.
    16  stale -cover m/example
    17  
    18  # Collect build ID from for m/example built with -cover.
    19  go list -cover -export -f '{{.BuildID}}' m/example
    20  cp stdout $WORK/listbuildid.txt
    21  
    22  # Now build the m/example binary with coverage.
    23  go build -cover -o $WORK/m.exe m/example
    24  
    25  # Ask for the binary build ID by running "go tool buildid".
    26  go tool buildid $WORK/m.exe
    27  cp stdout $WORK/rawtoolbuildid.txt
    28  
    29  # Make sure that the two build IDs agree with respect to the
    30  # m/example package. Build IDs from binaries are of the form X/Y/Z/W
    31  # where Y/Z is the package build ID; running the program below will
    32  # pick out the parts of the ID that we want.
    33  env GOCOVERDIR=$WORK
    34  exec $WORK/m.exe $WORK/rawtoolbuildid.txt
    35  cp stdout $WORK/toolbuildid.txt
    36  
    37  # Build IDs should match here.
    38  cmp $WORK/toolbuildid.txt $WORK/listbuildid.txt
    39  
    40  # Make sure that the build succeeds regardless of covermode.
    41  go list -export -covermode=atomic m/example
    42  go list -export -covermode=count m/example
    43  
    44  -- go.mod --
    45  module m
    46  
    47  go 1.20
    48  -- example/main.go --
    49  package main
    50  
    51  import (
    52  	"fmt"
    53  	"os"
    54  	"strings"
    55  )
    56  
    57  func main() {
    58  	println(os.Args[1])
    59  	content, err := os.ReadFile(os.Args[1])
    60  	if err != nil {
    61  		os.Exit(1)
    62  	}
    63  	fields := strings.Split(strings.TrimSpace(string(content)), "/")
    64  	if len(fields) != 4 {
    65  		os.Exit(2)
    66  	}
    67  	fmt.Println(fields[1] + "/" + fields[2])
    68  }
    69  

View as plain text