Add support to match regex in ok tests
This commit is contained in:
parent
22b34dcff6
commit
3eac598e2c
@ -67,6 +67,16 @@ function(ovni_test source)
|
||||
"${driver}"
|
||||
"${OVNI_TEST_NAME}"
|
||||
WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}")
|
||||
else()
|
||||
if(OVNI_TEST_REGEX)
|
||||
# Custom error handler for ok too
|
||||
add_test(NAME "${OVNI_TEST_NAME}"
|
||||
COMMAND
|
||||
"${OVNI_TEST_SOURCE_DIR}/match-ok.sh"
|
||||
"${OVNI_TEST_REGEX}"
|
||||
"${driver}"
|
||||
"${OVNI_TEST_NAME}"
|
||||
WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}")
|
||||
else()
|
||||
add_test(NAME "${OVNI_TEST_NAME}"
|
||||
COMMAND
|
||||
@ -74,6 +84,7 @@ function(ovni_test source)
|
||||
"${OVNI_TEST_NAME}"
|
||||
WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set_tests_properties("${OVNI_TEST_NAME}"
|
||||
PROPERTIES
|
||||
|
31
test/match-ok.sh
Executable file
31
test/match-ok.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# This script return 0 if and only if the given program returns zero
|
||||
# AND the regex matches the output
|
||||
|
||||
# $1 = the regex as grep
|
||||
# $2... The program
|
||||
|
||||
regex="$1"
|
||||
shift
|
||||
|
||||
"${@}" 2>&1 | stdbuf -i0 -o0 tee /dev/stderr | grep -q "${regex}"
|
||||
|
||||
rcprog=${PIPESTATUS[0]} rcgrep=${PIPESTATUS[2]}
|
||||
|
||||
echo "rcprog='$rcprog' rcgrep='$rcgrep'"
|
||||
|
||||
if [ "$rcprog" = 0 ] && [ "$rcgrep" = 0 ]; then
|
||||
echo "ok: program succeded and grep matched the error line"
|
||||
exit 0
|
||||
else
|
||||
if [ "$rcprog" != 0 ]; then
|
||||
echo "error: program exited with \"$rcprog\" rather than 0"
|
||||
fi
|
||||
if [ "$rcgrep" != 0 ]; then
|
||||
echo "error: regex \"${regex}\" not matched"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
Loading…
Reference in New Issue
Block a user