summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-12-18 22:44:13 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-12-18 22:44:13 -0500
commit1319240b4e7cce5e293e0f92eb887c4b97f03239 (patch)
tree3c35ce529a619d80d858fd6cb6d42feeddbfff68
parentab25c4b2256fc136c3a70494a80741e6a41d01fd (diff)
downloadpython-coveragepy-git-1319240b4e7cce5e293e0f92eb887c4b97f03239.tar.gz
Fix #496, while-true loop with a continue.
-rw-r--r--CHANGES.rst15
-rw-r--r--coverage/parser.py2
-rw-r--r--tests/test_arcs.py16
3 files changed, 28 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 98cdbea6..40f82e61 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -18,10 +18,16 @@ Unreleased
data, leaving you with an empty .coverage data file. Fixes issues
`issue 525`_, `issue 412`_, `issue 516`_, and probably `issue 511`_.
-- Branch coverage could misunderstand a finally clause on a try block that
- never continued on to the following statement, as described in `issue 493`_.
- This is now fixed. Thanks to Joe Doherty for the report and Loïc Dachary for
- the fix.
+- Branch coverage fixes:
+
+ - Branch coverage could misunderstand a finally clause on a try block that
+ never continued on to the following statement, as described in `issue
+ 493`_. This is now fixed. Thanks to Joe Doherty for the report and Loïc
+ Dachary for the fix.
+
+ - A while-loop with a constant condition (while True) and a continue
+ statement would be mis-analyzed, as described in `issue 496`_. This is now
+ fixed, thanks to a bug report by Eli Skeggs and a fix by Loïc Dachary.
- Options can now be read from a tox.ini file, if any. Like setup.cfg, sections
are prefixed with "coverage:", so ``[run]`` options will be read from the
@@ -91,6 +97,7 @@ Unreleased
.. _issue 265: https://bitbucket.org/ned/coveragepy/issues/265/when-using-source-include-is-silently
.. _issue 412: https://bitbucket.org/ned/coveragepy/issues/412/coverage-combine-should-error-if-no
.. _issue 493: https://bitbucket.org/ned/coveragepy/issues/493/confusing-branching-failure
+.. _issue 496: https://bitbucket.org/ned/coveragepy/issues/496/incorrect-coverage-with-branching-and
.. _issue 505: https://bitbucket.org/ned/coveragepy/issues/505/use-canonical-filename-for-debounce
.. _issue 514: https://bitbucket.org/ned/coveragepy/issues/514/path-to-problem-file-not-reported-when
.. _issue 510: https://bitbucket.org/ned/coveragepy/issues/510/erase-still-needed-in-42
diff --git a/coverage/parser.py b/coverage/parser.py
index 8b71b51c..f65e4abb 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -952,7 +952,7 @@ class AstArcAnalyzer(object):
start = to_top = self.line_for_node(node.test)
if constant_test:
to_top = self.line_for_node(node.body[0])
- self.block_stack.append(LoopBlock(start=start))
+ self.block_stack.append(LoopBlock(start=to_top))
from_start = ArcStart(start, cause="the condition on line {lineno} was never true")
exits = self.add_body_arcs(node.body, from_start=from_start)
for xit in exits:
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index 5baf9476..36eb4faa 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -270,6 +270,22 @@ class LoopArcTest(CoverageTest):
arcz=arcz,
)
+ def test_bug_496_continue_in_constant_while(self):
+ # https://bitbucket.org/ned/coveragepy/issue/496
+ if env.PY3:
+ arcz = ".1 12 23 34 43 45 5."
+ else:
+ arcz = ".1 12 2-1 23 34 42 45 5."
+ self.check_coverage("""\
+ up = iter('ta')
+ while True:
+ char = next(up)
+ if char == 't': continue
+ break
+ """,
+ arcz=arcz
+ )
+
def test_for_if_else_for(self):
self.check_coverage("""\
def branches_2(l):