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

     1  [short] skip
     2  
     3  # Workaround for issue 64014 -- for the portion of this test that
     4  # verifies that caching works correctly, the cache should theoretically
     5  # always behave reliably/deterministically, however if other tests are
     6  # concurrently accessing the cache while this test is running, it can
     7  # lead to cache lookup failures, which manifest as test failures here.
     8  # To avoid such flakes, use a separate isolated GOCACHE for this test.
     9  env GOCACHE=$WORK/cache
    10  
    11  # Initial run with simple coverage.
    12  go test -cover ./pkg1 ./pkg2 ./pkg3 ./pkg4
    13  [!GOEXPERIMENT:coverageredesign] stdout 'pkg1	\[no test files\]'
    14  [GOEXPERIMENT:coverageredesign] stdout 'pkg1		coverage: 0.0% of statements'
    15  stdout 'pkg2	\S+	coverage: 0.0% of statements \[no tests to run\]'
    16  stdout 'pkg3	\S+	coverage: 100.0% of statements'
    17  stdout 'pkg4	\S+	coverage: \[no statements\]'
    18  
    19  # Second run to make sure that caching works properly.
    20  go test -x -cover ./pkg1 ./pkg2 ./pkg3 ./pkg4
    21  [!GOEXPERIMENT:coverageredesign] stdout 'pkg1	\[no test files\]'
    22  [GOEXPERIMENT:coverageredesign] stdout 'pkg1		coverage: 0.0% of statements'
    23  stdout 'pkg2	\S+	coverage: 0.0% of statements \[no tests to run\]'
    24  stdout 'pkg3	\S+	coverage: 100.0% of statements'
    25  stdout 'pkg4	\S+	coverage: \[no statements\]'
    26  [GOEXPERIMENT:coverageredesign] ! stderr 'link(\.exe"?)? -'
    27  ! stderr 'compile(\.exe"?)? -'
    28  ! stderr 'cover(\.exe"?)? -'
    29  [GOEXPERIMENT:coverageredesign] stderr 'covdata(\.exe"?)? percent'
    30  
    31  # Now add in -coverprofile.
    32  go test -cover -coverprofile=cov.dat ./pkg1 ./pkg2 ./pkg3 ./pkg4
    33  [!GOEXPERIMENT:coverageredesign] stdout 'pkg1	\[no test files\]'
    34  [GOEXPERIMENT:coverageredesign] stdout 'pkg1		coverage: 0.0% of statements'
    35  stdout 'pkg2	\S+	coverage: 0.0% of statements \[no tests to run\]'
    36  stdout 'pkg3	\S+	coverage: 100.0% of statements'
    37  stdout 'pkg4	\S+	coverage: \[no statements\]'
    38  
    39  # Validate
    40  go tool cover -func=cov.dat
    41  [GOEXPERIMENT:coverageredesign] stdout 'pkg1/a.go:5:\s+F\s+0.0%'
    42  
    43  -- go.mod --
    44  module m
    45  
    46  go 1.16
    47  -- pkg1/a.go --
    48  package pkg1
    49  
    50  import "fmt"
    51  
    52  func F() {
    53  	fmt.Println("pkg1")
    54  }
    55  -- pkg2/a.go --
    56  package pkg2
    57  
    58  import "fmt"
    59  
    60  func F() {
    61  	fmt.Println("pkg2")
    62  }
    63  -- pkg2/a_test.go --
    64  package pkg2
    65  -- pkg3/a.go --
    66  package pkg3
    67  
    68  import "fmt"
    69  
    70  func F() {
    71  	fmt.Println("pkg3")
    72  }
    73  -- pkg3/a_test.go --
    74  package pkg3
    75  
    76  import "testing"
    77  
    78  func TestF(t *testing.T) {
    79  	F()
    80  }
    81  -- pkg4/a.go --
    82  package pkg4
    83  
    84  type T struct {
    85  	X bool
    86  }
    87  -- pkg4/a_test.go --
    88  package pkg4
    89  
    90  import (
    91  	"testing"
    92  )
    93  
    94  func TestT(t *testing.T) {
    95  	_ = T{}
    96  }
    97  

View as plain text