Don't generate line 0 in profdata_coverage_file.rb from line with error #387
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.
I was able to reproduce issue #290 by having error in coverage processed using
profdata_coverage_file.rb
Problem description
When passing Cobertura XML format generated using
slather
tosonar-scanner
, it crashes on error like this:It makes sense since there is no "line 0" in source code (text file).
In my case there was line number 0 generated in Cobertura XML output like this:
I found it is because the source being passed to
ProfdataCoverageFile
contains error in following format:Implementation
This change just filters out these lines from
source_code_lines
and it fixes the issue in my case.It is implemented only in case of
self.line_numbers_first
because this case is easy and fast to detect and handle.Detecting the issue if
self.line_numbers_first == false
would require rather complex regex due to duplication of valid source line in the error listing.Solution
This change prevents the
0
line from appearing in XML coverage report.Tests
Not having good enough knowledge of
slather
andruby
, I didn't find simple / elegant solution to adjust tests for this case (tests are usingline_numbers_first = false
, while my fix is fortrue
case).Sorry about that.
Notes
I will appreciate any suggestion or better solution for this problem.
However I would appreciate some fix for this problem to be released in
slather
so I don't have to use fork or some XML text manipulation in production to workaround this problem.Thanks to everyone for your time to review!