...

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

Documentation: cmd/go/testdata/script

     1# Without -coverpkg, we should get the same value for a given
     2# package regardless of how many other packages are selected
     3# (see issue 65570).
     4
     5[short] skip
     6
     7go test -count=1 -cover ./a ./b ./main
     8stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements'
     9go test -count=1 -cover ./main
    10stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements'
    11
    12-- go.mod --
    13module M
    14
    15go 1.21
    16-- a/a.go --
    17package a
    18
    19func AFunc() int {
    20	return 42
    21}
    22-- b/b.go --
    23package b
    24
    25func BFunc() int {
    26	return -42
    27}
    28-- main/main.go --
    29package main
    30
    31import (
    32	"M/a"
    33)
    34
    35func MFunc() string {
    36	return "42"
    37}
    38
    39func M2Func() int {
    40	return a.AFunc()
    41}
    42
    43func init() {
    44	println("package 'main' init")
    45}
    46
    47func main() {
    48	println(a.AFunc())
    49}
    50-- main/main_test.go --
    51package main
    52
    53import "testing"
    54
    55func TestMain(t *testing.T) {
    56	if MFunc() != "42" {
    57		t.Fatalf("bad!")
    58	}
    59	if M2Func() != 42 {
    60		t.Fatalf("also bad!")
    61	}
    62}
    63

View as plain text