File tree 2 files changed +51
-0
lines changed
2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ __assert ()
3
+ {
4
+ E_PARAM_ERR=98
5
+ E_ASSERT_FAILED=99
6
+
7
+ lineno=` caller 1`
8
+
9
+ if [[ $# < 3 || $# > 4 ]]
10
+ then
11
+ num=` expr $# - 1`
12
+ >&2 echo " ERR: assert require 2 or 3 params, got $num "
13
+ return $E_PARAM_ERR
14
+ fi
15
+
16
+ cmd=" \" $2 \" == \" $3 \" "
17
+
18
+ if [ $# -eq 3 ]; then
19
+ if [ " $2 " == " $3 " ]
20
+ then
21
+ success=" true"
22
+ else
23
+ success=" false"
24
+ fi
25
+ fi
26
+
27
+ if [ " $success " != " $1 " ]
28
+ then
29
+ >&2 printf " \e[91m---=== ASSERTION FAILED ===---\n$cmd \n"
30
+ >&2 printf " File \" $0 \" , line $lineno \e[39m\n\n"
31
+ return $E_ASSERT_FAILED
32
+ fi
33
+ }
34
+
35
+ assert () {
36
+ __assert " true" " $@ " ;
37
+ return $?
38
+ }
39
+
40
+ assert_fail () {
41
+ __assert " false" " $@ " ;
42
+ return $?
43
+ }
Original file line number Diff line number Diff line change
1
+ source ./assert.sh
2
+
3
+ # The following test should work, since our incorrect assertion is ignored
4
+ ../testbin/asserttest-ndebug
5
+ assert " $? " " 0"
6
+ # The following test should fail, as it's testing that sydlibc assert works
7
+ ../testbin/asserttest
8
+ assert_fail " $? " " 0"
You can’t perform that action at this time.
0 commit comments