Skip to content

Commit 1dc04a0

Browse files
committed
chore: simplify coverage usage flags
1 parent 036dc88 commit 1dc04a0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

docs/coverage.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Enable coverage tracking with the `--coverage` flag:
1111
bashunit tests/ --coverage
1212
```
1313
```bash [With custom paths]
14-
bashunit tests/ --coverage --coverage-paths src/
14+
bashunit tests/ --coverage-paths src/
1515
```
1616
```bash [Output]
1717
bashunit - 0.30.0 | Tests: 5
@@ -61,6 +61,10 @@ The DEBUG trap adds overhead to test execution. For large test suites, consider
6161
| `--coverage-min <percent>` | Minimum coverage threshold (fails if below) |
6262
| `--no-coverage-report` | Disable LCOV file generation (console only) |
6363

64+
::: tip Auto-enable
65+
Coverage is automatically enabled when using `--coverage-report`, `--coverage-report-html`, or `--coverage-min`. You don't need to specify `--coverage` explicitly with these options.
66+
:::
67+
6468
### Environment Variables
6569

6670
You can also configure coverage via environment variables in your `.env` file:
@@ -133,7 +137,7 @@ Fail the test run if coverage drops below a threshold:
133137

134138
::: code-group
135139
```bash [Command]
136-
bashunit tests/ --coverage --coverage-min 80
140+
bashunit tests/ --coverage-min 80
137141
```
138142
```[Output - Passing]
139143
Coverage Report
@@ -169,7 +173,7 @@ Generate a detailed HTML report showing line-by-line coverage:
169173

170174
::: code-group
171175
```bash [Command]
172-
bashunit tests/ --coverage --coverage-report-html coverage/html
176+
bashunit tests/ --coverage-report-html coverage/html
173177
```
174178
```bash [.env]
175179
BASHUNIT_COVERAGE_REPORT_HTML=coverage/html
@@ -194,7 +198,7 @@ Generate coverage for CI tools like Codecov or Coveralls:
194198
::: code-group
195199
```yaml [GitHub Actions]
196200
- name: Run tests with coverage
197-
run: bashunit tests/ --coverage --coverage-min 80
201+
run: bashunit tests/ --coverage-min 80
198202

199203
- name: Upload coverage to Codecov
200204
uses: codecov/codecov-action@v4

src/main.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function bashunit::main::cmd_test() {
88
local raw_args=()
99
local args=()
1010
local assert_fn=""
11+
local _bashunit_coverage_opt_set=false
1112

1213
# Parse test-specific options
1314
while [[ $# -gt 0 ]]; do
@@ -115,11 +116,13 @@ function bashunit::main::cmd_test() {
115116
--coverage-report)
116117
# shellcheck disable=SC2034
117118
BASHUNIT_COVERAGE_REPORT="$2"
119+
_bashunit_coverage_opt_set=true
118120
shift
119121
;;
120122
--coverage-min)
121123
# shellcheck disable=SC2034
122124
BASHUNIT_COVERAGE_MIN="$2"
125+
_bashunit_coverage_opt_set=true
123126
shift
124127
;;
125128
--no-coverage-report)
@@ -129,6 +132,7 @@ function bashunit::main::cmd_test() {
129132
--coverage-report-html)
130133
# shellcheck disable=SC2034
131134
BASHUNIT_COVERAGE_REPORT_HTML="$2"
135+
_bashunit_coverage_opt_set=true
132136
shift
133137
;;
134138
*)
@@ -138,6 +142,12 @@ function bashunit::main::cmd_test() {
138142
shift
139143
done
140144

145+
# Auto-enable coverage when any coverage output option is specified
146+
if [[ "$_bashunit_coverage_opt_set" == true ]]; then
147+
# shellcheck disable=SC2034
148+
BASHUNIT_COVERAGE=true
149+
fi
150+
141151
# Expand positional arguments and extract inline filters
142152
# Skip filter parsing for assert mode - args are not file paths
143153
local inline_filter=""

0 commit comments

Comments
 (0)