summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2021-08-11 20:08:14 +0200
committerPhil Sutter <phil@nwl.cc>2021-08-24 18:44:15 +0200
commit7e1e90591a1c2adb8b7f265db07bdf71cc70db84 (patch)
tree77c736452f760c760f5d92a52bd8441de08002cd
parentf74f277a3a965261d16f60b0331bad6c22af10a9 (diff)
tests: monitor: Print errors to stderr
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>
-rwxr-xr-xtests/monitor/run-tests.sh27
1 files changed, 17 insertions, 10 deletions
diff --git a/tests/monitor/run-tests.sh b/tests/monitor/run-tests.sh
index 1fe613c7..c30c328c 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