Skip to content

Commit bddf016

Browse files
authored
Merge pull request #625 from TypedDevs/docs/update-0-34-features
docs: update 0.34 features, fix stale refs, expand globals
2 parents f6d87be + 99f4a07 commit bddf016

6 files changed

+248
-11
lines changed

docs/command-line.md

Lines changed: 134 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
```bash
88
bashunit test [path] [options] # Run tests (default)
99
bashunit bench [path] [options] # Run benchmarks
10+
bashunit watch [path] [options] # Watch files, re-run tests on change
11+
bashunit assert <fn> <args> # Run standalone assertion
1012
bashunit doc [filter] # Show assertion documentation
1113
bashunit init [dir] # Initialize test directory
1214
bashunit learn # Interactive tutorial
@@ -55,6 +57,10 @@ bashunit test tests/ --parallel --simple
5557
| `-a, --assert <fn> <args>` | Run a standalone assert function |
5658
| `-e, --env, --boot <file>` | Load custom env/bootstrap file (supports args) |
5759
| `-f, --filter <name>` | Only run tests matching name |
60+
| `--tag <name>` | Only run tests with matching `@tag` (repeatable) |
61+
| `--exclude-tag <name>` | Skip tests with matching `@tag` (repeatable) |
62+
| `--output <format>` | Output format (`tap` for TAP version 13) |
63+
| `-w, --watch` | Watch files and re-run tests on change |
5864
| `--log-junit <file>` | Write JUnit XML report |
5965
| `-j, --jobs <N>` | Run tests in parallel with max N concurrent jobs |
6066
| `-p, --parallel` | Run tests in parallel |
@@ -114,6 +120,84 @@ bashunit test tests/ --filter "user_login"
114120
```
115121
:::
116122

