[PATCH] D2916: Add test for Python binding Index read.
Brian Gesiak
modocache at gmail.com
Wed Aug 5 10:59:50 PDT 2015
modocache updated this revision to Diff 31376.
modocache added a comment.
Rebase onto master.
http://reviews.llvm.org/D2916
Files:
bindings/python/tests/cindex/test_index.py
bindings/python/tests/cindex/test_translation_unit.py
bindings/python/tests/cindex/util.py
Index: bindings/python/tests/cindex/util.py
===================================================================
--- bindings/python/tests/cindex/util.py
+++ bindings/python/tests/cindex/util.py
@@ -1,5 +1,7 @@
# This file provides common utility functions for the test suite.
+import tempfile
+
from clang.cindex import Cursor
from clang.cindex import TranslationUnit
@@ -30,6 +32,16 @@
return TranslationUnit.from_source(name, args, unsaved_files=[(name,
source)])
+def save_tu(tu):
+ """Convenience API to save a TranslationUnit to a file.
+
+ Returns the filename it was saved to.
+ """
+ _, path = tempfile.mkstemp()
+ tu.save(path)
+
+ return path
+
def get_cursor(source, spelling):
"""Obtain a cursor from a source object.
Index: bindings/python/tests/cindex/test_translation_unit.py
===================================================================
--- bindings/python/tests/cindex/test_translation_unit.py
+++ bindings/python/tests/cindex/test_translation_unit.py
@@ -1,6 +1,5 @@
import gc
import os
-import tempfile
from clang.cindex import CursorKind
from clang.cindex import Cursor
@@ -13,6 +12,7 @@
from clang.cindex import TranslationUnit
from .util import get_cursor
from .util import get_tu
+from .util import save_tu
kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
@@ -89,16 +89,6 @@
for i in zip(inc, tu.get_includes()):
assert eq(i[0], i[1])
-def save_tu(tu):
- """Convenience API to save a TranslationUnit to a file.
-
- Returns the filename it was saved to.
- """
- _, path = tempfile.mkstemp()
- tu.save(path)
-
- return path
-
def test_save():
"""Ensure TranslationUnit.save() works."""
Index: bindings/python/tests/cindex/test_index.py
===================================================================
--- bindings/python/tests/cindex/test_index.py
+++ bindings/python/tests/cindex/test_index.py
@@ -1,12 +1,26 @@
-from clang.cindex import *
import os
+from clang.cindex import Index
+from clang.cindex import TranslationUnit
+from .util import get_cursor
+from .util import get_tu
+from .util import save_tu
+
kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
def test_create():
index = Index.create()
-# FIXME: test Index.read
+def test_read():
+ translation_unit = get_tu('int foo();')
+ path = save_tu(translation_unit)
+
+ index = Index.create()
+ read_unit = index.read(path)
+ assert len(read_unit.diagnostics) == 0
+
+ cursor = get_cursor(read_unit, 'foo')
+ assert cursor is not None
def test_parse():
index = Index.create()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2916.31376.patch
Type: text/x-patch
Size: 2669 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150805/00c1a986/attachment.bin>
More information about the cfe-commits
mailing list