1
2 [short] skip
3
4 # Hard-wire new coverage for this test.
5 env GOEXPERIMENT=coverageredesign
6
7 # Baseline run.
8 go test -cover example/foo
9 stdout 'coverage: 50.0% of statements$'
10
11 # Coverage percentage output should mention -coverpkg selection.
12 go test -coverpkg=example/foo example/foo
13 stdout 'coverage: 50.0% of statements in example/foo'
14
15 # Try to ask for coverage of a package that doesn't exist.
16 go test -coverpkg nonexistent example/bar
17 stderr 'no packages being tested depend on matches for pattern nonexistent'
18 stdout 'coverage: \[no statements\]'
19
20 # Ask for foo coverage, but test bar.
21 go test -coverpkg=example/foo example/bar
22 stdout 'coverage: 50.0% of statements in example/foo'
23
24 # end of test cmds, start of harness and related files.
25
26 -- go.mod --
27 module example
28
29 go 1.18
30
31 -- foo/foo.go --
32 package foo
33
34 func FooFunc() int {
35 return 42
36 }
37 func FooFunc2() int {
38 return 42
39 }
40
41 -- foo/foo_test.go --
42 package foo
43
44 import "testing"
45
46 func TestFoo(t *testing.T) {
47 if FooFunc() != 42 {
48 t.Fatalf("bad")
49 }
50 }
51
52 -- bar/bar.go --
53 package bar
54
55 import "example/foo"
56
57 func BarFunc() int {
58 return foo.FooFunc2()
59 }
60
61 -- bar/bar_test.go --
62 package bar_test
63
64 import (
65 "example/bar"
66 "testing"
67 )
68
69 func TestBar(t *testing.T) {
70 if bar.BarFunc() != 42 {
71 t.Fatalf("bad")
72 }
73 }
74
75 -- baz/baz.go --
76 package baz
77
78 func BazFunc() int {
79 return -42
80 }
81
View as plain text