2 # $Id: shunit2_test_macros.sh 299 2010-05-03 12:44:20Z kate.ward@forestent.com $
3 # vim:et:ft=sh:sts=2:sw=2
5 # Copyright 2008 Kate Ward. All Rights Reserved.
6 # Released under the LGPL (GNU Lesser General Public License)
7 # Author: kate.ward@forestent.com (Kate Ward)
9 # shUnit2 unit test for macros.
12 . ./shunit2_test_helpers
14 #------------------------------------------------------------------------------
20 # start skipping if LINENO not available
21 [ -z "${LINENO:-}" ] && startSkipping
23 ( ${_ASSERT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
24 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
26 assertTrue '_ASSERT_EQUALS_ failure' ${rtrn}
27 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
29 ( ${_ASSERT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
30 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
32 assertTrue '_ASSERT_EQUALS_ w/ msg failure' ${rtrn}
33 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
38 # start skipping if LINENO not available
39 [ -z "${LINENO:-}" ] && startSkipping
41 ( ${_ASSERT_NOT_EQUALS_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
42 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
44 assertTrue '_ASSERT_NOT_EQUALS_ failure' ${rtrn}
45 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
47 ( ${_ASSERT_NOT_EQUALS_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
48 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
50 assertTrue '_ASSERT_NOT_EQUALS_ w/ msg failure' ${rtrn}
51 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
56 # start skipping if LINENO not available
57 [ -z "${LINENO:-}" ] && startSkipping
59 ( ${_ASSERT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
60 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
62 assertTrue '_ASSERT_SAME_ failure' ${rtrn}
63 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
65 ( ${_ASSERT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
66 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
68 assertTrue '_ASSERT_SAME_ w/ msg failure' ${rtrn}
69 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
74 # start skipping if LINENO not available
75 [ -z "${LINENO:-}" ] && startSkipping
77 ( ${_ASSERT_NOT_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
78 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
80 assertTrue '_ASSERT_NOT_SAME_ failure' ${rtrn}
81 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
83 ( ${_ASSERT_NOT_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
84 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
86 assertTrue '_ASSERT_NOT_SAME_ w/ msg failure' ${rtrn}
87 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
92 # start skipping if LINENO not available
93 [ -z "${LINENO:-}" ] && startSkipping
95 ( ${_ASSERT_NULL_} 'x' >"${stdoutF}" 2>"${stderrF}" )
96 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
98 assertTrue '_ASSERT_NULL_ failure' ${rtrn}
99 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
101 ( ${_ASSERT_NULL_} '"some msg"' 'x' >"${stdoutF}" 2>"${stderrF}" )
102 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
104 assertTrue '_ASSERT_NULL_ w/ msg failure' ${rtrn}
105 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
110 # start skipping if LINENO not available
111 [ -z "${LINENO:-}" ] && startSkipping
113 ( ${_ASSERT_NOT_NULL_} '' >"${stdoutF}" 2>"${stderrF}" )
114 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
116 assertTrue '_ASSERT_NOT_NULL_ failure' ${rtrn}
117 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
119 ( ${_ASSERT_NOT_NULL_} '"some msg"' '""' >"${stdoutF}" 2>"${stderrF}" )
120 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
122 assertTrue '_ASSERT_NOT_NULL_ w/ msg failure' ${rtrn}
123 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stdoutF}" "${stderrF}" >&2
128 # start skipping if LINENO not available
129 [ -z "${LINENO:-}" ] && startSkipping
131 ( ${_ASSERT_TRUE_} ${SHUNIT_FALSE} >"${stdoutF}" 2>"${stderrF}" )
132 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
134 assertTrue '_ASSERT_TRUE_ failure' ${rtrn}
135 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
138 ( ${_ASSERT_TRUE_} '"some msg"' ${SHUNIT_FALSE} >"${stdoutF}" 2>"${stderrF}" )
139 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
141 assertTrue '_ASSERT_TRUE_ w/ msg failure' ${rtrn}
142 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
147 # start skipping if LINENO not available
148 [ -z "${LINENO:-}" ] && startSkipping
150 ( ${_ASSERT_FALSE_} ${SHUNIT_TRUE} >"${stdoutF}" 2>"${stderrF}" )
151 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
153 assertTrue '_ASSERT_FALSE_ failure' ${rtrn}
154 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
156 ( ${_ASSERT_FALSE_} '"some msg"' ${SHUNIT_TRUE} >"${stdoutF}" 2>"${stderrF}" )
157 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
159 assertTrue '_ASSERT_FALSE_ w/ msg failure' ${rtrn}
160 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
165 # start skipping if LINENO not available
166 [ -z "${LINENO:-}" ] && startSkipping
168 ( ${_FAIL_} >"${stdoutF}" 2>"${stderrF}" )
169 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
171 assertTrue '_FAIL_ failure' ${rtrn}
172 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
174 ( ${_FAIL_} '"some msg"' >"${stdoutF}" 2>"${stderrF}" )
175 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
177 assertTrue '_FAIL_ w/ msg failure' ${rtrn}
178 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
183 # start skipping if LINENO not available
184 [ -z "${LINENO:-}" ] && startSkipping
186 ( ${_FAIL_NOT_EQUALS_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
187 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
189 assertTrue '_FAIL_NOT_EQUALS_ failure' ${rtrn}
190 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
192 ( ${_FAIL_NOT_EQUALS_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
193 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
195 assertTrue '_FAIL_NOT_EQUALS_ w/ msg failure' ${rtrn}
196 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
201 # start skipping if LINENO not available
202 [ -z "${LINENO:-}" ] && startSkipping
204 ( ${_FAIL_SAME_} 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
205 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
207 assertTrue '_FAIL_SAME_ failure' ${rtrn}
208 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
210 ( ${_FAIL_SAME_} '"some msg"' 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
211 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
213 assertTrue '_FAIL_SAME_ w/ msg failure' ${rtrn}
214 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
219 # start skipping if LINENO not available
220 [ -z "${LINENO:-}" ] && startSkipping
222 ( ${_FAIL_NOT_SAME_} 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
223 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
225 assertTrue '_FAIL_NOT_SAME_ failure' ${rtrn}
226 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
228 ( ${_FAIL_NOT_SAME_} '"some msg"' 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
229 grep '^ASSERT:\[[0-9]*\] *' "${stdoutF}" >/dev/null
231 assertTrue '_FAIL_NOT_SAME_ w/ msg failure' ${rtrn}
232 [ ${rtrn} -ne ${SHUNIT_TRUE} ] && cat "${stderrF}" >&2
235 #------------------------------------------------------------------------------
241 tmpDir="${__shunit_tmpDir}/output"
243 stdoutF="${tmpDir}/stdout"
244 stderrF="${tmpDir}/stderr"
247 # load and run shUnit2
248 [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0