diff --git a/exercises/shared/.docs/tests.md b/exercises/shared/.docs/tests.md index 36c1fd47..c5871846 100644 --- a/exercises/shared/.docs/tests.md +++ b/exercises/shared/.docs/tests.md @@ -19,6 +19,42 @@ Help for the various `assert*` functions can be found there. [bats-assert]: https://github.com/bats-core/bats-assert +## Debugging output + +```exercism/caution +This works locally with `bats`, but **not** in the Exercism online editor. +``` + +When running tests, `bats` captures both stdout and stderr for comparison with the expected output. +If you print debug messages to stdout (`echo`) or stderr (`>&2`), they will be included in the captured output and may cause the test to fail. + +To print debug information without affecting the test results, `bats` provides file descriptor **3** for this purpose. +Anything redirected to `>&3` will be shown during the test run but will not be included in the captured output used for assertions. + +Example: + +```bash +#!/usr/bin/env bash + +# This debug message will not interfere with test output comparison +echo "debug message" >&3 + +# Normal program output (this is what your tests will see and compare) +echo "Hello, World!" +``` + +Example run: + +```none +$ bats hello_world.bats +hello_world.bats + ✓ Say Hi! +debug message +1 test, 0 failures +``` + +This allows you to see helpful debug output without affecting the tests. + ## Skipped tests Solving an exercise means making all its tests pass.