2023-04-05 15:18:03 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Copyright (c) 2022-2023 Barcelona Supercomputing Center (BSC)
|
2022-09-19 12:39:02 +02:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2022-08-22 16:40:08 +02:00
|
|
|
|
|
|
|
# This script return 0 if and only if the given program returns non-zero
|
|
|
|
# AND the regex matches the output
|
|
|
|
|
|
|
|
# $1 = the regex as grep
|
|
|
|
# $2... The program
|
|
|
|
|
|
|
|
regex="$1"
|
|
|
|
shift
|
|
|
|
|
2022-11-09 16:20:04 +01:00
|
|
|
"${@}" 2>&1 | stdbuf -i0 -o0 tee /dev/stderr | grep "${regex}" >/dev/null
|
2022-08-22 16:40:08 +02:00
|
|
|
|
|
|
|
rcprog=${PIPESTATUS[0]} rcgrep=${PIPESTATUS[2]}
|
|
|
|
|
|
|
|
echo "rcprog='$rcprog' rcgrep='$rcgrep'"
|
|
|
|
|
|
|
|
if [ "$rcprog" != 0 ] && [ "$rcgrep" = 0 ]; then
|
|
|
|
echo "ok: program failed and grep matched the error line"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
if [ "$rcprog" = 0 ]; then
|
|
|
|
echo "error: program exited with 0 rather than failure"
|
|
|
|
fi
|
|
|
|
if [ "$rcgrep" != 0 ]; then
|
|
|
|
echo "error: regex \"${regex}\" not matched"
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|