Skip to content

Commit a970edd

Browse files
authored
feat: add the "debugging output" for tests.md (#748)
1 parent bbe9249 commit a970edd

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

exercises/shared/.docs/tests.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,42 @@ 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+
```exercism/caution
25+
This works locally with `bats`, but **not** in the Exercism online editor.
26+
```
27+
28+
When running tests, `bats` captures both stdout and stderr for comparison with the expected output.
29+
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.
30+
31+
To print debug information without affecting the test results, `bats` provides file descriptor **3** for this purpose.
32+
Anything redirected to `>&3` will be shown during the test run but will not be included in the captured output used for assertions.
33+
34+
Example:
35+
36+
```bash
37+
#!/usr/bin/env bash
38+
39+
# This debug message will not interfere with test output comparison
40+
echo "debug message" >&3
41+
42+
# Normal program output (this is what your tests will see and compare)
43+
echo "Hello, World!"
44+
```
45+
46+
Example run:
47+
48+
```none
49+
$ bats hello_world.bats
50+
hello_world.bats
51+
✓ Say Hi!
52+
debug message
53+
1 test, 0 failures
54+
```
55+
56+
This allows you to see helpful debug output without affecting the tests.
57+
2258
## Skipped tests
2359

2460
Solving an exercise means making all its tests pass.

0 commit comments

Comments
 (0)