-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshunit2.assert.command-test
executable file
·210 lines (177 loc) · 5.13 KB
/
shunit2.assert.command-test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env bash
# file: shunit2.assert.command.sh
COMMAND_TEST_OUTPUT=''
COMMAND_TEST_RETURN=''
commandTest() {
local COMMAND="$1"
COMMAND_TEST_OUTPUT="$(eval ${COMMAND})"
COMMAND_TEST_RETURN="$?"
}
assertCommandReturnEquals() {
local MESSAGE EXPECTED
${_SHUNIT_LINENO_}
if command [ $# -lt 1 -o $# -gt 2 ]; then
_shunit_error "assertCommandReturnEquals() requires one or two arguments; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 2 ];then
MESSAGE="$1"
shift
fi
EXPECTED="$1"
assertEquals \
"${MESSAGE:-Command Test return code did not capture expected code}" \
"${EXPECTED}" \
"${COMMAND_TEST_RETURN}"
}
assertCommandReturnNotEquals() {
local MESSAGE EXPECTED
${_SHUNIT_LINENO_}
if command [ $# -lt 1 -o $# -gt 2 ]; then
_shunit_error "assertCommandReturnNotEquals() requires one or two arguments; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 2 ];then
MESSAGE="$1"
shift
fi
EXPECTED="$1"
assertNotEquals \
"${MESSAGE:-Command Test return code captured unexpected code}" \
"${EXPECTED}" \
"${COMMAND_TEST_RETURN}"
}
assertCommandReturnTrue() {
local MESSAGE
${_SHUNIT_LINENO_}
if command [ $# -gt 1 ]; then
_shunit_error "assertCommandReturnTrue() requires zero or one argument; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 1 ];then
MESSAGE="$1"
fi
assertTrue \
"${MESSAGE:-Command Test return code did not capture true code}" \
"${COMMAND_TEST_RETURN}"
}
assertCommandReturnFalse() {
local MESSAGE
${_SHUNIT_LINENO_}
if command [ $# -gt 1 ]; then
_shunit_error "assertCommandReturnFalse() requires zero or one argument; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 1 ];then
MESSAGE="$1"
fi
assertFalse \
"${MESSAGE:-Command Test return code did not capture false code}" \
"${COMMAND_TEST_RETURN}"
}
assertCommandOutputEquals() {
local MESSAGE EXPECTED
${_SHUNIT_LINENO_}
if command [ $# -lt 1 -o $# -gt 2 ]; then
_shunit_error "assertCommandOutputEquals() requires one or two arguments; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 2 ];then
MESSAGE="$1"
shift
fi
EXPECTED="$1"
assertEquals \
"${MESSAGE:-Command Test did not capture expected output string}" \
"${EXPECTED}" \
"${COMMAND_TEST_OUTPUT}"
}
assertCommandOutputNotEquals() {
local MESSAGE EXPECTED
${_SHUNIT_LINENO_}
if command [ $# -lt 1 -o $# -gt 2 ]; then
_shunit_error "assertCommandOutputNotEquals() requires one or two arguments; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 2 ];then
MESSAGE="$1"
shift
fi
EXPECTED="$1"
assertNotEquals \
"${MESSAGE:-Command Test captured unexpected output string}" \
"${EXPECTED}" \
"${COMMAND_TEST_OUTPUT}"
}
assertCommandOutputContains() {
local MESSAGE CONTAINS
${_SHUNIT_LINENO_}
if command [ $# -lt 1 -o $# -gt 2 ]; then
_shunit_error "assertCommandOutputContains() requires one or two arguments; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 2 ];then
MESSAGE="$1"
shift
fi
CONTAINS="$1"
assertContains \
"${MESSAGE:-Command Test did not capture expected output string}" \
"${COMMAND_TEST_OUTPUT}" \
"${CONTAINS}"
}
assertCommandOutputNotContains() {
local MESSAGE CONTAINS
${_SHUNIT_LINENO_}
if command [ $# -lt 1 -o $# -gt 2 ]; then
_shunit_error "assertCommandOutputNotContains() requires one or two arguments; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 2 ];then
MESSAGE="$1"
shift
fi
CONTAINS="$1"
assertNotContains \
"${MESSAGE:-Command Test captured unexpected output string}" \
"${COMMAND_TEST_OUTPUT}" \
"${CONTAINS}"
}
assertCommandOutputNull() {
local MESSAGE
${_SHUNIT_LINENO_}
if command [ $# -gt 1 ]; then
_shunit_error "assertCommandOutputNull() requires zero or one argument; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 1 ];then
MESSAGE="$1"
fi
assertNull \
"${MESSAGE:-Command Test did not capture expected empty string}" \
"${COMMAND_TEST_OUTPUT}"
}
assertCommandOutputNotNull() {
local MESSAGE
${_SHUNIT_LINENO_}
if command [ $# -gt 1 ]; then
_shunit_error "assertCommandOutputNotNull() requires zero or one argument; $# given"
_shunit_assertFail
return ${SHUNIT_ERROR}
fi
if command [ $# -eq 1 ];then
MESSAGE="$1"
fi
assertNotNull \
"${MESSAGE:-Command Test captured unexpected empty string}" \
"${COMMAND_TEST_OUTPUT}"
}