The effect go test -v flag on local directory mode and package list mode

85 views
Skip to first unread message

Jingguo Yao

unread,
Oct 11, 2022, 11:42:00 PM10/11/22
to golang-nuts
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

Ian Lance Taylor

unread,
Oct 12, 2022, 7:13:44 PM10/12/22
to Jingguo Yao, golang-nuts
I don't think we want to lock ourselves into the current behavior if
we can avoid it. We may find reasons to change it over time.

(That said I wouldn't be surprised if changing this behavior broke
some people's use cases.)

Ian

jingguo yao

unread,
Oct 13, 2022, 1:48:02 AM10/13/22
to Ian Lance Taylor, golang-nuts
Got it. 
--
Jingguo

Reply all
Reply to author
Forward
0 new messages