...
Run Format

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

Documentation: cmd/go/testdata/script

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

View as plain text