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

Improve debug output #332

Merged
merged 2 commits into from
Sep 21, 2024
Merged

Improve debug output #332

merged 2 commits into from
Sep 21, 2024

Conversation

Chemaclass
Copy link
Member

@Chemaclass Chemaclass commented Sep 21, 2024

📚 Description

Inspired by wanting debug this in an easier way #305 (comment) @staabm

🔖 Changes

  • Add optional file-path as 2nd arg to --debug option

BEFORE

./bashunit local/example_test.sh --debug > local/debug.sh 2>&1

AFTER

./bashunit local/example_test.sh --debug local/debug.sh

✅ To-do list

  • I updated the CHANGELOG.md to reflect the new feature or fix
  • I updated the documentation to reflect the changes

This will redirect the debug option to a file, which makes debugging much easier.

Eg: ./bashunit local/example_test.sh --debug local/debug.sh
@Chemaclass Chemaclass added the enhancement New feature or request label Sep 21, 2024
@Chemaclass Chemaclass self-assigned this Sep 21, 2024
@@ -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
Copy link
Contributor

@staabm staabm Sep 21, 2024

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 ?

Copy link
Member Author

@Chemaclass Chemaclass Sep 21, 2024

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

Copy link
Contributor

@staabm staabm Sep 21, 2024

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

Copy link
Member Author

@Chemaclass Chemaclass Sep 21, 2024

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)
Screenshot 2024-09-21 at 12 21 10
Screenshot 2024-09-21 at 12 22 02

while when doing it with ./bashunit tests/acceptance --debug > local/debug.sh 2>&1 I dont get any error

(with or without --debug)
Screenshot 2024-09-21 at 12 24 02
Screenshot 2024-09-21 at 12 24 14


My guess this error is due to how the FD2 (for errors) is handled... I am still having struggle understanding these bash FDs 😄

@Chemaclass Chemaclass requested a review from staabm September 21, 2024 10:07
@Chemaclass Chemaclass merged commit a829587 into main Sep 21, 2024
7 checks passed
@Chemaclass Chemaclass deleted the feat/improve-debug-output branch September 21, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants