...

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

Documentation: cmd/go/testdata/script

     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
     8env GOBIN=$WORK/bin
     9
    10# Install a target and then do an ordinary staleness check on it.
    11go 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.
    17stale -cover m/example
    18
    19# Collect build ID from for m/example built with -cover.
    20go list -cover -export -f '{{.BuildID}}' m/example
    21cp stdout $WORK/listbuildid.txt
    22
    23# Now build the m/example binary with coverage.
    24go build -cover -o $WORK/m.exe m/example
    25
    26# Ask for the binary build ID by running "go tool buildid".
    27go tool buildid $WORK/m.exe
    28cp 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.
    34env GOCOVERDIR=$WORK
    35exec $WORK/m.exe $WORK/rawtoolbuildid.txt
    36cp stdout $WORK/toolbuildid.txt
    37
    38# Build IDs should match here.
    39cmp $WORK/toolbuildid.txt $WORK/listbuildid.txt
    40
    41-- go.mod --
    42module m
    43
    44go 1.20
    45-- example/main.go --
    46package main
    47
    48import (
    49	"fmt"
    50	"os"
    51	"strings"
    52)
    53
    54func main() {
    55	println(os.Args[1])
    56	content, err := os.ReadFile(os.Args[1])
    57	if err != nil {
    58		os.Exit(1)
    59	}
    60	fields := strings.Split(strings.TrimSpace(string(content)), "/")
    61	if len(fields) != 4 {
    62		os.Exit(2)
    63	}
    64	fmt.Println(fields[1] + "/" + fields[2])
    65}

View as plain text