From b25fa3e68e83a3c36a111bca0fc090e3bd5529db Mon Sep 17 00:00:00 2001 From: Mattia Rizzolo Date: Fri, 13 Nov 2015 12:11:16 +0000 Subject: t/testlib: add a expect_stderr(), to explicitely test stderr --- t/testlib.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 +} -- cgit v1.2.3