mirror of
https://github.com/samba-team/samba.git
synced 2025-01-03 01:18:10 +03:00
ctdb-tests: Reformat script
Samba is reformatting shell scripts using shfmt -w -p -i 0 -fn so update this one before editing. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
bcd66e17ee
commit
5fa0c86b61
@ -12,17 +12,17 @@ trap -- '' PIPE
|
||||
# indicates empty output.
|
||||
# If argument 2 is not present or null then read required test output
|
||||
# from stdin.
|
||||
required_result ()
|
||||
required_result()
|
||||
{
|
||||
required_rc="${1:-0}"
|
||||
if [ -n "$2" ] ; then
|
||||
if [ "$2" = "--" ] ; then
|
||||
if [ -n "$2" ]; then
|
||||
if [ "$2" = "--" ]; then
|
||||
required_output=""
|
||||
else
|
||||
required_output="$2"
|
||||
fi
|
||||
else
|
||||
if ! tty -s ; then
|
||||
if ! tty -s; then
|
||||
required_output=$(cat)
|
||||
else
|
||||
required_output=""
|
||||
@ -30,36 +30,36 @@ required_result ()
|
||||
fi
|
||||
}
|
||||
|
||||
required_error ()
|
||||
required_error()
|
||||
{
|
||||
rc=$(errcode "$1")
|
||||
shift
|
||||
required_result "$rc" "$@"
|
||||
}
|
||||
|
||||
ok ()
|
||||
ok()
|
||||
{
|
||||
required_result 0 "$@"
|
||||
}
|
||||
|
||||
ok_null ()
|
||||
ok_null()
|
||||
{
|
||||
ok --
|
||||
}
|
||||
|
||||
reset_extra_header ()
|
||||
reset_extra_header()
|
||||
{
|
||||
# Re-define this function to output extra header information
|
||||
extra_header ()
|
||||
extra_header()
|
||||
{
|
||||
:
|
||||
}
|
||||
}
|
||||
|
||||
reset_extra_footer ()
|
||||
reset_extra_footer()
|
||||
{
|
||||
# Re-define this function to output extra footer information
|
||||
extra_footer ()
|
||||
extra_footer()
|
||||
{
|
||||
:
|
||||
}
|
||||
@ -68,37 +68,37 @@ reset_extra_footer ()
|
||||
reset_extra_header
|
||||
reset_extra_footer
|
||||
|
||||
result_print ()
|
||||
result_print()
|
||||
{
|
||||
_passed="$1"
|
||||
_out="$2"
|
||||
_rc="$3"
|
||||
|
||||
if "$CTDB_TEST_VERBOSE" || ! $_passed ; then
|
||||
if "$CTDB_TEST_VERBOSE" || ! $_passed; then
|
||||
extra_header
|
||||
|
||||
cat <<EOF
|
||||
cat <<EOF
|
||||
--------------------------------------------------
|
||||
Output (Exit status: ${_rc}):
|
||||
--------------------------------------------------
|
||||
EOF
|
||||
# Avoid echo, which might expand unintentional escapes
|
||||
printf '%s\n' "$_out" | \
|
||||
result_filter | \
|
||||
printf '%s\n' "$_out" |
|
||||
result_filter |
|
||||
cat "${CTDB_TEST_CAT_RESULTS_OPTS:--}"
|
||||
fi
|
||||
|
||||
if ! $_passed ; then
|
||||
if ! $_passed; then
|
||||
cat <<EOF
|
||||
--------------------------------------------------
|
||||
Required output (Exit status: ${required_rc}):
|
||||
--------------------------------------------------
|
||||
EOF
|
||||
# Avoid echo, which might expand unintentional escapes
|
||||
printf '%s\n' "$required_output" | \
|
||||
printf '%s\n' "$required_output" |
|
||||
cat "${CTDB_TEST_CAT_RESULTS_OPTS:--}"
|
||||
|
||||
if $CTDB_TEST_DIFF_RESULTS ; then
|
||||
if $CTDB_TEST_DIFF_RESULTS; then
|
||||
_outr=$(mktemp)
|
||||
# Avoid echo, which might expand unintentional escapes
|
||||
printf '%s\n' "$required_output" >"$_outr"
|
||||
@ -118,15 +118,15 @@ EOF
|
||||
fi
|
||||
}
|
||||
|
||||
result_footer ()
|
||||
result_footer()
|
||||
{
|
||||
_passed="$1"
|
||||
|
||||
if "$CTDB_TEST_VERBOSE" || ! $_passed ; then
|
||||
if "$CTDB_TEST_VERBOSE" || ! $_passed; then
|
||||
extra_footer
|
||||
fi
|
||||
|
||||
if $_passed ; then
|
||||
if $_passed; then
|
||||
echo "PASSED"
|
||||
return 0
|
||||
else
|
||||
@ -140,7 +140,7 @@ result_footer ()
|
||||
# prefix on some CTDB tool/client log messages with the literal string
|
||||
# "DATE TIME [PID]". This allows tests to loosely match this output,
|
||||
# since it can't otherwise be matched.
|
||||
result_filter_default ()
|
||||
result_filter_default()
|
||||
{
|
||||
_date_time_pid='[0-9/][0-9/]*\ [0-9:\.][0-9:\.]*\ \[[\ 0-9][\ 0-9]*\]'
|
||||
sed -e "s@^${_date_time_pid}:@DATE\ TIME\ \[PID\]:@"
|
||||
@ -150,19 +150,20 @@ result_filter_default ()
|
||||
TEST_DATE_STAMP=""
|
||||
|
||||
# Override this function to customise output filtering.
|
||||
result_filter ()
|
||||
result_filter()
|
||||
{
|
||||
result_filter_default
|
||||
}
|
||||
|
||||
result_check ()
|
||||
result_check()
|
||||
{
|
||||
_rc=$?
|
||||
|
||||
# Avoid echo, which might expand unintentional escapes
|
||||
_fout=$(printf '%s\n' "$_out" | result_filter)
|
||||
|
||||
if [ "$_fout" = "$required_output" ] && [ "$_rc" = "$required_rc" ] ; then
|
||||
if [ "$_fout" = "$required_output" ] &&
|
||||
[ "$_rc" = "$required_rc" ]; then
|
||||
_passed=true
|
||||
else
|
||||
_passed=false
|
||||
@ -172,22 +173,22 @@ result_check ()
|
||||
result_footer "$_passed"
|
||||
}
|
||||
|
||||
test_fail ()
|
||||
test_fail()
|
||||
{
|
||||
_passed=false
|
||||
return 1
|
||||
}
|
||||
|
||||
test_header_default ()
|
||||
test_header_default()
|
||||
{
|
||||
echo "=================================================="
|
||||
echo "Running \"$*\""
|
||||
}
|
||||
|
||||
reset_test_header ()
|
||||
reset_test_header()
|
||||
{
|
||||
# Re-define this function to get different header
|
||||
test_header ()
|
||||
test_header()
|
||||
{
|
||||
test_header_default "$@"
|
||||
}
|
||||
@ -196,12 +197,12 @@ reset_test_header ()
|
||||
reset_test_header
|
||||
|
||||
# Simple test harness for running binary unit tests
|
||||
unit_test ()
|
||||
unit_test()
|
||||
{
|
||||
test_header "$@"
|
||||
|
||||
_wrapper="$VALGRIND"
|
||||
if $CTDB_TEST_COMMAND_TRACE ; then
|
||||
if $CTDB_TEST_COMMAND_TRACE; then
|
||||
_wrapper="strace"
|
||||
fi
|
||||
_out=$($_wrapper "$@" 2>&1)
|
||||
@ -210,12 +211,12 @@ unit_test ()
|
||||
}
|
||||
|
||||
# Simple test harness for running shell script unit tests
|
||||
script_test ()
|
||||
script_test()
|
||||
{
|
||||
test_header "$@"
|
||||
|
||||
_shell=""
|
||||
if ${CTDB_TEST_COMMAND_TRACE} ; then
|
||||
if ${CTDB_TEST_COMMAND_TRACE}; then
|
||||
_shell="sh -x"
|
||||
else
|
||||
_shell="sh"
|
||||
@ -227,7 +228,7 @@ script_test ()
|
||||
}
|
||||
|
||||
# Simple test harness for running tests without tracing
|
||||
unit_test_notrace ()
|
||||
unit_test_notrace()
|
||||
{
|
||||
test_header "$@"
|
||||
|
||||
@ -238,7 +239,7 @@ unit_test_notrace ()
|
||||
|
||||
test_cleanup_hooks=""
|
||||
|
||||
test_cleanup ()
|
||||
test_cleanup()
|
||||
{
|
||||
test_cleanup_hooks="${test_cleanup_hooks}${test_cleanup_hooks:+ ; }$*"
|
||||
}
|
||||
@ -246,6 +247,6 @@ test_cleanup ()
|
||||
trap 'eval $test_cleanup_hooks' 0
|
||||
|
||||
local="${CTDB_TEST_SUITE_DIR}/scripts/local.sh"
|
||||
if [ -r "$local" ] ; then
|
||||
if [ -r "$local" ]; then
|
||||
. "$local"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user