Skip to content
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

fix: silence output when running go test #88

Merged
merged 1 commit into from
Mar 9, 2024

Conversation

trym-b
Copy link
Contributor

@trym-b trym-b commented Mar 7, 2024

This commit fixes the issue where running go test would write to stdout. This was caused by
commit 0c94a34.

The solution is just to redirect stdout and
stderr to nil.

Solves #87

@maeb
Copy link
Member

maeb commented Mar 7, 2024

See #87 (comment).

@maeb maeb linked an issue Mar 7, 2024 that may be closed by this pull request
@maeb
Copy link
Member

maeb commented Mar 7, 2024

So my suggestion is to close this PR since the test command in CI usually is go test ./... which by default suppresses output.

main_test.go Outdated
Comment on lines 11 to 20
stdout_backup := os.Stdout
stderr_backup := os.Stderr
os.Stdout = nil
os.Stderr = nil

shell := cmd.NewCommand()
_ = shell.Execute()

os.Stdout = stdout_backup
os.Stderr = stderr_backup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
stdout_backup := os.Stdout
stderr_backup := os.Stderr
os.Stdout = nil
os.Stderr = nil
shell := cmd.NewCommand()
_ = shell.Execute()
os.Stdout = stdout_backup
os.Stderr = stderr_backup
os.Stdout = nil
os.Stderr = nil
shell := cmd.NewCommand()
_ = shell.Execute()

Why not keep it simple?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a fixup commit: 0369090

@maeb
Copy link
Member

maeb commented Mar 7, 2024

So my suggestion is to close this PR since the test command in CI usually is go test ./... which by default suppresses output.

Sorry I didn't read the reply in #87 so ignore this comment.

Copy link
Member

@maeb maeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. See my suggestion to simplify it.

This commit fixes the issue where running `go
test` would write to stdout. This was caused by
commit 0c94a34.

The solution is just to redirect `stdout` and
`stderr` to `nil`.

Solves #87
@trym-b trym-b force-pushed the fix/silence-output-when-running-go-test branch from 0369090 to 492023e Compare March 8, 2024 06:36
@trym-b trym-b merged commit f051953 into main Mar 9, 2024
4 checks passed
@trym-b trym-b deleted the fix/silence-output-when-running-go-test branch March 9, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

go test prints unneeded data to stdout
2 participants