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

Handling custom exit code in TestMain after m.Run() #32

Open
mfridman opened this issue Jan 10, 2019 · 1 comment
Open

Handling custom exit code in TestMain after m.Run() #32

mfridman opened this issue Jan 10, 2019 · 1 comment

Comments

@mfridman
Copy link
Owner

If a user has TestMain and invokes m.Run() they'll eventually get back an exit code, which normally gets fed to os.Exit().

tparse returns an exit code that's inline with what m.Run() would return based on parsing the test output.

However, there is an edge case where m.Run() can return 0, but the user has additional logic that manually marks the exit code as >0, and then calls os.Exit()

Since tparse operates on the go test output, and doesn't know about this "extra" logic, it can report something different than expected.

@mfridman mfridman changed the title Handling exit code modifications after m.Run() Handling custom exit code in TestMain after m.Run() Dec 15, 2019
@mfridman
Copy link
Owner Author

mfridman commented May 26, 2022

The most sane thing to do here is what was suggested in #54

set -o pipefail && go test ./... -json | tparse -all

Although tparse makes every effort to parse the output and return a non-zero status code, pipefail is your friend:

The exit status of a pipeline is the exit status of the last command in the pipeline, unless the pipefail option is enabled. If pipefail is enabled, the pipeline’s return status is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands exit successfully. [...]

Ref: https://utcc.utoronto.ca/~cks/space/blog/unix/ShellPipesTwoUsages

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

No branches or pull requests

1 participant