Auto discover coverage paths from test file names#571
Merged
Chemaclass merged 5 commits intoDec 21, 2025
Conversation
When --coverage-paths is not specified, automatically find source files matching the test files base name (e.g., assert_test.sh -> assert*.sh). Priority: CLI flag > env var > auto-discovery
- Remove subshell check that blocked coverage inside $(...) substitutions
- Exclude control flow keywords from executable lines: then, else, fi,
do, done, esac, in, ;;, ;&, ;;&
- Exclude case patterns (--option), *)) and standalone )
- Fix empty array handling for Bash 3.2 compatibility
JesusValeraDev
approved these changes
Dec 21, 2025
4ac1e30 to
9a0b61c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📚 Description
This PR introduces automatic source file discovery for coverage tracking based on test file naming conventions. Previously, users had to manually specify
BASHUNIT_COVERAGE_PATHSto indicate which files to track. Now, bashunit intelligently discovers source files by analyzing test file names.The Problem
When running coverage on a specific test file like:
Users had to explicitly set
BASHUNIT_COVERAGE_PATHS="src/assert.sh"to track the corresponding source file. This was tedious and error-prone, especially when running individual tests.The Solution
bashunit now automatically discovers source files based on test file naming conventions:
tests/unit/assert_test.shsrc/assert.sh,src/assert_*.shtests/unit/RunnerTest.shsrc/Runner.sh,src/Runner*.shThe auto-discovery:
_test.shandTest.shsuffixesBASHUNIT_COVERAGE_PATHSis not explicitly set🔖 Changes
Auto-discovery feature
bashunit::coverage::auto_discover_paths()function insrc/coverage.sh_BASHUNIT_DEFAULT_COVERAGE_PATHSfrom"src/"to""to enable auto-discoveryCoverage line detection improvements
then,else,fi,do,done,esac,in;;,;&,;;&--option)and*))charactersBug fixes
Tests
✅ To-do list
CHANGELOG.mdto reflect the new feature or fix