...

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
     7env GOBIN=$WORK/bin
     8
     9# Install a target and then do an ordinary staleness check on it.
    10go 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.
    16stale -cover m/example
    17
    18# Collect build ID from for m/example built with -cover.
    19go list -cover -export -f '{{.BuildID}}' m/example
    20cp stdout $WORK/listbuildid.txt
    21
    22# Now build the m/example binary with coverage.
    23go build -cover -o $WORK/m.exe m/example
    24
    25# Ask for the binary build ID by running "go tool buildid".
    26go tool buildid $WORK/m.exe
    27cp 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.
    33env GOCOVERDIR=$WORK
    34exec $WORK/m.exe $WORK/rawtoolbuildid.txt
    35cp stdout $WORK/toolbuildid.txt
    36
    37# Build IDs should match here.
    38cmp $WORK/toolbuildid.txt $WORK/listbuildid.txt
    39
    40# Make sure that the build succeeds regardless of covermode.
    41go list -export -covermode=atomic m/example
    42go list -export -covermode=count m/example
    43
    44-- go.mod --
    45module m
    46
    47go 1.20
    48-- example/main.go --
    49package main
    50
    51import (
    52	"fmt"
    53	"os"
    54	"strings"
    55)
    56
    57func 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}

View as plain text