...

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

Documentation: cmd/go/testdata/script

     1[short] skip
     2
     3go test -trimpath -v .
     4! stdout '[/\\]pkg_test[/\\]'
     5stdout -count=3 '[/\\]pkg[/\\]'
     6
     7-- go.mod --
     8module example.com/pkg
     9
    10go 1.17
    11
    12-- pkg.go --
    13package pkg
    14
    15import "runtime"
    16
    17func PrintFile() {
    18	_, file, _, _ := runtime.Caller(0)
    19	println(file)
    20}
    21
    22-- pkg_test.go --
    23package pkg
    24
    25import "runtime"
    26
    27func PrintFileForTest() {
    28	_, file, _, _ := runtime.Caller(0)
    29	println(file)
    30}
    31
    32-- pkg_x_test.go --
    33package pkg_test
    34
    35import (
    36	"runtime"
    37	"testing"
    38
    39	"example.com/pkg"
    40)
    41
    42func TestMain(m *testing.M) {
    43	pkg.PrintFile()
    44	pkg.PrintFileForTest()
    45	PrintFileInXTest()
    46}
    47
    48func PrintFileInXTest() {
    49	_, file, _, _ := runtime.Caller(0)
    50	println(file)
    51}

View as plain text