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 -- go.mod --
42 module m
43
44 go 1.20
45 -- example/main.go --
46 package main
47
48 import (
49 "fmt"
50 "os"
51 "strings"
52 )
53
54 func 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 }
66
View as plain text