]> granicus.if.org Git - clang/commitdiff
[cindex.py] fix infinite iteration of compilation database CompileCommands
authorArnaud A. de Grandmaison <arnaud.adegm@gmail.com>
Mon, 9 Jul 2012 11:57:30 +0000 (11:57 +0000)
committerArnaud A. de Grandmaison <arnaud.adegm@gmail.com>
Mon, 9 Jul 2012 11:57:30 +0000 (11:57 +0000)
Patch by David Röthlisberger

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159926 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/python/clang/cindex.py
bindings/python/tests/cindex/test_cdb.py

index afbfe3d2ae39cbd5541511ddfb7caf99391608d1..0aea4669e89810841bee9a3d99e71efcabcbc6da 100644 (file)
@@ -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)
 
index 38de4b1c14e7492b971b61d3365c1f3a5de9abb6..374f99bcbf6eb32b2d58b7166eef8238fbb5d1dc 100644 (file)
@@ -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)