Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Auto-discover coverage paths from test file names when `BASHUNIT_COVERAGE_PATHS` is not set
- `tests/unit/assert_test.sh` automatically tracks `src/assert.sh`
- Removes need for manual `--coverage-paths` configuration in most cases
- `--coverage-report-html` now defaults to `coverage/html` when no directory is specified

### Fixed
- Coverage now excludes control flow keywords (`then`, `else`, `fi`, `do`, `done`, `esac`, `;;`, case patterns) from line tracking
Expand Down
15 changes: 11 additions & 4 deletions docs/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ bashunit --help # Show help
bashunit --version # Show version
```

## Argument Notation

| Syntax | Meaning |
|----------|------------------------------------------|
| `<arg>` | Required - must be provided |
| `[arg]` | Optional - can be omitted (uses default) |

## test

> `bashunit test [path] [options]`
Expand Down Expand Up @@ -69,8 +76,8 @@ bashunit test tests/ --parallel --simple
| `--coverage` | Enable code coverage tracking |
| `--coverage-paths <paths>` | Paths to track (default: auto-discover) |
| `--coverage-exclude <pat>` | Exclusion patterns |
| `--coverage-report <file>` | LCOV output path (default: `coverage/lcov.info`) |
| `--coverage-report-html <dir>` | Generate HTML report with line highlighting |
| `--coverage-report [file]` | LCOV output path (default: `coverage/lcov.info`) |
| `--coverage-report-html [dir]` | Generate HTML report (default: `coverage/html`) |
| `--coverage-min <percent>` | Minimum coverage threshold |
| `--no-coverage-report` | Console output only, no LCOV file |

Expand Down Expand Up @@ -313,8 +320,8 @@ bashunit test tests/ --coverage --coverage-paths src/,lib/ --coverage-min 80
| `--coverage` | Enable coverage tracking |
| `--coverage-paths <paths>` | Comma-separated paths to track (default: auto-discover from test files) |
| `--coverage-exclude <patterns>` | Comma-separated patterns to exclude (default: `tests/*,vendor/*,*_test.sh`) |
| `--coverage-report <file>` | LCOV output file path (default: `coverage/lcov.info`) |
| `--coverage-report-html <dir>` | Generate HTML coverage report with line-by-line highlighting |
| `--coverage-report [file]` | LCOV output file path (default: `coverage/lcov.info`) |
| `--coverage-report-html [dir]` | Generate HTML report (default: `coverage/html`) |
| `--coverage-min <percent>` | Minimum coverage percentage; fails if below |
| `--no-coverage-report` | Show console report only, don't generate LCOV file |

Expand Down
2 changes: 1 addition & 1 deletion docs/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The DEBUG trap adds overhead to test execution. For large test suites, consider
| `--coverage-paths <paths>` | Comma-separated paths to track (default: auto-discover from test files) |
| `--coverage-exclude <patterns>` | Comma-separated exclusion patterns |
| `--coverage-report <file>` | LCOV report output path (default: `coverage/lcov.info`) |
| `--coverage-report-html <dir>` | Generate HTML coverage report with line-by-line details |
| `--coverage-report-html [dir]` | Generate HTML report (default: `coverage/html`) |
| `--coverage-min <percent>` | Minimum coverage threshold (fails if below) |
| `--no-coverage-report` | Disable LCOV file generation (console only) |

Expand Down
16 changes: 8 additions & 8 deletions src/console_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ Options:
-h, --help Show this help message

Coverage:
--coverage Enable code coverage tracking
--coverage-paths <paths> Source paths to track (comma-separated, default: src/)
--coverage-exclude <pats> Patterns to exclude (comma-separated)
--coverage-report <file> Output file (default: coverage/lcov.info)
--coverage-report-html <dir> Generate HTML coverage report
--coverage-min <pct> Fail if coverage below percentage
--no-coverage-report Disable file output, console only
--coverage Enable code coverage tracking
--coverage-paths <paths> Source paths to track (default: auto-discover)
--coverage-exclude <pats> Patterns to exclude (comma-separated)
--coverage-report [file] Output file (default: coverage/lcov.info)
--coverage-report-html [dir] HTML report (default: coverage/html)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the other parameters are with <>, is there any reason to use [] here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great question! I updated the docs to reflect the answer

Screenshot 2025-12-22 at 00 39 44

--coverage-min <pct> Fail if coverage below percentage
--no-coverage-report Disable file output, console only

Examples:
bashunit test tests/
Expand All @@ -139,7 +139,7 @@ Examples:
bashunit test -a equals "foo" "foo"
bashunit test tests/ --coverage
bashunit test tests/ --coverage --coverage-min 80
bashunit test tests/ --coverage --coverage-report-html coverage/html
bashunit test tests/ --coverage-report-html
EOF
}

Expand Down
9 changes: 7 additions & 2 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,14 @@ function bashunit::main::cmd_test() {
;;
--coverage-report-html)
# shellcheck disable=SC2034
BASHUNIT_COVERAGE_REPORT_HTML="$2"
# Use default if no value provided or next arg is a flag
if [[ -z "${2:-}" || "${2:-}" == -* ]]; then
BASHUNIT_COVERAGE_REPORT_HTML="coverage/html"
else
BASHUNIT_COVERAGE_REPORT_HTML="$2"
shift
fi
_bashunit_coverage_opt_set=true
shift
;;
*)
raw_args+=("$1")
Expand Down
Loading