assert.sh
assert.sh copied to clipboard
How to test stderr?
Could you give any advice on how to test stderr? E.g. for assert_raises I'd love to assert on some expected error message.
Figured it out myself. We can just add small bash functions helpers to the test suite test more complex behaviors in a concise way:
. assert.sh
assert_statment(){
# usage cmd exp_stout exp_stder exp_exit_code
assert "$1" "$2"
assert "( $1 ) 2>&1 >/dev/null" "$3"
assert_raises "$1" "$4"
}
assert_statment "echo foo; echo bar >&2; exit 1" "foo" "bar" 1