aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMattia Rizzolo <mattia@mapreri.org>2015-11-13 12:11:16 +0000
committerMattia Rizzolo <mattia@mapreri.org>2015-11-15 10:16:21 +0000
commitb25fa3e68e83a3c36a111bca0fc090e3bd5529db (patch)
treebc3b86906764f535803dfb50f50c697b1cc39989
parent142b718d9bce0be499e8426c27bce848728559a8 (diff)
downloadpbuilder-b25fa3e68e83a3c36a111bca0fc090e3bd5529db.tar
pbuilder-b25fa3e68e83a3c36a111bca0fc090e3bd5529db.tar.gz
t/testlib: add a expect_stderr(), to explicitely test stderr
-rw-r--r--t/testlib.sh13
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
+}