/
apron-assert
60 lines (50 loc) · 1.13 KB
/
apron-assert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#
# these are written strangely because all APRON_assert_*
# functions are run with an error trap. We want to make
# sure the trap is triggered on error.
#
#
# Numeric assertions
#
APRON_assert_eq() {
(( $1 == $2 ))
(( $? )) && printf 'Assertion failed: %d == %d\n' "$1" "$2"
}
APRON_assert_ne() {
(( $1 != $2 ))
(( $? )) && printf 'Assertion failed: %d != %d\n' "$1" "$2"
}
APRON_assert_lt() {
(( $1 < $2 ))
(( $? )) && printf 'Assertion failed: %d < %d\n' "$1" "$2"
}
APRON_assert_le() {
(( $1 <= $2 ))
(( $? )) && printf 'Assertion failed: %d <= %d\n' "$1" "$2"
}
APRON_assert_gt() {
(( $1 > $2 ))
(( $? )) && printf 'Assertion failed: %d > %d\n' "$1" "$2"
}
APRON_assert_ge() {
(( $1 >= $2 ))
(( $? )) && printf 'Assertion failed: %d >= %d\n' "$1" "$2"
}
#
# String based assertions
#
APRON_assert_streq() {
[[ $1 == "$2" ]]
(( $? )) && printf 'Assertion failed: "%s" != "%s"\n' "$1" "$2"
}
APRON_assert_in() {
for i in "${@:2}"; do
if [[ $1 = "$i" ]]; then
return 0
fi
done
false
printf 'Assertion failed: "%s" not found in: %s\n' "$1" "${*:2}"
}
# vim: set ft=sh et ts=2 sw=2: