[cfe-commits] r159926 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_cdb.py

Arnaud A. de Grandmaison arnaud.adegm at gmail.com
Mon Jul 9 04:57:30 PDT 2012


Author: aadg
Date: Mon Jul  9 06:57:30 2012
New Revision: 159926

URL: http://llvm.org/viewvc/llvm-project?rev=159926&view=rev
Log:
[cindex.py] fix infinite iteration of compilation database CompileCommands

Patch by David Röthlisberger

Modified:
    cfe/trunk/bindings/python/clang/cindex.py
    cfe/trunk/bindings/python/tests/cindex/test_cdb.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=159926&r1=159925&r2=159926&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Mon Jul  9 06:57:30 2012
@@ -2162,7 +2162,7 @@
 
     def __getitem__(self, i):
         cc = CompileCommands_getCommand(self.ccmds, i)
-        if cc is None:
+        if not cc:
             raise IndexError
         return CompileCommand(cc, self)
 

Modified: cfe/trunk/bindings/python/tests/cindex/test_cdb.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cdb.py?rev=159926&r1=159925&r2=159926&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cdb.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cdb.py Mon Jul  9 06:57:30 2012
@@ -61,6 +61,14 @@
         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)





More information about the cfe-commits mailing list