-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Make asserting failed exit codes and output nicer #334
Comments
Sure thing! @ondrejmirtes, can you give me an example of how would you vision the ideal use case? Especially, how would you use bashunit in this context (what would you like to have). This can help me going in the direction you need (test-first mindset), because right now I am not sure if I got the solution/problem right. The core issue, I think, is that you currently need the |
I am playing around trying to feel the pain/problem <?php
class Testing {
function bar(int $baz = 0) {
return $baz;
}
} # Current example
OUTPUT=$("$PHPSTAN_PATH" analyze --no-progress --level 8 --error-format raw local/ || true)
echo "$OUTPUT"
./bashunit -a line_count 1 "$OUTPUT"
./bashunit -a contains 'Method teseting::bar() has no return type specified.' "$OUTPUT"
# Alternative(?)
OUTPUT=$("$PHPSTAN_PATH" analyze --no-progress --level 8 --error-format raw local/)
./bashunit -a line_count 1 "$OUTPUT"
./bashunit -a contains 'Method teseting::bar() has no return type specified.' "$OUTPUT" Both example works just fine. This is why I mention I feel I need more context, because using the |
there is still no assertion for the exit code of the phpstan command |
@staabm you can assert the exit codes as well: https://bashunit.typeddevs.com/assertions#assert-exit-code |
The github action will stop executing further commands as soon as a commands exits with non-zero. This means you can't assert after a command anymore as the execution already stopped I need to test it.. give me a few hours ;-) |
Have you tried - name: Run PHPUnit tests
run: phpunit --testdox
continue-on-error: true Docs: https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions Although, this might be similar as doing this ... 🤔 - name: Run PHPUnit tests
run: phpunit --testdox || true |
so our use case is, that we want to assert the output and also the exit code of the phpstan command we could assert the exit code with - I guess:
but not the output. or we can use
to assert the output.. but we cannot check the exit code that way |
I think something like this could work:
in case we could instruct bashunit to pass the stdout of the command thru. |
@ondrejmirtes @staabm how does this looks like for you? Here you have the MVP based on your last comment, @staabm I think this deferrable idea looks very sexy, however I am not sure about This POC is now only working on for the standalone |
I would not mix the output of bashunit and the callable on the same output stream. Bashunit output should go to stderr and the callable output to stdout The bashunit command should return exit code 0 if the assertion matched and otherwise non-zero All of the above only when --forward-stdout. Maybe we don't need the option at all, because bashunit will already behave correctly without it. I am not sure. I don't think we need it for other assertions, because after output has been caputred via stdout into a variable, I can use any assertion on said variable |
@ondrejmirtes @staabm yes, that make sense.
How does this looks like now? #336 |
Creating this based on our discussion in Dresden :)
If we want to assert that a command failed & assert its output, we have to do something like this:
The problem is that we're not really asserting that the commands returned exit code greater than zero, and also that we need to do the whole
OUTPUT=$(command || true)
dance.Would be great if Bashunit provided a nicer way to do this :)
The text was updated successfully, but these errors were encountered: