Skip to content

Commit 0913795

Browse files
committed
feat(coverage): add HTML report with line-by-line highlighting
Add --coverage-report-html option to generate interactive HTML coverage reports showing source code with covered/uncovered line highlighting. Features: - Index page with per-file coverage summary and progress bars - Individual file pages with line numbers, hit counts, and source code - Green highlighting for covered lines, red for uncovered - Color thresholds based on BASHUNIT_COVERAGE_THRESHOLD_LOW/HIGH - Self-contained HTML with inline CSS (no external dependencies)
1 parent 33ce311 commit 0913795

File tree

7 files changed

+455
-36
lines changed

7 files changed

+455
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Configurable source paths via `--coverage-paths` (default: `src/`)
99
- Configurable exclusions via `--coverage-exclude` (default: `tests/*,vendor/*,*_test.sh,*Test.sh`)
1010
- LCOV format output via `--coverage-report` (default: `coverage/lcov.info`)
11+
- HTML coverage report via `--coverage-report-html <dir>` with line-by-line highlighting
1112
- Minimum coverage threshold via `--coverage-min` (fails if below)
1213
- Console-only mode with `--no-coverage-report`
1314
- Color-coded console output with configurable thresholds (50%/80%)

docs/command-line.md

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,36 @@ bashunit test tests/ --parallel --simple
4343

4444
### Test Options
4545

