Skip to content

Commit 292f4e9

Browse files
committed
feat: add the "debugging output" for tests.md
1 parent bbe9249 commit 292f4e9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

exercises/shared/.docs/tests.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ Help for the various `assert*` functions can be found there.
1919

2020
[bats-assert]: https://github.com/bats-core/bats-assert
2121

22+
## Debugging output
23+
24+
When running tests, `bats` captures both stdout and stderr for comparison with the expected output.
25+
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.
26+
27+
To print debug information without affecting the test results, `bats` provides file descriptor **3** for this purpose.
28+
Anything written to `>&3` will be shown during the test run but will not be included in the captured output used for assertions.
29+
30+
Example:
31+
32+
```bash
33+
#!/usr/bin/env bash
34+
35+
# This debug message will not interfere with test output comparison
36+
printf '%(%T)T -- %s\n' -1 'debugging message' >&3
37+
38+
# Your normal program output
39+
echo "Hello, World!"
40+
```
41+
42+
This allows you to keep helpful debug output visible while running tests without breaking assertions.
43+
2244
## Skipped tests
2345

2446
Solving an exercise means making all its tests pass.

0 commit comments

Comments
 (0)