Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of gcov metadata #601

Merged
merged 4 commits into from Apr 3, 2022

Conversation

Spacetown
Copy link
Member

Gcc-11 has metadata lines without values in the gcov file (see #596). This PR add support for this lines and uses as value None.

Closes #596.

gcc-11 has metadata line "-: 0:Source is newer than graph" which throws an error.
Add the directory of the gcov file to the heuristic to fix test shared_lib for gcc-11.
@Spacetown Spacetown added this to the 5.2 milestone Apr 3, 2022
@Spacetown Spacetown requested a review from latk April 3, 2022 19:56
@Spacetown Spacetown force-pushed the fix_parsing_of_gcov_metadata branch from 455e3b4 to f1d1b15 Compare April 3, 2022 19:57
@codecov
Copy link

codecov bot commented Apr 3, 2022

Codecov Report

Merging #601 (543c495) into master (79a45db) will decrease coverage by 0.05%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master     #601      +/-   ##
==========================================
- Coverage   95.19%   95.14%   -0.06%     
==========================================
  Files          23       23              
  Lines        3350     3355       +5     
  Branches      614      616       +2     
==========================================
+ Hits         3189     3192       +3     
- Misses         89       90       +1     
- Partials       72       73       +1     
Flag Coverage Δ
ubuntu-18.04 93.94% <75.00%> (-0.06%) ⬇️
windows-2019 94.79% <75.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gcovr/gcov.py 75.59% <33.33%> (-0.51%) ⬇️
gcovr/gcov_parser.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 79a45db...543c495. Read the comment docs.

Copy link
Member

@latk latk left a comment

Choose a reason for hiding this comment

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

simple and elegant :)

Using a None value does kind of violate the type annotations around that code, but for now this won't break anything and that can be fixed in the next refactoring push.

(If you want to fix this, note that now the metadata values are not str but Optional[str]. This also means the metadata["Source"] access in process_gcov_data() could be None, as far as the type system is concerned. The most elegant approach to solve this would be to move the “Source must exist” check from the metadata-parser into process-gcov-data, to something like source = metadata.get("Source"); if source is None: raise RuntimeError(...))

@Spacetown
Copy link
Member Author

@latk I've moved the strip to the parsing of the metadata. How can I force a leading whitespace in the doctest if the editor removes them.

Always strip metadata value.
@Spacetown Spacetown force-pushed the fix_parsing_of_gcov_metadata branch from 0e47ad3 to ad0a8fb Compare April 3, 2022 20:21
@latk
Copy link
Member

latk commented Apr 3, 2022

How can I force a leading whitespace in the doctest if the editor removes them.

I don't entirely understand. Could you show an example of what you want to do?

@Spacetown
Copy link
Member Author

I wan't to add leading whitespaces to the following doctest:

    >>> parse_metadata('''
    ...   -: 0:Foo:bar
    ...   -: 0:Key:123
    ... '''.splitlines())

The whitepaces shouldn't be removed by the editor on save.

One solution is to write a single line string with \n.

@Spacetown Spacetown merged commit 7b6947b into gcovr:master Apr 3, 2022
@Spacetown Spacetown deleted the fix_parsing_of_gcov_metadata branch April 3, 2022 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing gcov file fails on "Source is newer than graph" line
2 participants