feature request: assert_stderr
In bats-core documentation Writing tests, it is said that:
Additionally, you can use
--separate-stderrto split stdout and stderr into$output/$stderrand${lines[@]}/${stderr_lines[@]}.
Unfortunately, bats-assert does not provide a method to test $stderr contents.
Please consider a refactor of assert_output to allow for stderr contents testing.
This is not even a bats-assert issue...
Per: https://github.com/bats-core/bats-core/blob/990d8e285e7564ff61ea2c93a6da12856d337d83/lib/bats-core/test_functions.bash#L362C3-L362C9
It works out of the box :
run sh -c ">&2 echo 'have'"
assert_output "want"
Merged is default, so it works by default. There is no $stderr by default (see below). So you must use separate.
Separate Example:
run --separate-stderr sh -c "echo 'have' 1>&2"
output=$stderr assert_output "want"
The above code works.
The key part your looking for is: "output=$stderr assert_output ..."
Or make your own function in setup():
setup(){
assert_stderr(){
output=$stderr assert_output "$@"
}
}
@test "bats-assert is not the cause" {
run --separate-stderr sh -c ">&2 echo 'have'"
assert_stderr "want"
}
You must modify run with "--separate-stderr" anyways.
run sh -c ">&2 echo 'have'"
echo "$stderr"
results in:
stderr: unbound variable
TL;DR;
You should "output=$stderr assert_output ..." if your going to "--separate-stderr" anyways. This feature request is not a good idea.
Thank you for the precision