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

View as plain text