summaryrefslogtreecommitdiffstats
path: root/test/units/util.sh
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2023-06-27 16:15:24 +0200
committerFrantisek Sumsal <frantisek@sumsal.cz>2023-06-28 11:07:46 +0200
commit1a36d2672f32fbbc695e77e12dfa43b646243d63 (patch)
treecd3a623997b9c5667e822b4bceecfc8a4bf71aad /test/units/util.sh
parenttest: fix test service unit description (diff)
downloadsystemd-1a36d2672f32fbbc695e77e12dfa43b646243d63.tar.xz
systemd-1a36d2672f32fbbc695e77e12dfa43b646243d63.zip
test: add a couple of tests for nss-myhostname
Diffstat (limited to 'test/units/util.sh')
-rwxr-xr-xtest/units/util.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/units/util.sh b/test/units/util.sh
index fdba709734..932fe1e603 100755
--- a/test/units/util.sh
+++ b/test/units/util.sh
@@ -57,6 +57,45 @@ assert_rc() {(
assert_eq "$rc" "$exp"
)}
+run_and_grep() {(
+ set +ex
+
+ local expression
+ local log ec
+ local exp_ec=0
+
+ # Invert the grep condition - i.e. check if the expression is _not_ in command's output
+ if [[ "${1:?}" == "-n" ]]; then
+ exp_ec=1
+ shift
+ fi
+
+ expression="${1:?}"
+ shift
+
+ if [[ $# -eq 0 ]]; then
+ echo >&2 "FAIL: Not enough arguments for ${FUNCNAME[0]}()"
+ return 1
+ fi
+
+ log="$(mktemp)"
+ if ! "$@" |& tee "${log:?}"; then
+ echo >&2 "FAIL: Command '$*' failed"
+ return 1
+ fi
+
+ grep -qE "$expression" "$log" && ec=0 || ec=$?
+ if [[ "$exp_ec" -eq 0 && "$ec" -ne 0 ]]; then
+ echo >&2 "FAIL: Expression '$expression' not found in the output of '$*'"
+ return 1
+ elif [[ "$exp_ec" -ne 0 && "$ec" -eq 0 ]]; then
+ echo >&2 "FAIL: Expression '$expression' found in the output of '$*'"
+ return 1
+ fi
+
+ rm -f "$log"
+)}
+
get_cgroup_hierarchy() {
case "$(stat -c '%T' -f /sys/fs/cgroup)" in
cgroup2fs)