-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubtest.subr
57 lines (49 loc) · 1.66 KB
/
subtest.subr
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
# subtest.subr
# Test plan
# By J. Stuart McMurray
# Created 20241105
# Last Modified 20250202
# tap_subtest runs a subtest, which should normally be its own function
# i.e. mysubtest() { tap_... }; tap_subtest "foo" mysubtest.
# The subtest function should return 0 on success.
# See examples/subtest.sh for an example.
#
# $1 - Subtest name for TAP output
# $2 - Subtest function name
# $3 - Test file (optional)
# $4 - Test line (optional)
tap_subtest() {
# Don't do anything if we've bailed.
if [ -n "${_tap_bailo}" ]; then
return
fi
# Make sure we have at least a test and a name.
if [ 2 -gt $# ]; then
echo "Need a subtest and a test name" >&2
return $TAP_RETURN_NOT_ENOUGH_ARGUMENTS
fi
# Note we're running a subtest
tap_note "Subtest: $1"
# Run the subtest with extra spaces
_tap_ret=0
(
trap tap_done_testing EXIT
_tap_save_space=${_tap_space}
tap_reset
_tap_space=" ${_tap_save_space}"
_tap_save_space=
"$2"
RET=$?
tap_done_testing && exit "$RET"
) || _tap_ret=$?
# If we've bailed, note it for the rest of testing. There's no really
# good way to pass things back from subshells.
if [ -z "$_tap_bailo" ] && \
[ $TAP_RETURN_BAILED_OUT -eq ${_tap_ret} ]; then
_tap_bailo="Bailed in subtest $2"
return
fi
# Emit the ok/not ok message and note success/fail.
tap_ok "${_tap_ret}" "$1" "$3" "$4"
}
# vim: ft=sh