All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nft PATCH 2/3] tests: monitor: Print errors to stderr
Date: Thu, 12 Aug 2021 00:53:26 +0200	[thread overview]
Message-ID: <20210811225327.26229-2-phil@nwl.cc> (raw)
In-Reply-To: <20210811225327.26229-1-phil@nwl.cc>

While being at it, introduce die() to error and exit. But don't use it
everywhere to prepare for continuing on errors.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 tests/monitor/run-tests.sh | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/tests/monitor/run-tests.sh b/tests/monitor/run-tests.sh
index 1fe613c7bc301..c30c328ca6e1e 100755
--- a/tests/monitor/run-tests.sh
+++ b/tests/monitor/run-tests.sh
@@ -9,15 +9,22 @@ mydiff() {
 	diff -w -I '^# ' "$@"
 }
 
-if [ "$(id -u)" != "0" ] ; then
-	echo "this requires root!"
+err() {
+	echo "$*" >&2
+}
+
+die() {
+	err "$*"
 	exit 1
+}
+
+if [ "$(id -u)" != "0" ] ; then
+	die "this requires root!"
 fi
 
 testdir=$(mktemp -d)
 if [ ! -d $testdir ]; then
-	echo "Failed to create test directory" >&2
-	exit 1
+	die "Failed to create test directory"
 fi
 trap 'rm -rf $testdir; $nft flush ruleset' EXIT
 
@@ -67,7 +74,7 @@ monitor_run_test() {
 		cat $command_file
 	}
 	$nft -f $command_file || {
-		echo "nft command failed!"
+		err "nft command failed!"
 		kill $monitor_pid
 		wait >/dev/null 2>&1
 		exit 1
@@ -77,8 +84,8 @@ monitor_run_test() {
 	wait >/dev/null 2>&1
 	$test_json && json_output_filter $monitor_output
 	if ! mydiff -q $monitor_output $output_file >/dev/null 2>&1; then
-		echo "monitor output differs!"
-		mydiff -u $output_file $monitor_output
+		err "monitor output differs!"
+		mydiff -u $output_file $monitor_output >&2
 		exit 1
 	fi
 	rm $command_file
@@ -94,12 +101,12 @@ echo_run_test() {
 		cat $command_file
 	}
 	$nft -nn -e -f $command_file >$echo_output || {
-		echo "nft command failed!"
+		err "nft command failed!"
 		exit 1
 	}
 	if ! mydiff -q $echo_output $output_file >/dev/null 2>&1; then
-		echo "echo output differs!"
-		mydiff -u $output_file $echo_output
+		err "echo output differs!"
+		mydiff -u $output_file $echo_output >&2
 		exit 1
 	fi
 	rm $command_file
-- 
2.32.0


  reply	other threads:[~2021-08-11 22:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-11 22:53 [nft PATCH 1/3] tests: json_echo: Print errors to stderr Phil Sutter
2021-08-11 22:53 ` Phil Sutter [this message]
2021-08-11 22:53 ` [nft PATCH 3/3] tests: monitor: Continue on error Phil Sutter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210811225327.26229-2-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.