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

feature request: add a -fail option that will cause gotestfmt to exit with a failing status code if any tests failed #33

Closed
gabesullice opened this issue Feb 11, 2022 · 5 comments · Fixed by #34

Comments

@gabesullice
Copy link

I have the following command in my GitHub Action:

go test -v -json ./... 2>&1 | gotestfmt

I was surprised to see that my action was passing, even though I was sure that a test was failing. When I looked at the output, the test did fail.

That's because the action succeeded since gotestfmt exited 0.

Would you consider adding an optional -fail flag that will cause gotestfmt to exit with a non-zero exit code if any test fails? That would allow most CI environments to catch failing tests without running them twice.

For now, this is my workaround (ofc, maybe I'm being dumb and there's a much easier solution):

go test -v -json ./... > output.log && (gotestfmt < output.log && exit 0) || (gotestfmt < output.log && exit 1)
@gabesullice
Copy link
Author

gabesullice commented Feb 11, 2022

🤦 I just saw the set -euo pipefail in the docs. That resolves the issue on GitHub.

@ghost
Copy link

ghost commented Feb 12, 2022

Hey @gabesullice thank you very much for your request. I would still consider your feature request as a "default behavior" since it is easy to miss the set -euo pipefail part. Would you mind if I reopened this issue?

@gabesullice
Copy link
Author

No, not at all :)

@gabesullice gabesullice reopened this Feb 12, 2022
ghost pushed a commit that referenced this issue Feb 13, 2022
ghost pushed a commit that referenced this issue Feb 13, 2022
@ghost ghost closed this as completed in #34 Feb 13, 2022
ghost pushed a commit that referenced this issue Feb 13, 2022
* Fixes #33: Non-zero exit code if one or more tests failed

* Added -nofail option to force a 0 exit code in case of a test failure.

* Updated readme with the -nofail flag
@ghost
Copy link

ghost commented Feb 13, 2022

@gabesullice thank you very much for reporting this, the default behavior starting version 2.3.0 will be to exit with a non-zero status if one or more tests fail. This behavior can be disabled with the -nofail option.

@gabesullice
Copy link
Author

Wow, thank you! That was fast :) open source FTW

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant