...

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# Make sure that the build succeeds regardless of covermode.
    42go list -export -covermode=atomic m/example
    43go list -export -covermode=count m/example
    44
    45-- go.mod --
    46module m
    47
    48go 1.20
    49-- example/main.go --
    50package main
    51
    52import (
    53	"fmt"
    54	"os"
    55	"strings"
    56)
    57
    58func 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}

View as plain text