mirror of
https://github.com/golang/go
synced 2024-11-16 16:54:39 -07:00
testing: add -fullpath to go test
When -test.fullpath flag is provided to go test, go test displays the full file names in error messages. Fixes #37708 Change-Id: I6096e75ed816fd42205810f20624e495047a73a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/463837 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
c17f8057b0
commit
81316ff50a
@ -2987,6 +2987,9 @@
|
||||
// -failfast
|
||||
// Do not start new tests after the first test failure.
|
||||
//
|
||||
// -fullpath
|
||||
// Show full file names in the error messages.
|
||||
//
|
||||
// -fuzz regexp
|
||||
// Run the fuzz test matching the regular expression. When specified,
|
||||
// the command line argument must match exactly one package within the
|
||||
|
@ -19,6 +19,7 @@ var passFlagToTest = map[string]bool{
|
||||
"cpu": true,
|
||||
"cpuprofile": true,
|
||||
"failfast": true,
|
||||
"fullpath": true,
|
||||
"fuzz": true,
|
||||
"fuzzminimizetime": true,
|
||||
"fuzztime": true,
|
||||
|
@ -240,6 +240,9 @@ control the execution of any test:
|
||||
-failfast
|
||||
Do not start new tests after the first test failure.
|
||||
|
||||
-fullpath
|
||||
Show full file names in the error messages.
|
||||
|
||||
-fuzz regexp
|
||||
Run the fuzz test matching the regular expression. When specified,
|
||||
the command line argument must match exactly one package within the
|
||||
|
@ -50,6 +50,7 @@ func init() {
|
||||
cf.StringVar(&testCPUProfile, "cpuprofile", "", "")
|
||||
cf.Bool("failfast", false, "")
|
||||
cf.StringVar(&testFuzz, "fuzz", "", "")
|
||||
cf.Bool("fullpath", false, "")
|
||||
cf.StringVar(&testList, "list", "", "")
|
||||
cf.StringVar(&testMemProfile, "memprofile", "", "")
|
||||
cf.String("memprofilerate", "", "")
|
||||
|
21
src/cmd/go/testdata/script/test_fullpath.txt
vendored
Normal file
21
src/cmd/go/testdata/script/test_fullpath.txt
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
[short] skip
|
||||
|
||||
# test with -fullpath
|
||||
! go test ./x/... -fullpath
|
||||
stdout '^ +.+/gopath/src/x/fullpath/fullpath_test.go:8: test failed'
|
||||
# test without -fullpath
|
||||
! go test ./x/...
|
||||
stdout '^ +fullpath_test.go:8: test failed'
|
||||
|
||||
-- go.mod --
|
||||
module example
|
||||
-- x/fullpath/fullpath_test.go --
|
||||
package fullpath_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFullPath(t *testing.T) {
|
||||
t.Error("test failed")
|
||||
}
|
@ -441,6 +441,7 @@ func Init() {
|
||||
parallel = flag.Int("test.parallel", runtime.GOMAXPROCS(0), "run at most `n` tests in parallel")
|
||||
testlog = flag.String("test.testlogfile", "", "write test action log to `file` (for use only by cmd/go)")
|
||||
shuffle = flag.String("test.shuffle", "off", "randomize the execution order of tests and benchmarks")
|
||||
fullPath = flag.Bool("test.fullpath", false, "show full file names in error messages")
|
||||
|
||||
initBenchmarkFlags()
|
||||
initFuzzFlags()
|
||||
@ -472,6 +473,7 @@ var (
|
||||
parallel *int
|
||||
shuffle *string
|
||||
testlog *string
|
||||
fullPath *bool
|
||||
|
||||
haveExamples bool // are there examples?
|
||||
|
||||
@ -751,8 +753,9 @@ func (c *common) decorate(s string, skip int) string {
|
||||
file := frame.File
|
||||
line := frame.Line
|
||||
if file != "" {
|
||||
// Truncate file name at last file name separator.
|
||||
if index := strings.LastIndex(file, "/"); index >= 0 {
|
||||
if *fullPath {
|
||||
// If relative path, truncate file name at last file name separator.
|
||||
} else if index := strings.LastIndex(file, "/"); index >= 0 {
|
||||
file = file[index+1:]
|
||||
} else if index = strings.LastIndex(file, "\\"); index >= 0 {
|
||||
file = file[index+1:]
|
||||
|
Loading…
Reference in New Issue
Block a user