assert.sh icon indicating copy to clipboard operation
assert.sh copied to clipboard

How to test stderr?

Open holgerbrandl opened this issue 8 years ago • 1 comments

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.

holgerbrandl avatar Apr 27 '17 20:04 holgerbrandl

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


holgerbrandl avatar May 02 '17 12:05 holgerbrandl