-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbright-test.bash
executable file
·162 lines (119 loc) · 3.7 KB
/
bright-test.bash
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
#!/bin/bash
##
## This file is part of the `src-run/bash-bright-library` package.
##
## (c) Rob Frawley 2nd <[email protected]>
##
## For the full copyright and license information, view the LICENSE.md
## file distributed with this source code.
##
# SC2086: Ignore warnings about missing double quotes to prevent word splitting. (intended)
# SC2155: Ignore warnings about separate declare/assign to not mask return values. (intended)
# shellcheck disable=SC2086
# shellcheck disable=SC2155
#
# resolve test root directory path
#
declare -r _TEST_ROOT_PATH="$(cd "$(dirname "$(
readlink -e "${BASH_SOURCE[0]}" 2> /dev/null
)" 2> /dev/null)" &> /dev/null && pwd 2> /dev/null)"
#
# include test configuration, test subroutines, and the bright library itself
#
# shellcheck source=test/_bright-test-cfg.bash
source "${_TEST_ROOT_PATH:-.}/_bright-test-cfg.bash"
# shellcheck source=test/_bright-test-sub.bash
source "${_TEST_ROOT_PATH:-.}/_bright-test-sub.bash"
# shellcheck source=test/_bright-test-lib.bash
source "${_TEST_ROOT_PATH:-.}/_bright-test-lib.bash"
#
# test ANSI escape codes: style (uninterpreted return values)
#
test_return_style() {
for key in "${!_CODES_STYLE[@]}"; do
_assertSameAnsiReturn style "${key}" "${_CODES_STYLE[${key}]}"
done
}
#
# test ANSI escape codes: style (interpreted output values)
#
test_output_style() {
for key in "${!_CODES_STYLE[@]}"; do
_assertSameAnsiOutput style "${key}" "${_CODES_STYLE[${key}]}"
done
}
#
# test ANSI escape codes: reset (uninterpreted return values)
#
test_return_reset() {
for key in "${!_CODES_RESET[@]}"; do
_assertSameAnsiReturn reset "${key}" "${_CODES_RESET[${key}]}"
done
}
#
# test ANSI escape codes: reset (interpreted output values)
#
test_output_reset() {
for key in "${!_CODES_RESET[@]}"; do
_assertSameAnsiOutput reset "${key}" "${_CODES_RESET[${key}]}"
done
}
#
# test ANSI escape codes: foreground color (uninterpreted return values)
#
test_return_color_foreground() {
for key in "${!_CODES_COLOR_FOREGROUND[@]}"; do
_assertSameAnsiReturn fg "${key}" "${_CODES_COLOR_FOREGROUND[${key}]}"
done
}
#
# test ANSI escape codes: foreground color (interpreted output values)
#
test_output_color_foreground() {
for key in "${!_CODES_COLOR_FOREGROUND[@]}"; do
_assertSameAnsiOutput fg "${key}" "${_CODES_COLOR_FOREGROUND[${key}]}"
done
}
#
# test ANSI escape codes: background color (uninterpreted return values)
#
test_return_color_background() {
for key in "${!_CODES_COLOR_BACKGROUND[@]}"; do
_assertSameAnsiReturn bg "${key}" "${_CODES_COLOR_BACKGROUND[${key}]}"
done
}
#
# test ANSI escape codes: background color (interpreted output values)
#
test_output_color_background() {
for key in "${!_CODES_COLOR_BACKGROUND[@]}"; do
_assertSameAnsiOutput bg "${key}" "${_CODES_COLOR_BACKGROUND[${key}]}"
done
}
#
# test ANSI escape codes: complex instructions (uninterpreted return values)
#
test_return_insts() {
for key in "${!_CODES_INSTS[@]}"; do
_assertSameAnsi \
"insts:${key}:${_CODES_INSTS[$key]}" \
"$(_escapeAnsiCodes "${_CODES_INSTS[$key]}")" \
"$(_escapeAnsiCodes "$(_get ${key})")"
done
}
#
# test ANSI escape codes: complex instructions (interpreted output values)
#
test_output_insts() {
for key in "${!_CODES_INSTS[@]}"; do
_assertSameAnsi \
"insts:${key}:${_CODES_INSTS[$key]}" \
"$(_escapeAnsiCodes "${_CODES_INSTS[$key]}$(_ansiCodeSequence 0 '\n')")" \
"$(_escapeAnsiCodes "$(_out '@ctl:no-interpret' ${key})")"
done
}
#
# source testing framework runtime
#
# shellcheck disable=SC1090
source "${_TEST_ROOT_PATH}/.shunit/shunit2"