mirror of
https://github.com/golang/go
synced 2024-11-16 21:24:53 -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
|
// -failfast
|
||||||
// Do not start new tests after the first test failure.
|
// Do not start new tests after the first test failure.
|
||||||
//
|
//
|
||||||
|
// -fullpath
|
||||||
|
// Show full file names in the error messages.
|
||||||
|
//
|
||||||
// -fuzz regexp
|
// -fuzz regexp
|
||||||
// Run the fuzz test matching the regular expression. When specified,
|
// Run the fuzz test matching the regular expression. When specified,
|
||||||
// the command line argument must match exactly one package within the
|
// the command line argument must match exactly one package within the
|
||||||
|
@ -19,6 +19,7 @@ var passFlagToTest = map[string]bool{
|
|||||||
"cpu": true,
|
"cpu": true,
|
||||||
"cpuprofile": true,
|
"cpuprofile": true,
|
||||||
"failfast": true,
|
"failfast": true,
|
||||||
|
"fullpath": true,
|
||||||
"fuzz": true,
|
"fuzz": true,
|
||||||
"fuzzminimizetime": true,
|
"fuzzminimizetime": true,
|
||||||
"fuzztime": true,
|
"fuzztime": true,
|
||||||
|
@ -240,6 +240,9 @@ control the execution of any test:
|
|||||||
-failfast
|
-failfast
|
||||||
Do not start new tests after the first test failure.
|
Do not start new tests after the first test failure.
|
||||||
|
|
||||||
|
-fullpath
|
||||||
|
Show full file names in the error messages.
|
||||||
|
|
||||||
-fuzz regexp
|
-fuzz regexp
|
||||||
Run the fuzz test matching the regular expression. When specified,
|
Run the fuzz test matching the regular expression. When specified,
|
||||||
the command line argument must match exactly one package within the
|
the command line argument must match exactly one package within the
|
||||||
|
@ -50,6 +50,7 @@ func init() {
|
|||||||
cf.StringVar(&testCPUProfile, "cpuprofile", "", "")
|
cf.StringVar(&testCPUProfile, "cpuprofile", "", "")
|
||||||
cf.Bool("failfast", false, "")
|
cf.Bool("failfast", false, "")
|
||||||
cf.StringVar(&testFuzz, "fuzz", "", "")
|
cf.StringVar(&testFuzz, "fuzz", "", "")
|
||||||
|
cf.Bool("fullpath", false, "")
|
||||||
cf.StringVar(&testList, "list", "", "")
|
cf.StringVar(&testList, "list", "", "")
|
||||||
cf.StringVar(&testMemProfile, "memprofile", "", "")
|
cf.StringVar(&testMemProfile, "memprofile", "", "")
|
||||||
cf.String("memprofilerate", "", "")
|
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")
|
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)")
|
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")
|
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()
|
initBenchmarkFlags()
|
||||||
initFuzzFlags()
|
initFuzzFlags()
|
||||||
@ -472,6 +473,7 @@ var (
|
|||||||
parallel *int
|
parallel *int
|
||||||
shuffle *string
|
shuffle *string
|
||||||
testlog *string
|
testlog *string
|
||||||
|
fullPath *bool
|
||||||
|
|
||||||
haveExamples bool // are there examples?
|
haveExamples bool // are there examples?
|
||||||
|
|
||||||
@ -751,8 +753,9 @@ func (c *common) decorate(s string, skip int) string {
|
|||||||
file := frame.File
|
file := frame.File
|
||||||
line := frame.Line
|
line := frame.Line
|
||||||
if file != "" {
|
if file != "" {
|
||||||
// Truncate file name at last file name separator.
|
if *fullPath {
|
||||||
if index := strings.LastIndex(file, "/"); index >= 0 {
|
// If relative path, truncate file name at last file name separator.
|
||||||
|
} else if index := strings.LastIndex(file, "/"); index >= 0 {
|
||||||
file = file[index+1:]
|
file = file[index+1:]
|
||||||
} else if index = strings.LastIndex(file, "\\"); index >= 0 {
|
} else if index = strings.LastIndex(file, "\\"); index >= 0 {
|
||||||
file = file[index+1:]
|
file = file[index+1:]
|
||||||
|
Loading…
Reference in New Issue
Block a user