diff options
author | Mattia Rizzolo <mattia@mapreri.org> | 2015-11-13 12:11:16 +0000 |
---|---|---|
committer | Mattia Rizzolo <mattia@mapreri.org> | 2015-11-15 10:16:21 +0000 |
commit | b25fa3e68e83a3c36a111bca0fc090e3bd5529db (patch) | |
tree | bc3b86906764f535803dfb50f50c697b1cc39989 | |
parent | 142b718d9bce0be499e8426c27bce848728559a8 (diff) | |
download | pbuilder-b25fa3e68e83a3c36a111bca0fc090e3bd5529db.tar pbuilder-b25fa3e68e83a3c36a111bca0fc090e3bd5529db.tar.gz |
t/testlib: add a expect_stderr(), to explicitely test stderr
-rw-r--r-- | t/testlib.sh | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/t/testlib.sh b/t/testlib.sh index 7d31888..05cdfdc 100644 --- a/t/testlib.sh +++ b/t/testlib.sh @@ -156,3 +156,16 @@ expect_output() { fi } +expect_stderr() { + # we need to use 2 subshells, one which discards the stdout, and the other + # that redirects stderr to stdout so that it can be saved to the variable + local val result + val="$1" + shift + result="$( { "$@" >/dev/null; } 2>&1)" || true + if [ "$result" = "$val" ]; then + testlib_echo "OK" "$1" + else + testlib_echo "FAIL" "$1" "expected [$val] but got [$result]" + fi +} |