Skip to content

Commit

Permalink
Fix: incorrect path for header can still generate
Browse files Browse the repository at this point in the history
Fixes gcovr#271
  • Loading branch information
ensky committed Mar 17, 2020
1 parent e4dfebe commit 7f29ad2
Show file tree
Hide file tree
Showing 14 changed files with 1,485 additions and 6 deletions.
17 changes: 11 additions & 6 deletions gcovr/html_generator.py
Expand Up @@ -16,6 +16,7 @@
from .version import __version__
from .utils import commonpath, sort_coverage
from .coverage import FileCoverage
from .utils import Logger


class lazy(object):
Expand Down Expand Up @@ -87,6 +88,8 @@ def coverage_to_color(coverage, medium_threshold, high_threshold):
# Produce an HTML report
#
def print_html_report(covdata, output_file, options):
logger = Logger(options.verbose)

medium_threshold = options.html_medium_threshold
high_threshold = options.html_high_threshold
details = options.html_details
Expand Down Expand Up @@ -245,12 +248,14 @@ def print_html_report(covdata, output_file, options):
data['ROWS'] = []
currdir = os.getcwd()
os.chdir(options.root_dir)
with io.open(data['FILENAME'], 'r', encoding=options.source_encoding,
errors='replace') as INPUT:
for ctr, line in enumerate(INPUT, 1):
data['ROWS'].append(
source_row(ctr, line.rstrip(), cdata.lines.get(ctr))
)
try:
with io.open(data['FILENAME'], 'r', encoding=options.source_encoding, errors='replace') as INPUT:
for ctr, line in enumerate(INPUT, 1):
data['ROWS'].append(
source_row(ctr, line.rstrip(), cdata.lines.get(ctr))
)
except IOError as e:
logger.warn('File Generation failed: {filename}, reason={reason}', filename=data['FILENAME'], reason=repr(e))
os.chdir(currdir)

htmlString = templates().get_template('source_page.html').render(**data)
Expand Down
27 changes: 27 additions & 0 deletions gcovr/tests/subfolder-includes/Makefile
@@ -0,0 +1,27 @@
all:
make -C subfolder

run: txt xml html sonarqube json

txt:
./subfolder/subfolder/testcase
$(GCOVR) -d -o coverage.txt

xml:
./subfolder/subfolder/testcase
$(GCOVR) -d -x -o coverage.xml

html:
./subfolder/subfolder/testcase
$(GCOVR) -d --html-details -o coverage.html

sonarqube:
./subfolder/subfolder/testcase
$(GCOVR) -d --sonarqube sonarqube.xml

json:
# pass

clean:
make -C subfolder clean
rm -f coverage.txt coverage.xml coverage*.html sonarqube.xml
1 change: 1 addition & 0 deletions gcovr/tests/subfolder-includes/README
@@ -0,0 +1 @@
A subfolder includes pattern that causes include header file has a incorrect relative path in .gcov file.
4 changes: 4 additions & 0 deletions gcovr/tests/subfolder-includes/include/lib.h
@@ -0,0 +1,4 @@
int foo();
inline int bar() {
return 1;
}

0 comments on commit 7f29ad2

Please sign in to comment.