bringing in testkit tools
[feisty_meow.git] / testkit / shunit / shunit2_test_failures.sh
1 #! /bin/sh
2 # $Id: shunit2_test_failures.sh 286 2008-11-24 21:42:34Z kate.ward@forestent.com $
3 # vim:et:ft=sh:sts=2:sw=2
4 #
5 # Copyright 2008 Kate Ward. All Rights Reserved.
6 # Released under the LGPL (GNU Lesser General Public License)
7 #
8 # Author: kate.ward@forestent.com (Kate Ward)
9 #
10 # shUnit2 unit test for failure functions
11
12 # load common unit-test functions
13 . ./shunit2_test_helpers
14
15 #-----------------------------------------------------------------------------
16 # suite tests
17 #
18
19 testFail()
20 {
21   ( fail >"${stdoutF}" 2>"${stderrF}" )
22   th_assertFalseWithOutput 'fail' $? "${stdoutF}" "${stderrF}"
23
24   ( fail "${MSG}" >"${stdoutF}" 2>"${stderrF}" )
25   th_assertFalseWithOutput 'fail with msg' $? "${stdoutF}" "${stderrF}"
26
27   ( fail arg1 >"${stdoutF}" 2>"${stderrF}" )
28   th_assertFalseWithOutput 'too many arguments' $? "${stdoutF}" "${stderrF}"
29 }
30
31 testFailNotEquals()
32 {
33   ( failNotEquals 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
34   th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}"
35
36   ( failNotEquals "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
37   th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}"
38
39   ( failNotEquals 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
40   th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}"
41
42   ( failNotEquals '' '' >"${stdoutF}" 2>"${stderrF}" )
43   th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}"
44
45   ( failNotEquals >"${stdoutF}" 2>"${stderrF}" )
46   th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
47
48   ( failNotEquals arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
49   th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
50 }
51
52 testFailSame()
53 {
54   ( failSame 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
55   th_assertFalseWithOutput 'same' $? "${stdoutF}" "${stderrF}"
56
57   ( failSame "${MSG}" 'x' 'x' >"${stdoutF}" 2>"${stderrF}" )
58   th_assertFalseWithOutput 'same with msg' $? "${stdoutF}" "${stderrF}"
59
60   ( failSame 'x' 'y' >"${stdoutF}" 2>"${stderrF}" )
61   th_assertFalseWithOutput 'not same' $? "${stdoutF}" "${stderrF}"
62
63   ( failSame '' '' >"${stdoutF}" 2>"${stderrF}" )
64   th_assertFalseWithOutput 'null values' $? "${stdoutF}" "${stderrF}"
65
66   ( failSame >"${stdoutF}" 2>"${stderrF}" )
67   th_assertFalseWithError 'too few arguments' $? "${stdoutF}" "${stderrF}"
68
69   ( failSame arg1 arg2 arg3 arg4 >"${stdoutF}" 2>"${stderrF}" )
70   th_assertFalseWithError 'too many arguments' $? "${stdoutF}" "${stderrF}"
71 }
72
73 #-----------------------------------------------------------------------------
74 # suite functions
75 #
76
77 oneTimeSetUp()
78 {
79   tmpDir="${__shunit_tmpDir}/output"
80   mkdir "${tmpDir}"
81   stdoutF="${tmpDir}/stdout"
82   stderrF="${tmpDir}/stderr"
83
84   MSG='This is a test message'
85 }
86
87 # load and run shUnit2
88 [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
89 . ${TH_SHUNIT}