46-
| Option | Description |
47-
|----------------------------|--------------------------------------------------|
48-
| `-a, --assert <fn> <args>` | Run a standalone assert function |
49-
| `-e, --env, --boot <file>` | Load custom env/bootstrap file (supports args) |
50-
| `-f, --filter <name>` | Only run tests matching name |
51-
| `--log-junit <file>` | Write JUnit XML report |
52-
| `-p, --parallel` | Run tests in parallel |
53-
| `--no-parallel` | Run tests sequentially |
54-
| `-r, --report-html <file>` | Write HTML report |
55-
| `-R, --run-all` | Run all assertions (don't stop on first failure) |
56-
| `-s, --simple` | Simple output (dots) |
57-
| `--detailed` | Detailed output (default) |
58-
| `-S, --stop-on-failure` | Stop on first failure |
59-
| `--show-skipped` | Show skipped tests summary at end |
60-
| `--show-incomplete` | Show incomplete tests summary at end |
61-
| `-vvv, --verbose` | Show execution details |
62-
| `--debug [file]` | Enable shell debug mode |
63-
| `--no-output` | Suppress all output |
64-
| `--failures-only` | Only show failures |
65-
| `--strict` | Enable strict shell mode |
66-
| `--skip-env-file` | Skip `.env` loading, use shell environment only |
67-
| `-l, --login` | Run tests in login shell context |
68-
| `--no-color` | Disable colored output |
69-
| `--coverage` | Enable code coverage tracking |
70-
| `--coverage-paths <paths>` | Paths to track (default: `src/`) |
71-
| `--coverage-exclude <pat>` | Exclusion patterns |
72-
| `--coverage-report <file>` | LCOV output path (default: `coverage/lcov.info`) |
73-
| `--coverage-min <percent>` | Minimum coverage threshold |
74-
| `--no-coverage-report` | Console output only, no LCOV file |
46+
| Option | Description |
47+
|--------------------------------|--------------------------------------------------|
48+
| `-a, --assert <fn> <args>` | Run a standalone assert function |
49+
| `-e, --env, --boot <file>` | Load custom env/bootstrap file (supports args) |
50+
| `-f, --filter <name>` | Only run tests matching name |
51+
| `--log-junit <file>` | Write JUnit XML report |
52+
| `-p, --parallel` | Run tests in parallel |
53+
| `--no-parallel` | Run tests sequentially |
54+
| `-r, --report-html <file>` | Write HTML report |
55+
| `-R, --run-all` | Run all assertions (don't stop on first failure) |
56+
| `-s, --simple` | Simple output (dots) |
57+
| `--detailed` | Detailed output (default) |
58+
| `-S, --stop-on-failure` | Stop on first failure |
59+
| `--show-skipped` | Show skipped tests summary at end |
60+
| `--show-incomplete` | Show incomplete tests summary at end |
61+
| `-vvv, --verbose` | Show execution details |
62+
| `--debug [file]` | Enable shell debug mode |
63+
| `--no-output` | Suppress all output |
64+
| `--failures-only` | Only show failures |
65+
| `--strict` | Enable strict shell mode |
66+
| `--skip-env-file` | Skip `.env` loading, use shell environment only |
67+
| `-l, --login` | Run tests in login shell context |
68+
| `--no-color` | Disable colored output |
69+
| `--coverage` | Enable code coverage tracking |
70+
| `--coverage-paths <paths>` | Paths to track (default: `src/`) |
71+
| `--coverage-exclude <pat>` | Exclusion patterns |
72+
| `--coverage-report <file>` | LCOV output path (default: `coverage/lcov.info`) |
73+
| `--coverage-report-html <dir>` | Generate HTML report with line highlighting |
74+
| `--coverage-min <percent>` | Minimum coverage threshold |
75+
| `--no-coverage-report` | Console output only, no LCOV file |
7576

7677
### Standalone Assert
7778

@@ -307,14 +308,15 @@ bashunit test tests/ --coverage --coverage-paths src/,lib/ --coverage-min 80
307308

308309
**Coverage options:**
309310

310-
| Option | Description |
311-
|--------|-------------|
312-
| `--coverage` | Enable coverage tracking |
313-
| `--coverage-paths <paths>` | Comma-separated paths to track (default: `src/`) |
311+
| Option | Description |
312+
|---------------------------------|-----------------------------------------------------------------------------|
313+
| `--coverage` | Enable coverage tracking |
314+
| `--coverage-paths <paths>` | Comma-separated paths to track (default: `src/`) |
314315
| `--coverage-exclude <patterns>` | Comma-separated patterns to exclude (default: `tests/*,vendor/*,*_test.sh`) |
315-
| `--coverage-report <file>` | LCOV output file path (default: `coverage/lcov.info`) |
316-
| `--coverage-min <percent>` | Minimum coverage percentage; fails if below |
317-
| `--no-coverage-report` | Show console report only, don't generate LCOV file |
316+
| `--coverage-report <file>` | LCOV output file path (default: `coverage/lcov.info`) |
317+
| `--coverage-report-html <dir>` | Generate HTML coverage report with line-by-line highlighting |
318+
| `--coverage-min <percent>` | Minimum coverage percentage; fails if below |
319+
| `--no-coverage-report` | Show console report only, don't generate LCOV file |
318320

319321
::: tip
320322
Coverage works with parallel execution (`-p`). Each worker tracks coverage independently, and results are aggregated before reporting.

docs/coverage.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The DEBUG trap adds overhead to test execution. For large test suites, consider
5757
| `--coverage-paths <paths>` | Comma-separated paths to track (default: `src/`) |
5858
| `--coverage-exclude <patterns>` | Comma-separated exclusion patterns |
5959
| `--coverage-report <file>` | LCOV report output path (default: `coverage/lcov.info`) |
60+
| `--coverage-report-html <dir>` | Generate HTML coverage report with line-by-line details |
6061
| `--coverage-min <percent>` | Minimum coverage threshold (fails if below) |
6162
| `--no-coverage-report` | Disable LCOV file generation (console only) |
6263

@@ -77,6 +78,9 @@ BASHUNIT_COVERAGE_EXCLUDE=tests/*,vendor/*,*_test.sh
7778
# LCOV report output path
7879
BASHUNIT_COVERAGE_REPORT=coverage/lcov.info
7980

81+
# HTML report output directory (generates line-by-line coverage view)
82+
BASHUNIT_COVERAGE_REPORT_HTML=coverage/html
83+
8084
# Minimum coverage percentage (optional)
8185
BASHUNIT_COVERAGE_MIN=80
8286

@@ -159,6 +163,30 @@ bashunit tests/ --coverage --no-coverage-report
159163
```
160164
:::
161165

166+
### HTML Coverage Report
167+
168+
Generate a detailed HTML report showing line-by-line coverage:
169+
170+
::: code-group
171+
```bash [Command]
172+
bashunit tests/ --coverage --coverage-report-html coverage/html
173+
```
174+
```bash [.env]
175+
BASHUNIT_COVERAGE_REPORT_HTML=coverage/html
176+
```
177+
:::
178+
179+
This creates a directory with:
180+
- `index.html` - Summary page with per-file coverage percentages
181+
- `files/*.html` - Individual source file views with line highlighting
182+
183+
**Line highlighting:**
184+
- **Green background**: Lines executed during tests (covered)
185+
- **Red background**: Executable lines not executed (uncovered)
186+
- **No background**: Non-executable lines (comments, function declarations, etc.)
187+
188+
Each line also shows the number of times it was executed, helping identify hot paths and dead code.
189+
162190
### CI/CD Integration
163191

164192
Generate coverage for CI tools like Codecov or Coveralls:

src/console_header.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Coverage:
128128
--coverage-paths <paths> Source paths to track (comma-separated, default: src/)
129129
--coverage-exclude <pats> Patterns to exclude (comma-separated)
130130
--coverage-report <file> Output file (default: coverage/lcov.info)
131+
--coverage-report-html <dir> Generate HTML coverage report
131132
--coverage-min <pct> Fail if coverage below percentage
132133
--no-coverage-report Disable file output, console only
133134
@@ -138,6 +139,7 @@ Examples:
138139
bashunit test -a equals "foo" "foo"
139140
bashunit test tests/ --coverage
140141
bashunit test tests/ --coverage --coverage-min 80
142+
bashunit test tests/ --coverage --coverage-report-html coverage/html
141143
EOF
142144
}
143145

0 commit comments

Comments
 (0)