Skip to content

Commit a9b82ce

Browse files
committed
Script to run all tests
1 parent 6cd0252 commit a9b82ce

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/assert.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

tests/test.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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"

0 commit comments

Comments
 (0)