Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions exercises/shared/.docs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down