]>
Commit | Line | Data |
---|---|---|
759ed0a2 YW |
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 | local rc | |
8 | ||
9 | set +e | |
10 | "$@" | |
11 | rc=$? | |
12 | set -e | |
13 | if [[ "$rc" != "0" ]]; then | |
14 | echo "FAIL: command '$*' failed with exit code $rc" >&2 | |
15 | exit 1 | |
16 | fi | |
17 | } | |
18 | ||
19 | ||
20 | assert_eq() { | |
21 | if [[ "$1" != "$2" ]]; then | |
22 | echo "FAIL: expected: '$2' actual: '$1'" >&2 | |
23 | exit 1 | |
24 | fi | |
25 | } | |
26 | ||
27 | assert_in() { | |
28 | if ! echo "$2" | grep -q "$1"; then | |
29 | echo "FAIL: '$1' not found in:" >&2 | |
30 | echo "$2" >&2 | |
31 | exit 1 | |
32 | fi | |
33 | } | |
34 | ||
35 | assert_rc() { | |
36 | local exp=$1 | |
37 | local rc | |
38 | shift | |
39 | set +e | |
40 | "$@" | |
41 | rc=$? | |
42 | set -e | |
43 | assert_eq "$rc" "$exp" | |
44 | } |