72c48749feb6e64469f66a85804daef1b67cc87f
[project/uci.git] / tests / shunit2 / tests.sh
1 #!/bin/sh
2
3 TESTS_DIR="./tests"
4 CONFIG_DIR=${TESTS_DIR}"/config"
5 CHANGES_DIR="/tmp/.uci"
6 TMP_DIR=${TESTS_DIR}"/tmp"
7 FULL_SUITE=${TESTS_DIR}"/full_suite.sh"
8
9 UCI_BIN=${UCI_BIN:-"../uci"}
10 [ -x "$UCI_BIN" ] || {
11 echo "uci is not present." >&2
12 return 1
13 }
14 UCI="${UCI_BIN} -c ${CONFIG_DIR} -p ${CHANGES_DIR}"
15 UCI_Q="${UCI_BIN} -c ${CONFIG_DIR} -p ${CHANGES_DIR} -q"
16
17 REF_DIR="./references"
18 SCRIPTS_DIR="./tests.d"
19 DO_TEST="./shunit2/shunit2"
20
21 rm -rf ${TESTS_DIR}
22 mkdir -p ${TESTS_DIR}
23
24 cat << 'EOF' > ${FULL_SUITE}
25 setUp() {
26 mkdir -p ${CONFIG_DIR} ${CHANGES_DIR} ${TMP_DIR}
27 }
28 tearDown() {
29 rm -rf ${CONFIG_DIR} ${CHANGES_DIR} ${TMP_DIR}
30 }
31 assertSameFile() {
32 local ref=$1
33 local test=$2
34 diff -qr $ref $test
35 assertTrue $? || {
36 echo "REF:"
37 cat $ref
38 echo "----"
39 echo "TEST:"
40 cat $test
41 echo "----"
42 }
43 }
44 assertNotSegFault()
45 {
46 [ $1 -eq 139 ] && fail "Returned with 139: segmentation fault (SIGSEGV)!!!"
47 }
48 assertNotIllegal()
49 {
50 [ $1 -eq 132 ] && fail "Returned with 132: Illegal instruction (SIGILL)!!!"
51 }
52 assertFailWithNoReturn() {
53 local test="$1"
54 value=$( $test )
55 rv=$?
56 assertFalse "'$test' does not fail" $rv
57 assertNotSegFault $rv
58 assertNotIllegal $rv
59 assertNull "'$test' returns '$value'" "$value"
60 }
61 EOF
62
63 for suite in "${SCRIPTS_DIR}"/*
64 do
65 cat "${suite}" >> ${FULL_SUITE}
66 done
67
68 echo ". ${DO_TEST}" >> ${FULL_SUITE}
69
70 REF_DIR="${REF_DIR}" \
71 CONFIG_DIR="${CONFIG_DIR}" \
72 CHANGES_DIR="${CHANGES_DIR}" \
73 TMP_DIR="${TMP_DIR}" \
74 UCI="${UCI}" \
75 UCI_Q="${UCI_Q}" \
76 /bin/sh ${FULL_SUITE}
77
78 rm -rf ${TESTS_DIR}