Skip to content

Commit c2cc519

Browse files
authored
Merge pull request #573 from TypedDevs/feat/default-value-for-coverage-report-html
Default value for coverage report html
2 parents 3ee3916 + b6f9f8c commit c2cc519

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ bashunit --help # Show help
1515
bashunit --version # Show version
1616
```
1717

18+
## Argument Notation
19+
20+
| Syntax | Meaning |
21+
|----------|------------------------------------------|
22+
| `<arg>` | Required - must be provided |
23+
| `[arg]` | Optional - can be omitted (uses default) |
24+
1825
## test
1926

2027
> `bashunit test [path] [options]`
@@ -69,8 +76,8 @@ bashunit test tests/ --parallel --simple
6976
| `--coverage` | Enable code coverage tracking |
7077
| `--coverage-paths <paths>` | Paths to track (default: auto-discover) |
7178
| `--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 |
79+
| `--coverage-report [file]` | LCOV output path (default: `coverage/lcov.info`) |
80+
| `--coverage-report-html [dir]` | Generate HTML report (default: `coverage/html`) |
7481
| `--coverage-min <percent>` | Minimum coverage threshold |
7582
| `--no-coverage-report` | Console output only, no LCOV file |
7683

@@ -313,8 +320,8 @@ bashunit test tests/ --coverage --coverage-paths src/,lib/ --coverage-min 80
313320
| `--coverage` | Enable coverage tracking |
314321
| `--coverage-paths <paths>` | Comma-separated paths to track (default: auto-discover from test files) |
315322
| `--coverage-exclude <patterns>` | Comma-separated patterns to exclude (default: `tests/*,vendor/*,*_test.sh`) |
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 |
323+
| `--coverage-report [file]` | LCOV output file path (default: `coverage/lcov.info`) |
324+
| `--coverage-report-html [dir]` | Generate HTML report (default: `coverage/html`) |
318325
| `--coverage-min <percent>` | Minimum coverage percentage; fails if below |
319326
| `--no-coverage-report` | Show console report only, don't generate LCOV file |
320327

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)