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