-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Improve debug output #332
Improve debug output #332
Conversation
This will redirect the debug option to a file, which makes debugging much easier. Eg: ./bashunit local/example_test.sh --debug local/debug.sh
@@ -47,6 +47,10 @@ while [[ $# -gt 0 ]]; do | |||
export BASHUNIT_SIMPLE_OUTPUT=false | |||
;; | |||
--debug) | |||
OUTPUT_FILE="${2:-}" | |||
if [[ -n $OUTPUT_FILE ]]; then | |||
exec > "$OUTPUT_FILE" 2>&1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this new option? Isn't it sufficient to redirect the output directly in the cli command?
bashunit --debug > my.log
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, in that case the redirection is the result output. The --debug enable set -x
which produces a runtime output that is not redirected. That is why you need to change the FD adding 2>&1
to make it work as expected. For this reason, I thought simplifying this to make it work as expected.
Both equivalent examples
# full example before
./bashunit local/example_test.sh --debug > local/debug.sh 2>&1
# with this PR changes
./bashunit local/example_test.sh --debug local/debug.sh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the same as ./bashunit local/example_test.sh --debug 2> local/debug.sh
?
Or will it contain stderr and stdout?
So the question is whether the new option implements something which is not yet easily doable with standard stdout/stderr redirects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so at the beginning. The main diff:
-
./bashunit local/example_test.sh --debug 2> local/debug.sh
Captures only error messages in the file while allowing regular output to go to the terminal. -
./bashunit local/example_test.sh --debug > local/debug.sh 2>&1
Captures both output and error messages into the same file.
However, for some reason that I still dont know, when using ./bashunit tests/acceptance --debug 2> local/debug.sh
I get an error on runtime (it might need investigation why)
while when doing it with ./bashunit tests/acceptance --debug > local/debug.sh 2>&1
I dont get any error
My guess this error is due to how the FD2 (for errors) is handled... I am still having struggle understanding these bash FDs 😄
📚 Description
Inspired by wanting debug this in an easier way #305 (comment) @staabm
🔖 Changes
--debug
optionBEFORE
AFTER
✅ To-do list
CHANGELOG.md
to reflect the new feature or fix