Skip to content

Commit 076fe27

Browse files
committed
Don't count lines containing only function definitions as uncovered
1 parent e805626 commit 076fe27

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

fix_coverage.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ def main():
7979

8080
force_cover_active += line.count("_FORCE_COVER_START_")
8181

82+
# Special case where region of forced coverage starts at
83+
# the end of this line
84+
if line.endswith("_FORCE_COVER_START_") and \
85+
force_cover_active == line.count("_FORCE_COVER_START_"):
86+
lines.append(line)
87+
continue
88+
8289
if not force_cover_active: # Don't need to change line because
8390
lines.append(line) # we aren't in a template definition
8491
continue

force_cover.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ class TemplateClassHandler : public MatchFinder::MatchCallback {
4343
return;
4444
}
4545

46-
Rewrite.InsertText(ClassNode->getLocStart(), "/*_FORCE_COVER_START_*/", true, true);
46+
std::string source_range = clang::Lexer::getSourceText(clang::CharSourceRange::getCharRange(ClassNode->getSourceRange()), Rewrite.getSourceMgr(), Rewrite.getLangOpts()).str();
47+
std::size_t loc = source_range.find_first_of("{");
48+
if (loc == std::string::npos) {
49+
loc = 0;
50+
} else {
51+
loc++;
52+
}
53+
54+
Rewrite.InsertText(ClassNode->getLocStart().getLocWithOffset(loc), "/*_FORCE_COVER_START_*/", true, true);
4755
Rewrite.InsertText(ClassNode->getLocEnd().getLocWithOffset(1), "/*_FORCE_COVER_END_*/", true, true);
4856
}
4957

@@ -64,7 +72,15 @@ class TemplateFunctionHandler : public MatchFinder::MatchCallback {
6472
return;
6573
}
6674

67-
Rewrite.InsertText(FunctionNode->getLocStart(), "/*_FORCE_COVER_START_*/", true, true);
75+
std::string source_range = clang::Lexer::getSourceText(clang::CharSourceRange::getCharRange(FunctionNode->getSourceRange()), Rewrite.getSourceMgr(), Rewrite.getLangOpts()).str();
76+
std::size_t loc = source_range.find_first_of("{");
77+
if (loc == std::string::npos) {
78+
loc = 0;
79+
} else {
80+
loc++;
81+
}
82+
83+
Rewrite.InsertText(FunctionNode->getLocStart().getLocWithOffset(loc), "/*_FORCE_COVER_START_*/", true, true);
6884
Rewrite.InsertText(FunctionNode->getLocEnd().getLocWithOffset(1), "/*_FORCE_COVER_END_*/", true, true);
6985

7086
}

0 commit comments

Comments
 (0)