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 coverage reporting for gcc 8 and code that uses templates #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion cpp_coveralls/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ def parse_gcov_file(args, fobj, filename):
cov_num = report_fields[0].strip()
line_num = int(line_num)
text = report_fields[2]
if line_num == 0:

# skip gcov meta data and
# repeated lines for instances(templated code), because the 1st occurence reports the total count, we can
# ignore the instance specializations
if line_num == 0 or line_num <= len(coverage):
continue
if re.search(r'\bLCOV_EXCL_START\b', text):
if ignoring:
Expand Down
39 changes: 39 additions & 0 deletions cpp_coveralls/parse_gcov_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
#

import io
import unittest

from . import coverage


class ParseGcovTest(unittest.TestCase):
# test template example from the documentation (https://gcc.gnu.org/onlinedocs/gcc/Invoking-Gcov.html#Invoking-Gcov)
def test_templated_coverage(self):
args = coverage.create_args("")
f = io.BytesIO(b"""
-: 0:Source:tmp.cpp
-: 0:Working directory:/home/gcc/testcase
-: 0:Graph:tmp.gcno
-: 0:Data:tmp.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include <stdio.h>
-: 2:
-: 3:template<class T>
-: 4:class Foo
-: 5:{
-: 6: public:
1*: 7: Foo(): b (1000) {}
------------------
Foo<char>::Foo():
#####: 7: Foo(): b (1000) {}
------------------
Foo<int>::Foo():
1: 7: Foo(): b (1000) {}
------------------
""")
parsed_lines = coverage.parse_gcov_file(args, f, "bar")
self.assertEqual(7, len(parsed_lines))
self.assertEqual(1, parsed_lines[6])