Skip to content

Add debugging output section to TESTS.md and adjust formatting#768

Merged
kotp merged 4 commits into
exercism:mainfrom
jooexploit:main
Apr 4, 2026
Merged

Add debugging output section to TESTS.md and adjust formatting#768
kotp merged 4 commits into
exercism:mainfrom
jooexploit:main

Conversation

@jooexploit
Copy link
Copy Markdown
Contributor

@jooexploit jooexploit commented Apr 1, 2026

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

  • Added a Debugging output section to docs/TESTS.md.
  • Clarified that Bats captures both stdout and stderr for assertions.
  • Documented using file descriptor 3 (>&3) for debug messages so they are visible during local runs but excluded from asserted output.
  • Added note that this debugging approach is for local testing, not the Exercism online editor.

Why

Students may print debug text to stderr and see unexpected test failures. This update explains the expected behavior and recommended workflow clearly.

Testing

  • Docs-only change.
  • Content reviewed for clarity and consistency with existing track guidance.

Reviewer Resources:

Track Policies

Copilot AI review requested due to automatic review settings April 1, 2026 19:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/TESTS.md Outdated
```bash
#!/usr/bin/env bash

printf '%(%T)T -- %s\n' -1 'a debugging statement' >&3
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
printf '%(%T)T -- %s\n' -1 'a debugging statement' >&3
printf '%s\n' 'a debugging statement' >&3

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. exercises/shared/.docs/tests.md uses echo.

Comment thread docs/TESTS.md Outdated
Comment on lines +116 to +133
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.

Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both? I'd prefer not to duplicate large chunks of documentation.

Copy link
Copy Markdown
Contributor

@glennj glennj Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have one simply reference the other vs duplicating them?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread docs/TESTS.md Outdated
Comment on lines +129 to +130
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to show the bats output.

Comment thread docs/TESTS.md Outdated
Comment on lines +131 to +132
Use this only when testing locally.
The Exercism online editor does not support this style of debug output.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be more strongly emphasized

Suggested change
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.
~~~~

Comment thread docs/TESTS.md Outdated
Comment on lines +116 to +133
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@glennj glennj requested a review from a team April 1, 2026 20:25
@jooexploit jooexploit requested a review from glennj April 1, 2026 21:26
Comment thread docs/DEBUGGING_LOCALLY.md Outdated
1 test, 0 failures
```

This is useful when you are running the tests locally. The Exercism online editor does not support this pattern.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment thread docs/TESTS.md Outdated
bats whatever.bats
```

If you want to print debug output while running the tests locally, see [Debugging Locally](DEBUGGING_LOCALLY.md).
Copy link
Copy Markdown
Contributor

@glennj glennj Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. the url would be

    Suggested change
    If 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).
  2. 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

Comment thread exercises/shared/.docs/tests.md Outdated
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).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jooexploit jooexploit requested a review from glennj April 2, 2026 12:58
Comment thread docs/DEBUGGING_LOCALLY.md Outdated
@@ -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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment thread docs/DEBUGGING_LOCALLY.md Outdated
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment thread docs/DEBUGGING_LOCALLY.md
Comment thread exercises/shared/.docs/tests.md Outdated
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).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use named links similar to [tests] on line 15

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve updated everything you requested:

  • Updated wording in DEBUGGING_LOCALLY.md to 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.md to a named-link format ([debugging]), similar to [tests]

@jooexploit jooexploit requested a review from IsaacG April 3, 2026 09:11
@kotp kotp merged commit 254ca88 into exercism:main Apr 4, 2026
@glennj
Copy link
Copy Markdown
Contributor

glennj commented Apr 4, 2026

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document how to add debug output to bats testing

5 participants