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

     1  [short] skip
     2  [gccgo] skip
     3  
     4  # Test line numbers in cover errors.
     5  
     6  # Get errors from a go test into stderr.txt
     7  ! go test coverbad
     8  stderr 'p\.go:4' # look for error at coverbad/p.go:4
     9  [cgo] stderr 'p1\.go:6' # look for error at coverbad/p.go:6
    10  ! stderr $WORK # make sure temporary directory isn't in error
    11  
    12  cp stderr $WORK/stderr.txt
    13  
    14  # Clean out character positions from stderr.txt
    15  # It's OK that stderr2 drops the character position in the error,
    16  # because of the //line directive (see golang.org/issue/22662).
    17  go run clean_charpos.go $WORK/stderr.txt &
    18  
    19  # Get errors from coverage into stderr2.txt
    20  ! go test -cover coverbad
    21  cp stderr $WORK/stderr2.txt
    22  
    23  wait # for go run above
    24  
    25  cmp $WORK/stderr.txt $WORK/stderr2.txt
    26  
    27  -- go.mod --
    28  module coverbad
    29  
    30  go 1.16
    31  -- p.go --
    32  package p
    33  
    34  func f() {
    35  	g()
    36  }
    37  -- p1.go --
    38  package p
    39  
    40  import "C"
    41  
    42  func h() {
    43  	j()
    44  }
    45  -- p_test.go --
    46  package p
    47  
    48  import "testing"
    49  
    50  func Test(t *testing.T) {}
    51  -- clean_charpos.go --
    52  // +build ignore
    53  
    54  package main
    55  
    56  import (
    57  	"log"
    58  	"os"
    59  	"strings"
    60  )
    61  
    62  func main() {
    63  	log.SetFlags(0)
    64  	b, err := os.ReadFile(os.Args[1])
    65  	if err != nil {
    66  		log.Fatal(err)
    67  	}
    68  	s := strings.ReplaceAll(string(b), "p.go:4:2:", "p.go:4:")
    69  	s = strings.ReplaceAll(s, "p1.go:6:2:", "p1.go:6:")
    70  	os.WriteFile(os.Args[1], []byte(s), 0644)
    71  	if err != nil {
    72  		log.Fatal(err)
    73  	}
    74  }
    75  

View as plain text