@@ -46,6 +46,42 @@ teardown(){
4646 assert_failure
4747}
4848
49+ @test " is_num fails with no arguments" {
50+ run is_num
51+ assert_output " "
52+ assert_failure
53+ }
54+
55+ @test " is_num fails with alphabetical input" {
56+ run is_num foo
57+ assert_output " "
58+ assert_failure
59+ }
60+
61+ @test " is_num suceeds with integer" {
62+ run is_num foo
63+ assert_output 123
64+ assert_success
65+ }
66+
67+ @test " is_num suceeds with negative integer" {
68+ run is_num foo
69+ assert_output -123
70+ assert_success
71+ }
72+
73+ @test " is_num suceeds with float" {
74+ run is_num foo
75+ assert_output 123.4
76+ assert_success
77+ }
78+
79+ @test " is_num suceeds with negative float" {
80+ run is_num foo
81+ assert_output -123.4
82+ assert_success
83+ }
84+
4985@test " retry runs command only once if it succeeds the first time" {
5086 retryme (){
5187 date >> ${afile}
@@ -116,3 +152,87 @@ teardown(){
116152 assert_success
117153 assert_equal $( wc -l < ${afile} ) 1
118154}
155+
156+
157+
158+
159+ # ***************
160+
161+
162+ @test " retry_constant runs command only once if it succeeds the first time" {
163+ retry_me (){
164+ date >> ${afile}
165+ }
166+ run retry_constant 3 1 retry_me
167+ assert_success
168+ assert_equal $( wc -l < ${afile} ) 1
169+ }
170+
171+ @test " retry_constant doesn't introduce delay when the command succeeds first time" {
172+ retry_me (){
173+ date >> ${afile}
174+ }
175+ start=$( date +%s)
176+ run retry_constant 3 10 retry_me
177+ end=$( date +%s)
178+ assert [ " $(( start + 1 )) " -ge " ${end} " ]
179+ assert_success
180+ }
181+
182+ @test " retry_constant runs n times on consecutive failure and waits between attempts" {
183+ retry_me (){
184+ date >> ${afile}
185+ false
186+ }
187+ start=$( date +%s)
188+ run retry_constant 2 1 retry_me
189+ end=$( date +%s)
190+ # introduces at least a two second delay between attempts
191+ assert [ " $(( start + 2 )) " -le " ${end} " ]
192+ assert_failure
193+ assert_equal $( wc -l < ${afile} ) 2
194+ }
195+
196+ @test " retry_constant returns after first success" {
197+ retry_me (){
198+ date >> " ${afile} "
199+ case $( wc -l < ${afile} ) in
200+ * 1)
201+ return 1
202+ ;;
203+ * )
204+ return 0
205+ ;;
206+ esac
207+ }
208+ run retry_constant 3 1 retry_me
209+ assert_success
210+ assert_equal $( wc -l < ${afile} ) 2
211+ }
212+
213+ @test " retry_constant fails with less than three arguments" {
214+ run retry_constant 3 1
215+ assert_failure
216+ assert_output --partial usage
217+ assert [ ! -e " ${temp_dir} /appendfile" ]
218+ }
219+
220+ @test " retry_constant fails with non-integer retry count" {
221+ run retry_constant " this" 1 date
222+ assert_failure
223+ assert_output --partial number
224+ assert [ ! -e " ${temp_dir} /appendfile" ]
225+ }
226+
227+ @test " retry_constant fails with non-integer interval" {
228+ run retry_constant 2 " this" date
229+ assert_failure
230+ assert_output --partial interval
231+ assert [ ! -e " ${temp_dir} /appendfile" ]
232+ }
233+
234+ @test " retry_constant succeeds with compound statements" {
235+ run retry_constant 3 1 " true && date >> ${afile} "
236+ assert_success
237+ assert_equal $( wc -l < ${afile} ) 1
238+ }
0 commit comments