Add debugging output section to TESTS.md and adjust formatting#768
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Bash track testing documentation to improve formatting and add guidance on emitting debug output during local bats test runs.
Changes:
- Reformatted the Homebrew note about installing
bats-core(list formatting/indentation). - Added a new “Debugging output” section describing use of file descriptor 3 for diagnostics.
- Cleaned up minor formatting (removed trailing whitespace / extra blank line).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ```bash | ||
| #!/usr/bin/env bash | ||
|
|
||
| printf '%(%T)T -- %s\n' -1 'a debugging statement' >&3 |
There was a problem hiding this comment.
The debugging example uses Bash’s extended printf time format (%(...)T), which is not supported in older Bash versions (notably the default Bash 3.2 on many macOS installations). Since this is a general troubleshooting tip for local runs, consider using a simpler echo/portable printf message to >&3 so the snippet works across common environments.
| printf '%(%T)T -- %s\n' -1 'a debugging statement' >&3 | |
| printf '%s\n' 'a debugging statement' >&3 |
There was a problem hiding this comment.
agreed. exercises/shared/.docs/tests.md uses echo.
| When running tests, `bats` captures both stdout and stderr for output assertions. | ||
| This means debug output printed with `echo` (stdout) or redirected to `>&2` (stderr) can cause tests to fail. | ||
|
|
||
| For debugging, print to file descriptor `3` instead. | ||
| `bats` reserves fd 3 for diagnostic output that is shown during test runs but not included in captured output. | ||
|
|
||
| Example: | ||
|
|
||
| ```bash | ||
| #!/usr/bin/env bash | ||
|
|
||
| printf '%(%T)T -- %s\n' -1 'a debugging statement' >&3 | ||
| echo "Hello, World!" | ||
| ``` | ||
|
|
||
| Use this only when testing locally. | ||
| The Exercism online editor does not support this style of debug output. | ||
|
|
There was a problem hiding this comment.
This new “Debugging output” section largely duplicates the guidance already present in exercises/shared/.docs/tests.md (including the fd 3 recommendation). To avoid the two docs drifting over time, consider keeping the wording/example in sync with the shared docs (or referencing it) so learners see consistent guidance.
| When running tests, `bats` captures both stdout and stderr for output assertions. | |
| This means debug output printed with `echo` (stdout) or redirected to `>&2` (stderr) can cause tests to fail. | |
| For debugging, print to file descriptor `3` instead. | |
| `bats` reserves fd 3 for diagnostic output that is shown during test runs but not included in captured output. | |
| Example: | |
| ```bash | |
| #!/usr/bin/env bash | |
| printf '%(%T)T -- %s\n' -1 'a debugging statement' >&3 | |
| echo "Hello, World!" | |
| ``` | |
| Use this only when testing locally. | |
| The Exercism online editor does not support this style of debug output. | |
| Guidance on producing debug output when running `bats` tests (including the use of file descriptor `3`) is shared across exercises. | |
| Please refer to the "Debugging output" section in the shared tests documentation (`exercises/shared/.docs/tests.md`) for the recommended approach and examples. |
There was a problem hiding this comment.
Copilot, the exercises/shared/.docs/tests.md file is not visible to students. That file is used in the construction of the README.md file that is part of the exercism download process.
There was a problem hiding this comment.
Do we need both? I'd prefer not to duplicate large chunks of documentation.
There was a problem hiding this comment.
I think it's useful to have both. These changes are for https://exercism.org/docs/tracks/bash/tests (where there are lots of instructions for testing locally) and the other are for the exercism download READM file.
There was a problem hiding this comment.
Could we have one simply reference the other vs duplicating them?
There was a problem hiding this comment.
We should probably create docs/DEBUGGING_LOCALLY.md
Then docs/TESTS.md and the README can both link to it. We have to assume that people working locally have an internet connection.
@jooexploit can you rework this PR to make that happen?
There was a problem hiding this comment.
I ve reworked the PR as requested: I added DEBUGGING_LOCALLY.md and updated TESTS.md and README.md to link to it instead of duplicating the debugging guidance. I m going to push the updated changes now
| ``` | ||
|
|
There was a problem hiding this comment.
You need to show the bats output.
| Use this only when testing locally. | ||
| The Exercism online editor does not support this style of debug output. |
There was a problem hiding this comment.
This needs to be more strongly emphasized
| Use this only when testing locally. | |
| The Exercism online editor does not support this style of debug output. | |
| ~~~~exercism/caution | |
| Use this only when testing **locally**. | |
| The Exercism online editor does not support this style of debug output. | |
| ~~~~ |
| When running tests, `bats` captures both stdout and stderr for output assertions. | ||
| This means debug output printed with `echo` (stdout) or redirected to `>&2` (stderr) can cause tests to fail. | ||
|
|
||
| For debugging, print to file descriptor `3` instead. | ||
| `bats` reserves fd 3 for diagnostic output that is shown during test runs but not included in captured output. | ||
|
|
||
| Example: | ||
|
|
||
| ```bash | ||
| #!/usr/bin/env bash | ||
|
|
||
| printf '%(%T)T -- %s\n' -1 'a debugging statement' >&3 | ||
| echo "Hello, World!" | ||
| ``` | ||
|
|
||
| Use this only when testing locally. | ||
| The Exercism online editor does not support this style of debug output. | ||
|
|
There was a problem hiding this comment.
Copilot, the exercises/shared/.docs/tests.md file is not visible to students. That file is used in the construction of the README.md file that is part of the exercism download process.
| 1 test, 0 failures | ||
| ``` | ||
|
|
||
| This is useful when you are running the tests locally. The Exercism online editor does not support this pattern. |
There was a problem hiding this comment.
| This is useful when you are running the tests locally. The Exercism online editor does not support this pattern. | |
| This is useful when you are running the tests locally. | |
| The Exercism online editor does not support this pattern. |
Still use single sentence per line style.
| bats whatever.bats | ||
| ``` | ||
|
|
||
| If you want to print debug output while running the tests locally, see [Debugging Locally](DEBUGGING_LOCALLY.md). |
There was a problem hiding this comment.
-
the url would be
Suggested changeIf you want to print debug output while running the tests locally, see [Debugging Locally](DEBUGGING_LOCALLY.md). If you want to print debug output while running the tests locally, see [Debugging Locally](/docs/tracks/bash/debugging). -
edit docs/config.json to add a section for this doc
{ "uuid": "${UUID}", "slug": "debugging", "path": "docs/DEBUGGING_LOCALLY.md", "title": "Debugging with `bats`", "blurb": "Debugging your Bash code while testing with bats." },generate a uuid with
bin/configlet uuid
| bats hello_world.bats | ||
| ``` | ||
|
|
||
| If you need to print debug output while running tests locally, see [Debugging Locally](https://github.com/exercism/bash/blob/master/docs/DEBUGGING_LOCALLY.md). |
There was a problem hiding this comment.
| If you need to print debug output while running tests locally, see [Debugging Locally](https://github.com/exercism/bash/blob/master/docs/DEBUGGING_LOCALLY.md). | |
| If you need to print debug output while running tests locally, see [Debugging Locally](https://exercism.org/docs/tracks/bash/debugging). |
There was a problem hiding this comment.
Done. I updated the shared tests doc link to point to the published Exercism page at https://exercism.org/docs/tracks/bash/debugging, and I also added DEBUGGING_LOCALLY.md to config.json so it gets published at /docs/tracks/bash/debugging. The local debugging guide, TESTS.md, and README.md are all aligned now. Please take another look.
| @@ -0,0 +1,28 @@ | |||
| # Debugging Locally | |||
|
|
|||
| When you run Bash track tests with [Bats](https://github.com/bats-core/bats-core), Bats captures both stdout and stderr for output assertions. | |||
There was a problem hiding this comment.
| When you run Bash track tests with [Bats](https://github.com/bats-core/bats-core), Bats captures both stdout and stderr for output assertions. | |
| When you run Bash track tests with [Bats](https://github.com/bats-core/bats-core), Bats captures both STDOUT and STDERR for output assertions. |
| This works locally with `bats`, but **not** in the Exercism online editor. | ||
| ``` | ||
|
|
||
| If you want to print debug output without affecting the test result, write it to file descriptor 3. |
There was a problem hiding this comment.
| If you want to print debug output without affecting the test result, write it to file descriptor 3. | |
| If you want to print debug output without affecting the test result, write it to file descriptor (fd) 3. |
| bats hello_world.bats | ||
| ``` | ||
|
|
||
| If you need to print debug output while running tests locally, see [Debugging Locally](https://exercism.org/docs/tracks/bash/debugging). |
There was a problem hiding this comment.
Use named links similar to [tests] on line 15
There was a problem hiding this comment.
I’ve updated everything you requested:
- Updated wording in
DEBUGGING_LOCALLY.mdto use STDOUT and STDERR - Changed “file descriptor 3” to “file descriptor (fd) 3” in
DEBUGGING_LOCALLY.md - Removed the repeated online editor warning at the end of
DEBUGGING_LOCALLY.md - Switched the shared doc link in
tests.mdto a named-link format ([debugging]), similar to[tests]
…ile descriptor reference
|
@jooexploit here it is: https://exercism.org/docs/tracks/bash/debugging And my mistake: it's not the exercise's README, it's the HELP.md where this shows up: https://github.com/glennj/exercism.io/blob/main/bash/hello-world/HELP.md?plain=1 Thanks for contributing! |
pull request template
Summary
Closes #744.
This PR documents how to print debug output while running Bash track tests with Bats without breaking output assertions.
What Changed
docs/TESTS.md.>&3) for debug messages so they are visible during local runs but excluded from asserted output.Why
Students may print debug text to stderr and see unexpected test failures. This update explains the expected behavior and recommended workflow clearly.
Testing
Reviewer Resources:
Track Policies