Skip to content

Commit 1ea00ee

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

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

exercises/shared/.docs/tests.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,39 @@ 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 redirected 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+
echo "debug message" >&3
37+
38+
# Normal program output (this is what your tests will see and compare)
39+
echo "Say Hi!"
40+
41+
```
42+
43+
Example run::
44+
45+
```none
46+
$ bats hello_world.bats
47+
hello_world.bats
48+
✓ Say Hi!
49+
debug message
50+
1 test, 0 failures
51+
```
52+
53+
This allows you to keep helpful debug output visible while running tests without breaking assertions.
54+
2255
## Skipped tests
2356

2457
Solving an exercise means making all its tests pass.

0 commit comments

Comments
 (0)