diff --git a/coverage/annotate.py b/coverage/annotate.py index 48e2b91ce..429e2cbfc 100644 --- a/coverage/annotate.py +++ b/coverage/annotate.py @@ -60,6 +60,7 @@ def annotate_file(self, fr, analysis): statements = sorted(analysis.statements) missing = sorted(analysis.missing) excluded = sorted(analysis.excluded) + missing_branches = sorted(analysis.missing_branch_arcs().keys()) if self.directory: dest_file = os.path.join(self.directory, flat_rootname(fr.relative_filename())) @@ -96,7 +97,10 @@ def annotate_file(self, fr, analysis): elif lineno in excluded: dest.write(u'- ') elif covered: - dest.write(u'> ') + if lineno in missing_branches: + dest.write(u'~ ') + else: + dest.write(u'> ') else: dest.write(u'! ') diff --git a/tests/farm/annotate/gold_branch/white.py,cover b/tests/farm/annotate/gold_branch/white.py,cover new file mode 100644 index 000000000..e164227d4 --- /dev/null +++ b/tests/farm/annotate/gold_branch/white.py,cover @@ -0,0 +1,36 @@ + # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 + # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt + + # A test case sent to me by Steve White + +> def f(self): +! if self==1: +! pass +! elif self.m('fred'): +! pass +! elif (g==1) and (b==2): +! pass +! elif self.m('fred')==True: +! pass +! elif ((g==1) and (b==2))==True: +! pass +! else: +! pass + +> def g(x): +~ if x == 1: +> a = 1 +! else: +! a = 2 + +> g(1) + +> def h(x): +- if 0: #pragma: no cover +- pass +~ if x == 1: +! a = 1 +> else: +> a = 2 + +> h(2) diff --git a/tests/farm/annotate/run_branch.py b/tests/farm/annotate/run_branch.py new file mode 100644 index 000000000..eb9f277c7 --- /dev/null +++ b/tests/farm/annotate/run_branch.py @@ -0,0 +1,12 @@ +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt + +from tests.test_farm import clean, compare, copy, run + +copy("src", "out") +run(""" + coverage run --branch white.py + coverage annotate white.py + """, rundir="out") +compare("out", "gold_branch", "*,cover") +clean("out")