From 9fac62435c5f05783456512b09e3f207a9d62004 Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Wed, 28 Feb 2024 23:35:10 +0100 Subject: [PATCH] tests/functional: add assertStderr function Currently there isn't a convenient way to check for multiline output. In addition, these outputs will easily change and having a diff between the expected an the actual output upon failures is convenient. --- tests/functional/common/vars-and-functions.sh.in | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/functional/common/vars-and-functions.sh.in b/tests/functional/common/vars-and-functions.sh.in index 8fef29f97..3975986c0 100644 --- a/tests/functional/common/vars-and-functions.sh.in +++ b/tests/functional/common/vars-and-functions.sh.in @@ -216,6 +216,17 @@ expectStderr() { return 0 } +# Run a command and check whether the stderr matches stdin. +# Show a diff when output does not match. +# Usage: +# +# assertStderr nix profile remove nothing << EOF +# error: This error is expected +# EOF +assertStderr() { + diff -u /dev/stdin <($@ 2>/dev/null 2>&1) +} + needLocalStore() { if [[ "$NIX_REMOTE" == "daemon" ]]; then skipTest "Can’t run through the daemon ($1)"