123+
### Tags
124+
125+
> `bashunit test --tag <name>`
126+
> `bashunit test --exclude-tag <name>`
127+
128+
Filter tests by `# @tag` annotations. Both flags are repeatable. `--tag` uses OR
129+
logic across names; `--exclude-tag` wins when a test matches both.
130+
131+
::: code-group
132+
```bash [Annotate tests]
133+
# @tag slow
134+
function test_heavy_computation() {
135+
...
136+
}
137+
138+
# @tag integration
139+
function test_api_call() {
140+
...
141+
}
142+
```
143+
```bash [Run by tag]
144+
bashunit test tests/ --tag slow
145+
bashunit test tests/ --tag slow --tag integration
146+
bashunit test tests/ --exclude-tag integration
147+
```
148+
:::
149+
150+
### Output format
151+
152+
> `bashunit test --output <format>`
153+
154+
Select an alternative output format. Currently supported:
155+
156+
- `tap`[TAP version 13](https://testanything.org/tap-version-13-specification.html) for CI/CD integrations.
157+
158+
The `TAP version 13` header comes first, each test file is announced via a
159+
`# <path>` diagnostic line, each test emits an `ok <n> - <name>` or
160+
`not ok <n> - <name>` line (failures include a YAML `--- ... ...` block with
161+
expected/actual), and the `1..N` plan line closes the report.
162+
163+
::: code-group
164+
```bash [Example]
165+
bashunit test tests/ --output tap
166+
```
167+
```[Output]
168+
TAP version 13
169+
# tests/example_test.sh
170+
ok 1 - Should validate input
171+
not ok 2 - Should handle errors
172+
---
173+
Expected 'foo'
174+
but got 'bar'
175+
...
176+
177+
1..2
178+
```
179+
:::
180+
181+
### Watch mode
182+
183+
> `bashunit test -w|--watch`
184+
185+
Watch the test path (plus `src/` if present) and re-run tests when files change.
186+
The `-w`/`--watch` flag uses a lightweight **checksum polling loop** that works
187+
on any system — no external tools required.
188+
189+
::: code-group
190+
```bash [Example]
191+
bashunit test tests/ --watch
192+
```
193+
:::
194+
195+
::: tip
196+
For file-event-driven watching (no polling), use the dedicated
197+
[`watch`](#watch) subcommand, which relies on `inotifywait` (Linux) or
198+
`fswatch` (macOS).
199+
:::
200+
117201
### Environment / Bootstrap
118202

119203
> `bashunit test -e|--env|--boot <file>`
@@ -326,7 +410,7 @@ This is useful for:
326410
bashunit test tests/ --no-progress
327411
```
328412
```[Output]
329-
bashunit - 0.32.0 | Tests: 10
413+
bashunit - 0.34.1 | Tests: 10
330414
Tests: 10 passed, 10 total
331415
Assertions: 25 passed, 25 total
332416
@@ -464,6 +548,43 @@ bashunit bench --filter "parse"
464548
| `--skip-env-file` | Skip `.env` loading, use shell environment only |
465549
| `-l, --login` | Run in login shell context |
466550

551+
## watch
552+
553+
> `bashunit watch [path] [test-options]`
554+
555+
Dedicated watch subcommand that uses **OS file-event notifications** (no
556+
polling) to re-run tests as soon as a `.sh` file changes. Any option accepted
557+
by `bashunit test` is also accepted here.
558+
559+
::: code-group
560+
```bash [Examples]
561+
# Watch current directory
562+
bashunit watch
563+
564+
# Watch the tests/ directory
565+
bashunit watch tests/
566+
567+
# Watch and filter by name
568+
bashunit watch tests/ --filter user
569+
570+
# Watch with simple output
571+
bashunit watch tests/ --simple
572+
```
573+
:::
574+
575+
::: warning Requirements
576+
- **Linux:** `inotifywait` (`sudo apt install inotify-tools`)
577+
- **macOS:** `fswatch` (`brew install fswatch`)
578+
579+
If the required tool is not installed, bashunit prints a clear installation hint
580+
and exits with a non-zero code.
581+
:::
582+
583+
::: tip
584+
If you cannot install `inotifywait` or `fswatch`, use the portable
585+
[`-w/--watch`](#watch-mode) flag on `bashunit test` instead (uses polling).
586+
:::
587+
467588
## doc
468589

469590
> `bashunit doc [filter]`
@@ -567,7 +688,7 @@ bashunit upgrade
567688
```
568689
```[Output]
569690
> Upgrading bashunit to latest version
570-
> bashunit upgraded successfully to latest version 0.28.0
691+
> bashunit upgraded successfully to latest version 0.34.1
571692
```
572693
:::
573694

@@ -604,16 +725,18 @@ bashunit --help
604725
Usage: bashunit <command> [arguments] [options]
605726
606727
Commands:
607-
test [path] Run tests (default command)
608-
bench [path] Run benchmarks
609-
doc [filter] Display assertion documentation
610-
init [dir] Initialize a new test directory
611-
learn Start interactive tutorial
612-
upgrade Upgrade bashunit to latest version
728+
test [path] Run tests (default command)
729+
bench [path] Run benchmarks
730+
assert <fn> <args> Run standalone assertion
731+
doc [filter] Display assertion documentation
732+
init [dir] Initialize a new test directory
733+
learn Start interactive tutorial
734+
watch [path] Watch files and re-run tests on change
735+
upgrade Upgrade bashunit to latest version
613736
614737
Global Options:
615-
-h, --help Show this help message
616-
-v, --version Display the current version
738+
-h, --help Show this help message
739+
-v, --version Display the current version
617740
618741
Run 'bashunit <command> --help' for command-specific options.
619742
```
@@ -624,6 +747,7 @@ Each subcommand also supports `--help`:
624747
```bash
625748
bashunit test --help
626749
bashunit bench --help
750+
bashunit watch --help
627751
bashunit doc --help
628752
```
629753

docs/configuration.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ BASHUNIT_SHOW_EXECUTION_TIME=false
203203
```
204204
:::
205205

206+
## Output format
207+
208+
> `BASHUNIT_OUTPUT_FORMAT=tap`
209+
210+
Select an alternative output format. Currently supported: `tap` for
211+
[TAP version 13](https://testanything.org/tap-version-13-specification.html),
212+
useful for CI/CD integrations.
213+
214+
Similar as using `--output` option on the [command line](/command-line#output-format).
215+
216+
::: code-group
217+
```bash [.env]
218+
BASHUNIT_OUTPUT_FORMAT=tap
219+
```
220+
:::
221+
206222
## Log JUnit
207223

208224
> `BASHUNIT_LOG_JUNIT=file`

docs/globals.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ Internal messages from bashunit include the `[INTERNAL]` prefix so you can easil
3232

3333
> `bashunit::caller_filename`: Gets the caller filename.
3434
35+
## bashunit::caller_line
36+
37+
> `bashunit::caller_line`: Gets the line number of the caller.
38+
39+
Useful inside custom assertions to report the line that triggered the failure.
40+
3541
## bashunit::current_timestamp
3642

3743
> `bashunit::current_timestamp`: Gets the current timestamp.
@@ -54,4 +60,39 @@ The directory is automatically deleted when bashunit completes.
5460

5561
## bashunit::is_command_available
5662

57-
> `bashunit::is_command_available`: Checks if command is available
63+
> `bashunit::is_command_available <command>`: Checks if a command is available in `PATH`.
64+
65+
Returns `0` when the command is found, `1` otherwise.
66+
67+
```bash
68+
if bashunit::is_command_available jq; then
69+
# jq-based assertions
70+
fi
71+
```
72+
73+
## bashunit::print_line
74+
75+
> `bashunit::print_line <?length> <?char>`: Prints a horizontal separator.
76+
77+
Defaults to 70 characters of `-`. Both arguments are optional.
78+
79+
```bash
80+
bashunit::print_line # 70 dashes
81+
bashunit::print_line 40 '=' # 40 equals signs
82+
```
83+
84+
## Custom assertion helpers
85+
86+
These helpers are intended for building [custom assertions](/custom-asserts).
87+
88+
- `bashunit::assertion_passed` — Mark the current assertion as passed.
89+
- `bashunit::assertion_failed <expected> <actual> <?label>` — Mark the current
90+
assertion as failed and print a failure report.
91+
- `bashunit::fail <?message>` — Fail the current test with an optional message.
92+
93+
See [Custom asserts](/custom-asserts) for full examples.
94+
95+
## Test doubles
96+
97+
The `bashunit::spy`, `bashunit::mock`, and `bashunit::unmock` helpers are
98+
documented in [Test doubles](/test-doubles).
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
function set_up_before_script() {
5+
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
6+
}
7+
8+
function test_tap_output_passing_tests_matches_snapshot() {
9+
local test_file=tests/acceptance/fixtures/test_bashunit_when_a_test_passes.sh
10+
11+
assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --output tap "$test_file")"
12+
}
13+
14+
function test_tap_output_failing_tests_matches_snapshot() {
15+
local test_file=tests/acceptance/fixtures/test_bashunit_when_a_test_fail.sh
16+
17+
assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --output tap "$test_file" 2>&1 || true)"
18+
}
19+
20+
function test_tap_output_env_var_equivalent_to_flag() {
21+
local test_file=tests/acceptance/fixtures/test_bashunit_when_a_test_passes.sh
22+
local via_flag
23+
local via_env
24+
25+
via_flag=$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --output tap "$test_file")
26+
via_env=$(BASHUNIT_OUTPUT_FORMAT=tap ./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")
27+
28+
assert_equals "$via_flag" "$via_env"
29+
}
30+
31+
function test_tap_output_exits_non_zero_on_failure() {
32+
local test_file=tests/acceptance/fixtures/test_bashunit_when_a_test_fail.sh
33+
34+
assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --output tap "$test_file" 2>&1)"
35+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
TAP version 13
2+
# tests/acceptance/fixtures/test_bashunit_when_a_test_fail.sh
3+
ok 1 - Assert same
4+
ok 2 - Assert contains
5+
not ok 3 - Assert failing
6+
---
7+
Expected '1'
8+
but got '0'
9+
...
10+
ok 4 - Assert greater and less than
11+
ok 5 - Assert empty
12+
13+
1..5
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
TAP version 13
2+
# tests/acceptance/fixtures/test_bashunit_when_a_test_passes.sh
3+
ok 1 - Assert same
4+
ok 2 - Assert contains
5+
ok 3 - Assert greater and less than
6+
ok 4 - Assert empty
7+
8+
1..4

0 commit comments

Comments
 (0)