-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtestt.sh
More file actions
173 lines (142 loc) · 4.99 KB
/
Copy pathtestt.sh
File metadata and controls
173 lines (142 loc) · 4.99 KB
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
#!/bin/bash
#
# https://github.com/EngineeringSoftware/gobash/blob/main/LICENSE
#
# Test object (one object given as the first argument to test.)
if [ -n "${TESTT_MOD:-}" ]; then return 0; fi
readonly TESTT_MOD=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# ----------
# Functions.
function TestT() {
# Test object (one object given as an argument to each test).
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 2 ] && { ctx_wn $ctx; return $EC; }
local -r file="${1}"
local -r name="${2}"
shift 2 || { ctx_wn $ctx; return $EC; }
make_ $ctx \
"${FUNCNAME}" \
"_name" "${name}" \
"_file" "${file}" \
"_skip" "$FALSE" \
"_failed" "$FALSE" \
"_msg" "" \
"_btime" 0 \
"_etime" 0
}
function TestT_file() {
# Return test script name.
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
$testt $ctx _file
}
function TestT_msg() {
# Return message stored in this object.
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
$testt $ctx _msg
}
function TestT_name() {
# Return test name.
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
$testt $ctx _name
}
function TestT_skip() {
# Skip the test (and store the message).
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -lt 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
local -r msg="${2}"
shift 1 || { ctx_wn $ctx; return $EC; }
$testt $ctx _msg "${msg}"
$testt $ctx skip_now
}
function TestT_skip_now() {
# Skip the test and stop its execution by calling exit 0
# (which will not stop any sub process that was started).
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
$testt $ctx _skip $TRUE
exit 0
}
function TestT_fail() {
# Mark the test as failing and continue the execution.
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -lt 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
local -r msg="${2}"
shift 1 || { ctx_wn $ctx; return $EC; }
$testt $ctx _failed $TRUE
$testt $ctx _msg "${msg}"
}
function TestT_fail_now() {
# Mark the test as failing and exit 1 (which will not stop any
# sub process that was started).
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
$testt $ctx _failed $TRUE
exit 1
}
function TestT_timeout() {
# Mark the test as timeout.
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
$testt $ctx _failed $TRUE
$testt $ctx _msg "Timeout."
}
function TestT_skipped() {
# Check if test is skipped.
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
# If failed, then not counted as skipped.
$testt $ctx failed && return $FALSE
is_true $ctx $($testt $ctx _skip)
}
function TestT_failed() {
# Check if test failed.
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
is_true $ctx $($testt $ctx _failed)
}
function TestT_duration() {
# Return duration of the test (ms).
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
local duration=$(( $($testt $ctx _etime) - $($testt $ctx _btime) ))
echo "${duration}"
}
function TestT_to_string() {
# String representation of this test.
local ctx; is_ctx "${1}" && ctx="${1}" && shift
[ $# -ne 1 ] && { ctx_wn $ctx; return $EC; }
local -r testt="${1}"
shift 1 || { ctx_wn $ctx; return $EC; }
local outcome
if $testt $ctx failed; then
outcome="FAILED"
elif $testt $ctx skipped; then
outcome="SKIPPED"
else
outcome="PASSED"
fi
echo "$($testt $ctx _name) ${outcome}"
}