forked from TypedDevs/bashunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole_header.sh
More file actions
299 lines (245 loc) · 10.1 KB
/
console_header.sh
File metadata and controls
299 lines (245 loc) · 10.1 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/env bash
function bashunit::console_header::print_version_with_env() {
local filter=${1:-}
shift || true
if ! bashunit::env::is_show_header_enabled; then
return
fi
bashunit::console_header::print_version "$filter" "$@"
if bashunit::env::is_dev_mode_enabled; then
printf "%sDev log:%s %s\n" \
"${_BASHUNIT_COLOR_INCOMPLETE}" "${_BASHUNIT_COLOR_DEFAULT}" "$BASHUNIT_DEV_LOG"
fi
}
function bashunit::console_header::print_version() {
local filter=${1:-}
shift || true
# Bash 3.0 compatible: check argument count after shift
local files_count=$#
local total_tests
if [[ "$files_count" -eq 0 ]]; then
total_tests=0
elif bashunit::parallel::is_enabled && bashunit::env::is_simple_output_enabled; then
# Skip counting in parallel+simple mode for faster startup
total_tests=0
else
total_tests=$(bashunit::helper::find_total_tests "$filter" "$@")
fi
if bashunit::env::is_header_ascii_art_enabled; then
cat <<EOF
_ _ _
| |__ __ _ ___| |__ __ __ ____ (_) |_
| '_ \ / _' / __| '_ \| | | | '_ \| | __|
| |_) | (_| \__ \ | | | |_| | | | | | |_
|_.__/ \__,_|___/_| |_|\___/|_| |_|_|\__|
EOF
if [ "$total_tests" -eq 0 ]; then
printf "%s\n" "$BASHUNIT_VERSION"
else
printf "%s | Tests: %s\n" "$BASHUNIT_VERSION" "$total_tests"
fi
return
fi
if [ "$total_tests" -eq 0 ]; then
printf "%s%sbashunit%s - %s\n" \
"$_BASHUNIT_COLOR_BOLD" "$_BASHUNIT_COLOR_PASSED" "$_BASHUNIT_COLOR_DEFAULT" "$BASHUNIT_VERSION"
else
printf "%s%sbashunit%s - %s | Tests: %s\n" \
"${_BASHUNIT_COLOR_BOLD}" "${_BASHUNIT_COLOR_PASSED}" "${_BASHUNIT_COLOR_DEFAULT}" \
"$BASHUNIT_VERSION" "$total_tests"
fi
}
function bashunit::console_header::print_help() {
cat <<EOF
Usage: bashunit <command> [arguments] [options]
Commands:
test [path] Run tests (default command)
bench [path] Run benchmarks
assert <fn> <args> Run standalone assertion
doc [filter] Display assertion documentation
init [dir] Initialize a new test directory
learn Start interactive tutorial
watch [path] Watch files and re-run tests on change
upgrade Upgrade bashunit to latest version
Global Options:
-h, --help Show this help message
-v, --version Display the current version
Run 'bashunit <command> --help' for command-specific options.
Examples:
bashunit test tests/ Run all tests in directory
bashunit tests/ Run all tests (shorthand)
bashunit bench Run all benchmarks
bashunit assert equals "foo" "foo" Run standalone assertion
bashunit doc contains Show docs for 'contains' assertions
bashunit init Initialize test directory
More info: https://bashunit.typeddevs.com/command-line
EOF
}
function bashunit::console_header::print_test_help() {
cat <<EOF
Usage: bashunit test [path] [options]
bashunit [path] [options]
Run test files. If no path is provided, searches for tests in BASHUNIT_DEFAULT_PATH.
Arguments:
path File or directory containing tests
- Directories: runs all '*test.sh' files
- Wildcards: supported to match multiple files
Options:
-a, --assert <fn> <args> Run a standalone assert function (deprecated: use 'bashunit assert')
-e, --env, --boot <file> Load a custom env/bootstrap file (supports args)
-f, --filter <name> Only run tests matching the name
--tag <name> Only run tests with matching @tag (repeatable, OR logic)
--exclude-tag <name> Skip tests with matching @tag (repeatable, exclude wins)
--log-junit <file> Write JUnit XML report
-p, --parallel Run tests in parallel
--no-parallel Run tests sequentially
-r, --report-html <file> Write HTML report
-s, --simple Simple output (dots)
--detailed Detailed output (default)
-R, --run-all Run all assertions (don't stop on first failure)
-S, --stop-on-failure Stop on first failure
-vvv, --verbose Show execution details
--debug [file] Enable shell debug mode
--no-output Suppress all output
--failures-only Only show failures (suppress passed/skipped/incomplete)
--no-progress Suppress real-time progress, show only final results
--show-output Show test output on failure (default: enabled)
--no-output-on-failure Hide test output on failure
--strict Enable strict shell mode (set -euo pipefail)
--skip-env-file Skip .env loading, use shell environment only
-l, --login Run tests in login shell context
--no-color Disable colored output (honors NO_COLOR env var)
-h, --help Show this help message
Coverage:
--coverage Enable code coverage tracking
--coverage-paths <paths> Source paths to track (default: auto-discover)
--coverage-exclude <pats> Patterns to exclude (comma-separated)
--coverage-report [file] Output file (default: coverage/lcov.info)
--coverage-report-html [dir] HTML report (default: coverage/html)
--coverage-min <pct> Fail if coverage below percentage
--no-coverage-report Disable file output, console only
Examples:
bashunit test tests/
bashunit test tests/unit/ --parallel
bashunit test --filter "user" tests/
bashunit test -a equals "foo" "foo"
bashunit test tests/ --coverage
bashunit test tests/ --coverage --coverage-min 80
bashunit test tests/ --coverage-report-html
EOF
}
function bashunit::console_header::print_bench_help() {
cat <<EOF
Usage: bashunit bench [path] [options]
Run benchmark files. Searches for '*bench.sh' files.
Arguments:
path File or directory containing benchmarks
Options:
-e, --env, --boot <file> Load a custom env/bootstrap file (supports args)
-f, --filter <name> Only run benchmarks matching the name
-s, --simple Simple output
--detailed Detailed output (default)
-vvv, --verbose Show execution details
--skip-env-file Skip .env loading, use shell environment only
-l, --login Run in login shell context
--no-color Disable colored output (honors NO_COLOR env var)
-h, --help Show this help message
Examples:
bashunit bench
bashunit bench benchmarks/
bashunit bench --filter "parse"
EOF
}
function bashunit::console_header::print_doc_help() {
cat <<EOF
Usage: bashunit doc [filter]
Display documentation for assertion functions.
Arguments:
filter Optional filter to show only matching assertions
Examples:
bashunit doc Show all assertions
bashunit doc equals Show assertions containing 'equals'
bashunit doc file Show file-related assertions
EOF
}
function bashunit::console_header::print_init_help() {
cat <<EOF
Usage: bashunit init [directory]
Initialize a new test directory with sample files.
Arguments:
directory Target directory (default: tests)
Creates:
- bootstrap.sh Setup file for test configuration
- example_test.sh Sample test file to get started
Examples:
bashunit init Create tests/ directory
bashunit init spec Create spec/ directory
EOF
}
function bashunit::console_header::print_learn_help() {
cat <<EOF
Usage: bashunit learn
Start the interactive learning tutorial.
The tutorial includes 10 progressive lessons:
1. Basics - Your First Test
2. Assertions - Testing Different Conditions
3. Setup & Teardown - Managing Test Lifecycle
4. Testing Functions - Unit Testing Patterns
5. Testing Scripts - Integration Testing
6. Mocking - Test Doubles and Mocks
7. Spies - Verifying Function Calls
8. Data Providers - Parameterized Tests
9. Exit Codes - Testing Success and Failure
10. Complete Challenge - Real World Scenario
Your progress is saved automatically.
EOF
}
function bashunit::console_header::print_upgrade_help() {
cat <<EOF
Usage: bashunit upgrade
Upgrade bashunit to the latest version.
Downloads and installs the newest release from GitHub.
EOF
}
function bashunit::console_header::print_assert_help() {
cat <<EOF
Usage: bashunit assert <function> [args...]
bashunit assert "<command>" <assertion1> <arg1> [<assertion2> <arg2>...]
Run standalone assertion(s) without creating a test file.
Single assertion:
bashunit assert equals "foo" "foo"
bashunit assert same "1" "1"
bashunit assert contains "world" "hello world"
bashunit assert exit_code 0 "echo 'success'"
Multiple assertions on command output:
bashunit assert "echo 'error' && exit 1" exit_code "1" contains "error"
bashunit assert "./my_script.sh" exit_code "0" contains "success" not_contains "error"
Arguments:
function Assertion function name (with or without 'assert_' prefix)
command Command to execute (for multi-assertion mode)
assertion Assertion name (exit_code, contains, equals, etc.)
arg Expected value for the assertion
Note: You can also use 'bashunit test --assert <fn> <args>' (deprecated).
The 'bashunit assert' subcommand is the recommended approach.
More info: https://bashunit.typeddevs.com/standalone
EOF
}
function bashunit::console_header::print_watch_help() {
cat << 'ENDOFHELP'
Usage: bashunit watch [path] [test-options]
Watch .sh files for changes and automatically re-run tests.
Arguments:
[path] Directory or file to watch and test (default: .)
Options:
-h, --help Show this help message
Any option accepted by 'bashunit test' is also accepted here.
Requirements:
Linux: inotifywait (sudo apt install inotify-tools)
macOS: fswatch (brew install fswatch)
Examples:
bashunit watch Watch current directory
bashunit watch tests/ Watch the tests/ directory
bashunit watch tests/ --filter user Watch and filter by name
bashunit watch tests/ --simple Watch with simple output
ENDOFHELP
}