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