I have the following directory layout:
├── bar
│ └── bar_test.go
├── foo
│ └── foo_test.go
├── go.mod
└── go.sum
foo_test.go:
package main
import (
"fmt"
"testing"
)
func TestHelloWorld(t *testing.T) {
fmt.Println("hello, foo")
t.Log("hi, foo")
}
bar_test.go:
package bar
import (
"fmt"
"testing"
)
func TestGreeting(t *testing.T) {
fmt.Println("hello, bar")
t.Log("hi, bar")
}
$ go test -count=1 -v ./...
=== RUN TestGreeting
hello, bar
bar_test.go:10: hi, bar
--- PASS: TestGreeting (0.00s)
PASS
ok
yao.org/lang/bar 0.814s
=== RUN TestHelloWorld
hello, foo
foo_test.go:10: hi, foo
--- PASS: TestHelloWorld (0.00s)
PASS
ok
yao.org/lang/foo 0.518s
$ go test -count=1 ./...
ok
yao.org/lang/bar 0.115s
ok
yao.org/lang/foo 0.210s
foo$ go test -v -count=1
=== RUN TestHelloWorld
hello, foo
foo_test.go:10: hi, foo
--- PASS: TestHelloWorld (0.00s)
PASS
ok
yao.org/lang/foo 0.271s
foo$ go test -count=1
hello, foo
PASS
ok
yao.org/lang/foo 0.105s
I found the following different effects on two test modes by -v flag.
1. -v enables the output of fmt.Println and T.Log statements in package list mode.
2. -v enables the output of T.Log statements in local directory mode.
I browsed
https://pkg.go.dev/cmd/go. But I failed to find a description of
this difference. Does this difference work as designed? If yes, can we document
it explicitly?
I am using go version go1.19.1 darwin/amd64.
Jingguo