]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: add a smoke test for --version option in binaries
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 5 Apr 2022 08:51:21 +0000 (10:51 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 5 Apr 2022 20:18:31 +0000 (22:18 +0200)
This is very similar to (and directly based on) the test for --help. I think
it's nice to do this: the test is very quick, but it'll catch cases where we
forgot to hook up the option, or forgot to exit after printing --version, and
it'll also increase our test coverage a bit.

meson.build
tools/check-help.sh
tools/check-version.sh [new file with mode: 0755]

index 0455d89b78c8c8c682f41d5037027908661d8cdc..c54acd0d049a0be322881e1153da4f8846ff9e3b 100644 (file)
@@ -3891,6 +3891,7 @@ endif
 ############################################################
 
 check_help = find_program('tools/check-help.sh')
+check_version = find_program('tools/check-version.sh')
 
 foreach exec : public_programs
         name = exec.full_path().split('/')[-1]
@@ -3899,6 +3900,12 @@ foreach exec : public_programs
                      check_help,
                      args : exec.full_path(),
                      depends: exec)
+
+                test('check-version-' + name,
+                     check_version,
+                     args : [exec.full_path(),
+                             meson.project_version()],
+                     depends: exec)
         endif
 endforeach
 
index 76ac2926750f9e00c01ecdfcd85e7d064a044ea0..19ec9414692b21d09710e6c2bc7e594044fcebbc 100755 (executable)
@@ -3,8 +3,8 @@
 set -eu
 set -o pipefail
 
-# Note: `grep ... >/dev/null` instead of just `grep -q` is used intentionally
-#       here, since `grep -q` exits on the first match causing SIGPIPE being
+# 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:?}"
@@ -24,11 +24,11 @@ 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."
+    echo "$(basename "$BINARY") --help output is empty"
     exit 2
 fi
 
-# no --help output to stdout
+# no --help output to stderr
 if "$BINARY" --help 2>&1 1>/dev/null | grep .; then
     echo "$(basename "$BINARY") --help prints to stderr"
     exit 3
diff --git a/tools/check-version.sh b/tools/check-version.sh
new file mode 100755 (executable)
index 0000000..faefb46
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eu
+set -o pipefail
+
+# 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:?}"
+VERSION="${2:?}"
+export SYSTEMD_LOG_LEVEL=info
+
+if [[ ! -x "$BINARY" ]]; then
+    echo "$BINARY is not an executable"
+    exit 1
+fi
+
+# --version prints something. Also catches case where args are ignored.
+if ! "$BINARY" --version | grep . >/dev/null; then
+    echo "$(basename "$BINARY") --version output is empty"
+    exit 2
+fi
+
+# no --version output to stderr
+if "$BINARY" --version 2>&1 1>/dev/null | grep .; then
+    echo "$(basename "$BINARY") --version prints to stderr"
+    exit 3
+fi
+
+# project version appears in version output
+out="$("$BINARY" --version)"
+if ! grep -F "$VERSION" >/dev/null <<<"$out"; then
+    echo "$(basename "$BINARY") --version output does not match '$VERSION': $out"
+    exit 4
+fi