Debian Codegraph @

test/common

raw
1 #!/bin/bash
2
3 fail=0
4 testcount=0
5
6 EXPECT_success() {
7 (( ++testcount ))
8 if ! "$@"; then
9 (( ++fail ))
10 printf 'expectation failed: did not succeed: %s\n' "$*" >&2
11 fi
12 }
13
14 EXPECT_failure() {
15 (( ++testcount ))
16 if "$@"; then
17 (( ++fail ))
18 printf 'expectation failed: did not fail: %s\n' "$*" >&2
19 fi
20 }
21
22 TEST_exit() {
23 local result
24
25 trap -- EXIT
26
27 (( fail == 0 )) && result=PASS || result=FAIL
28
29 printf '%s: %s\n' "$result" "$1"
30
31 exit $(( fail != 0 ))
32 }
33
34 ASSERT_streq() {
35 if [[ $1 != "$2" ]]; then
36 printf 'assertion failed [line %d]: [[ %s = "%s" ]]\n' "$BASH_LINENO" "$1" "$2" >&2
37 fi
38 }
39
40 TEST_start() {
41 trap "TEST_exit '$1'" EXIT
42 }
43
44 TEST_start "${0##*/test_}"
45