1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00
systemd-stable/tools/check-help.sh

42 lines
1.2 KiB
Bash
Raw Normal View History

#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
2017-12-24 09:53:20 +03:00
set -eu
set -o pipefail
2017-04-13 18:52:05 +03:00
# Note: `grep ... >/dev/null` instead of just `grep -q` is used intentionally
# here, since `grep -q` exits on the first match causing SIGPIPE being
# sent to the sender.
BINARY="${1:?}"
export SYSTEMD_LOG_LEVEL=info
if [[ ! -x "$BINARY" ]]; then
echo "$BINARY is not an executable"
exit 1
fi
2017-04-13 18:52:05 +03:00
# output width
if "$BINARY" --help | grep -v 'default:' | grep -E '.{80}.' >/dev/null; then
echo "$(basename "$BINARY") --help output is too wide:"
"$BINARY" --help | awk 'length > 80' | grep -E --color=yes '.{80}'
exit 1
2017-04-13 18:52:05 +03:00
fi
# --help prints something. Also catches case where args are ignored.
if ! "$BINARY" --help | grep . >/dev/null; then
echo "$(basename "$BINARY") --help output is empty."
exit 2
fi
2017-04-13 18:52:05 +03:00
# no --help output to stdout
if "$BINARY" --help 2>&1 1>/dev/null | grep .; then
echo "$(basename "$BINARY") --help prints to stderr"
exit 3
2017-04-13 18:52:05 +03:00
fi
# error output to stderr
if ! ("$BINARY" --no-such-parameter 2>&1 1>/dev/null || :) | grep . >/dev/null; then
echo "$(basename "$BINARY") with an unknown parameter does not print to stderr"
exit 4
2017-04-13 18:52:05 +03:00
fi