Fix heredoc with space not reported as covered (fixes #102)#103
Fix heredoc with space not reported as covered (fixes #102)#103infertux merged 1 commit intoinfertux:masterfrom
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
📝 WalkthroughWalkthroughThe heredoc detection regex in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/bashcov/lexer.rb (1)
44-44: Good fix — consider[ \t]*instead of\s*to avoid matching newlines.
\s*matches newlines, which could theoretically cause a false match if<<-appears at the end of a line (since the delimiter must be on the same line in bash). Using[ \t]*would be more precise:Suggested tweak
- /\A[^\n]+<<-?\s*'?(\w+)'?.*$.*\1/m + /\A[^\n]+<<-?[ \t]*'?(\w+)'?.*$.*\1/mLow risk either way — just a minor robustness improvement.
While technically more precise, |
|
@infertux Can you help with the review please |
|
@sonikaarora Did you use AI to create the pull request? The formatting looks suspiciously nice ;) Either way, it's a valid bug fix so thank you very much. In the future, it would be nice to add a test case to prevent any regressions though. |
Fix heredoc coverage for heredocs with spaces
Fixes #102
Problem
When using heredocs with spaces between
<<and the delimiter (e.g.,<< EOF), the heredoc content lines were not being marked as covered, even though they were executed.Example from issue #102:
In this case, only line 1 was marked as covered, while lines 2-3 (heredoc content and terminator) were reported as uncovered.
Root Cause
The regex pattern in
lib/bashcov/lexer.rb(line 44) did not account for optional whitespace between the heredoc operator and delimiter:/\A[^\n]+<<-?'?(\w+)'?.*$.*\1/mThis pattern matched heredocs without spaces (
<<EOF) but failed to match heredocs with spaces (<< EOF).Solution
Added
\s*to allow optional whitespace between<<-?and the delimiter:/\A[^\n]+<<-?\s*'?(\w+)'?.*$.*\1/mTesting
Tested with the exact script from issue #102:
Test output: