@@ -62,8 +62,8 @@ assert_argc_psst()
62
62
63
63
if [ $# -ne 3 ]
64
64
then
65
- printf " Assertion fail : Function %s expects %s arguments, got %s!\n" \
66
- assert_argc_psst 3 $# >&2
65
+ printf " %s : Function \" %s \" expects %s arguments, got %s!\n" \
66
+ " Assertion fail " assert_argc_psst 3 $# >&2
67
67
exit 127
68
68
fi
69
69
@@ -73,8 +73,8 @@ assert_argc_psst()
73
73
74
74
if [ " $2 " -ne " $3 " ]
75
75
then
76
- printf " Assertion fail : Function %s expects %s arguments, got %s!\n" \
77
- " $@ " >&2
76
+ printf " %s : Function \" %s \" expects %s arguments, got %s!\n" \
77
+ " Assertion fail " " $@ " >&2
78
78
exit 127
79
79
fi
80
80
}
@@ -111,7 +111,7 @@ assert_minargc_psst()
111
111
112
112
if [ " $2 " -gt " $3 " ]
113
113
then
114
- printf " %s: Function %s expects at least %s arguments, got %s!\n" \
114
+ printf " %s: Function \" %s \" expects at least %s arguments, got %s!\n" \
115
115
" Assertion fail" " $@ " >&2
116
116
exit 127
117
117
fi
@@ -149,7 +149,7 @@ assert_maxargc_psst()
149
149
150
150
if [ " $2 " -lt " $3 " ]
151
151
then
152
- printf " %s: Function %s expects at most %s arguments, got %s!\n" \
152
+ printf " %s: Function \" %s \" expects at most %s arguments, got %s!\n" \
153
153
" Assertion fail" " $@ " >&2
154
154
exit 127
155
155
fi
@@ -203,3 +203,31 @@ assert_hasarg_psst()
203
203
fi
204
204
return
205
205
}
206
+
207
+
208
+
209
+ # #
210
+ # FUNCTION
211
+ # assert_func_fail_psst <func> <msg>
212
+ #
213
+ # SUMMARY
214
+ # Prints `msg` to stderr and terminates current process with error 127,
215
+ # which is the highest possible error as values 128 and up are reserved
216
+ # for signals and lower values are used by functions as failure indicators.
217
+ #
218
+ # PARAMETERS
219
+ # msg: Message to print to stderr.
220
+ #
221
+ # SAMPLE
222
+ # [ "$index" -gt 0 ] || assert_func_fail_psst "$func" "Index must be > 0"
223
+ #
224
+ assert_func_fail_psst ()
225
+ {
226
+ # We cannot use a subshell for this function as we need to exit the main
227
+ # shell in case an assertion is thrown. Thus we need to be careful to not
228
+ # conflict when defining local variables.
229
+
230
+ # func=$1
231
+ # msg=$2
232
+ assert_fail_psst " Assertion in \" $1 \" failed: $2 "
233
+ }
0 commit comments