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

Testing: console output and json file print out at the same time? #37204

Closed
qzhao17 opened this issue Feb 13, 2020 · 5 comments
Closed

Testing: console output and json file print out at the same time? #37204

qzhao17 opened this issue Feb 13, 2020 · 5 comments

Comments

@qzhao17
Copy link

qzhao17 commented Feb 13, 2020

What version of Go are you using (go version)?

$ go version go1.13.5

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

go test -v -json > gotest.json

What did you expect to see?

I am looking for a way to print out on the console and generate the json file at the same time.

What did you see instead?

only json file without console output

@networkimprov
Copy link

See unix tee command.

@muirdm
Copy link

muirdm commented Feb 13, 2020

This looks like a general programming question, not a Go issue. See https://github.com/golang/go/wiki/Questions.

I am looking for a way to print out on the console and generate the json file at the same time.

Since test output goes to stdout, you can separate your console output using stderr, e.g. fmt.Fprintln(os.Stderr, "my console output").

@qzhao17
Copy link
Author

qzhao17 commented Feb 13, 2020

🤔For example, if using 'go test -json > gotest.json test_folder_name'. The whole test output will be stored in gotest.json.
if using 'go test test_folder_name', it will print out some following information.
? github.com/script/local [no test files]
ok github.com/script/inputfilters (cached)

I am looking for a way to keep both. Any thoughts on it?

@networkimprov
Copy link

Post your Q on golang-nuts mailing list.

@qzhao17
Copy link
Author

qzhao17 commented Feb 13, 2020

Suggestion from Gohphers slack:
Step 1. go test -json test_folder_name | tee gotest.json
Step2. pipe the output file into tools like jq, awk to prettify

@qzhao17 qzhao17 closed this as completed Feb 13, 2020
@golang golang locked and limited conversation to collaborators Feb 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants