...

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

Documentation: cmd/go/testdata/script

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

View as plain text