...

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

Documentation: cmd/go/testdata/script

     1
     2# This test is intended to verify that coverage reporting is consistent
     3# between "go test -cover" and "go build -cover" with respect to how
     4# the "main" package is handled. See issue 57169 for details.
     5
     6[short] skip
     7
     8# Build this program with -cover and run to collect a profile.
     9
    10go build -cover -o $WORK/prog.exe .
    11
    12# Save off old GOCOVERDIR setting
    13env SAVEGOCOVERDIR=$GOCOVERDIR
    14
    15mkdir $WORK/covdata
    16env GOCOVERDIR=$WORK/covdata
    17exec $WORK/prog.exe
    18
    19# Restore previous GOCOVERDIR setting
    20env GOCOVERDIR=$SAVEGOCOVERDIR
    21
    22# Report percent lines covered.
    23go tool covdata percent -i=$WORK/covdata
    24stdout '\s*mainwithtest\s+coverage:'
    25! stdout 'main\s+coverage:'
    26
    27# Go test -cover should behave the same way.
    28go test -cover .
    29stdout 'ok\s+mainwithtest\s+\S+\s+coverage:'
    30! stdout 'ok\s+main\s+.*'
    31
    32
    33-- go.mod --
    34module mainwithtest
    35
    36go 1.20
    37-- mymain.go --
    38package main
    39
    40func main() {
    41	println("hi mom")
    42}
    43
    44func Mainer() int {
    45	return 42
    46}
    47-- main_test.go --
    48package main
    49
    50import "testing"
    51
    52func TestCoverage(t *testing.T) {
    53	println(Mainer())
    54}

View as plain text