]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/assert.sh
Merge pull request #23653 from aafeijoo-suse/ask-for-recovery-key
[thirdparty/systemd.git] / test / units / assert.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 # utility functions for shell tests
5
6 assert_true() {(
7 set +ex
8
9 local rc
10
11 "$@"
12 rc=$?
13 if [[ $rc -ne 0 ]]; then
14 echo "FAIL: command '$*' failed with exit code $rc" >&2
15 exit 1
16 fi
17 )}
18
19
20 assert_eq() {(
21 set +ex
22
23 if [[ "${1?}" != "${2?}" ]]; then
24 echo "FAIL: expected: '$2' actual: '$1'" >&2
25 exit 1
26 fi
27 )}
28
29 assert_in() {(
30 set +ex
31
32 if ! [[ "${2?}" =~ ${1?} ]]; then
33 echo "FAIL: '$1' not found in:" >&2
34 echo "$2" >&2
35 exit 1
36 fi
37 )}
38
39 assert_not_in() {(
40 set +ex
41
42 if [[ "${2?}" =~ ${1?} ]]; then
43 echo "FAIL: '$1' found in:" >&2
44 echo "$2" >&2
45 exit 1
46 fi
47 )}
48
49 assert_rc() {(
50 set +ex
51
52 local rc exp="${1?}"
53
54 shift
55 "$@"
56 rc=$?
57 assert_eq "$rc" "$exp"
58 )}