summaryrefslogtreecommitdiffstats
path: root/bindings/python
diff options
context:
space:
mode:
authorArnaud A. de Grandmaison <arnaud.adegm@gmail.com>2012-07-09 11:57:30 +0000
committerArnaud A. de Grandmaison <arnaud.adegm@gmail.com>2012-07-09 11:57:30 +0000
commitb1614041ac297f2e1fca359e9b77291ae5006832 (patch)
tree3d2014530024897af7bae3bd3bf3699ae1f01efa /bindings/python
parent4990890fc9428f98bef90ba349203a648c592778 (diff)
[cindex.py] fix infinite iteration of compilation database CompileCommands
Patch by David Röthlisberger git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159926 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python')
-rw-r--r--bindings/python/clang/cindex.py2
-rw-r--r--bindings/python/tests/cindex/test_cdb.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index afbfe3d2ae..0aea4669e8 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -2162,7 +2162,7 @@ class CompileCommands(object):
def __getitem__(self, i):
cc = CompileCommands_getCommand(self.ccmds, i)
- if cc is None:
+ if not cc:
raise IndexError
return CompileCommand(cc, self)
diff --git a/bindings/python/tests/cindex/test_cdb.py b/bindings/python/tests/cindex/test_cdb.py
index 38de4b1c14..374f99bcbf 100644
--- a/bindings/python/tests/cindex/test_cdb.py
+++ b/bindings/python/tests/cindex/test_cdb.py
@@ -61,6 +61,14 @@ def test_2_compilecommand():
for arg, exp in zip(cmds[i].arguments, expected[i]['line']):
assert arg.spelling == exp
+def test_compilecommand_iterator_stops():
+ """Check that iterator stops after the correct number of elements"""
+ cdb = CompilationDatabase.fromDirectory(kInputsDir)
+ count = 0
+ for cmd in cdb.getCompileCommands('/home/john.doe/MyProject/project2.cpp'):
+ count += 1
+ assert count <= 2
+
def test_compilationDB_references():
"""Ensure CompilationsCommands are independent of the database"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)