Skip to content

Commit a73af11

Browse files
committed
feat(coverage): add default value for --coverage-report-html
Allow using --coverage-report-html without specifying a directory, defaulting to coverage/html for convenience.
1 parent 3ee3916 commit a73af11

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Auto-discover coverage paths from test file names when `BASHUNIT_COVERAGE_PATHS` is not set
88
- `tests/unit/assert_test.sh` automatically tracks `src/assert.sh`
99
- Removes need for manual `--coverage-paths` configuration in most cases
10+
- `--coverage-report-html` now defaults to `coverage/html` when no directory is specified
1011

1112
### Fixed
1213
- Coverage now excludes control flow keywords (`then`, `else`, `fi`, `do`, `done`, `esac`, `;;`, case patterns) from line tracking

docs/command-line.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bashunit test tests/ --parallel --simple
7070
| `--coverage-paths <paths>` | Paths to track (default: auto-discover) |
7171
| `--coverage-exclude <pat>` | Exclusion patterns |
7272
| `--coverage-report <file>` | LCOV output path (default: `coverage/lcov.info`) |
73-
| `--coverage-report-html <dir>` | Generate HTML report with line highlighting |
73+
| `--coverage-report-html [dir]` | Generate HTML report (default: `coverage/html`) |
7474
| `--coverage-min <percent>` | Minimum coverage threshold |
7575
| `--no-coverage-report` | Console output only, no LCOV file |
7676

@@ -314,7 +314,7 @@ bashunit test tests/ --coverage --coverage-paths src/,lib/ --coverage-min 80
314314
| `--coverage-paths <paths>` | Comma-separated paths to track (default: auto-discover from test files) |
315315
| `--coverage-exclude <patterns>` | Comma-separated patterns to exclude (default: `tests/*,vendor/*,*_test.sh`) |
316316
| `--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 |
317+
| `--coverage-report-html [dir]` | Generate HTML report (default: `coverage/html`) |
318318
| `--coverage-min <percent>` | Minimum coverage percentage; fails if below |
319319
| `--no-coverage-report` | Show console report only, don't generate LCOV file |
320320

docs/coverage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +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: auto-discover from test files) |
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 |
60+
| `--coverage-report-html [dir]` | Generate HTML report (default: `coverage/html`) |
6161
| `--coverage-min <percent>` | Minimum coverage threshold (fails if below) |
6262
| `--no-coverage-report` | Disable LCOV file generation (console only) |
6363

src/console_header.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ Options:
124124
-h, --help Show this help message
125125
126126
Coverage:
127-
--coverage Enable code coverage tracking
128-
--coverage-paths <paths> Source paths to track (comma-separated, default: src/)
129-
--coverage-exclude <pats> Patterns to exclude (comma-separated)
130-
--coverage-report <file> Output file (default: coverage/lcov.info)
131-
--coverage-report-html <dir> Generate HTML coverage report
132-
--coverage-min <pct> Fail if coverage below percentage
133-
--no-coverage-report Disable file output, console only
127+
--coverage Enable code coverage tracking
128+
--coverage-paths <paths> Source paths to track (default: auto-discover)
129+
--coverage-exclude <pats> Patterns to exclude (comma-separated)
130+
--coverage-report <file> Output file (default: coverage/lcov.info)
131+
--coverage-report-html [dir] HTML report (default: coverage/html)
132+
--coverage-min <pct> Fail if coverage below percentage
133+
--no-coverage-report Disable file output, console only
134134
135135
Examples:
136136
bashunit test tests/
@@ -139,7 +139,7 @@ Examples:
139139
bashunit test -a equals "foo" "foo"
140140
bashunit test tests/ --coverage
141141
bashunit test tests/ --coverage --coverage-min 80
142-
bashunit test tests/ --coverage --coverage-report-html coverage/html
142+
bashunit test tests/ --coverage-report-html
143143
EOF
144144
}
145145

src/main.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,14 @@ function bashunit::main::cmd_test() {
131131
;;
132132
--coverage-report-html)
133133
# shellcheck disable=SC2034
134-
BASHUNIT_COVERAGE_REPORT_HTML="$2"
134+
# Use default if no value provided or next arg is a flag
135+
if [[ -z "${2:-}" || "${2:-}" == -* ]]; then
136+
BASHUNIT_COVERAGE_REPORT_HTML="coverage/html"
137+
else
138+
BASHUNIT_COVERAGE_REPORT_HTML="$2"
139+
shift
140+
fi
135141
_bashunit_coverage_opt_set=true
136-
shift
137142
;;
138143
*)
139144
raw_args+=("$1")

0 commit comments

Comments
 (0)