-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: test terminal fail in package list mode, success in local directory mode #68851
Comments
thanks, I checked the above posts. none of them is same issue. #34791 is the most similar but not same issue. In different mode, go test treat os.Stdout differently. it doesn't make sense for me. |
test.go, 1440 line, might be the key to answer the question. var buf bytes.Buffer
if len(pkgArgs) == 0 || testBench != "" || testFuzz != "" {
// Stream test output (no buffering) when no package has
// been given on the command line (implicit current directory)
// or when benchmarking or fuzzing.
// No change to stdout.
} else {
// If we're only running a single package under test or if parallelism is
// set to 1, and if we're displaying all output (testShowPass), we can
// hurry the output along, echoing it as soon as it comes in.
// We still have to copy to &buf for caching the result. This special
// case was introduced in Go 1.5 and is intentionally undocumented:
// the exact details of output buffering are up to the go command and
// subject to change. It would be nice to remove this special case
// entirely, but it is surely very helpful to see progress being made
// when tests are run on slow single-CPU ARM systems.
//
// If we're showing JSON output, then display output as soon as
// possible even when multiple tests are being run: the JSON output
// events are attributed to specific package tests, so interlacing them
// is OK.
if testShowPass() && (len(pkgs) == 1 || cfg.BuildP == 1) || testJSON {
// Write both to stdout and buf, for possible saving
// to cache, and for looking for the "no tests to run" message.
stdout = io.MultiWriter(stdout, &buf)
} else {
stdout = &buf
}
} |
thanks, @Zxilly. after check test.go. I am sure that the above code is the root cause of this issue. For package list mode, stdout is decorated with io.MultiWriter. io.MultiWriter is not a terminal anymore. For local directory mode, stdout is unchanged, it's still a terminal for the test. can anyone know how to get the undecorated stdout? anyway, In different mode, go test treat os.Stdout differently. it doesn't make sense for me. |
Duplicate of #34877 |
use func TestQT(t *testing.T) {
f, _ := os.Open("/dev/tty")
if tm := term.IsTerminal(int(f.Fd())); !tm {
t.Errorf("%s is not terminal\n", f.Name())
}
f.Close()
} |
Go version
go version go1.22.5 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
run test terminal as follows:
What did you see happen?
test passed in local directory mode:
qiwang@Qi15Pro client % go test PASS ok github.com/ericwq/aprilsh/frontend/client 2.263s
test failed in package list mode:
What did you expect to see?
test passed in package list mode.
The text was updated successfully, but these errors were encountered: