Open
Description
Because bats slurps up both stdout and stderr, it's a bit tricky to add debugging output:
$ cat hello_world.sh
#!/usr/bin/env bash
printf '%(%T)T -- %s\n' -1 'a debugging statement' >&2
echo "Hello, World!"
$ exercism test
Running tests via `bats hello_world.bats`
1..1
not ok 1 Say Hi!
# (from function `assert_output' in file bats-extra.bash, line 394,
# in test file hello_world.bats, line 13)
# `assert_output "Hello, World!"' failed
#
# -- output differs --
# expected (1 lines):
# Hello, World!
# actual (2 lines):
# 11:58:21 -- a debugging statement
# Hello, World!
# --
#
$ echo $?
1
bats
provides file descriptor 3 for just this purpose: stdout and stderr are captured for the tests, and fd 3 is available for debug output: change the printf
redirection to >&3
and:
$ exercism test
Running tests via `bats hello_world.bats`
1..1
11:59:10 -- a debugging statement
ok 1 Say Hi!
$ echo $?
0
This should be documented where it can be helpful to students.