diff options
author | Tobias Grosser <grosser@fim.uni-passau.de> | 2013-03-19 15:30:48 +0000 |
---|---|---|
committer | Tobias Grosser <grosser@fim.uni-passau.de> | 2013-03-19 15:30:48 +0000 |
commit | 14a2d7b9f0df50ff9874a7f721821d28e8323988 (patch) | |
tree | a1d27a5166ffa20a5ca839d9207c0b65033f0745 /clang/bindings/python/tests | |
parent | 9a8f0f55d5973fb90e216b0c78fba2f84373faca (diff) | |
download | bcm5719-llvm-14a2d7b9f0df50ff9874a7f721821d28e8323988.tar.gz bcm5719-llvm-14a2d7b9f0df50ff9874a7f721821d28e8323988.zip |
cindex.py: Handle NULL pointers when parsing translation units
The code inside cindex.py was comparing NULL pointer returned by
clang_parseTranslationUnit and clang_createTranslationUnit with None.
However, as illustrated by the two tests I've added, those conditions
were ineffective which resulted in assert triggering later on.
Instead, a pointer is now treated as a boolean value, a NULL pointer being
False.
Contributed-by: Xavier Deguillard <deguilx@gmail.com>
llvm-svn: 177408
Diffstat (limited to 'clang/bindings/python/tests')
-rw-r--r-- | clang/bindings/python/tests/cindex/test_translation_unit.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py index c91f126097a..f77998e5245 100644 --- a/clang/bindings/python/tests/cindex/test_translation_unit.py +++ b/clang/bindings/python/tests/cindex/test_translation_unit.py @@ -8,6 +8,7 @@ from clang.cindex import Index from clang.cindex import SourceLocation from clang.cindex import SourceRange from clang.cindex import TranslationUnitSaveError +from clang.cindex import TranslationUnitLoadError from clang.cindex import TranslationUnit from .util import get_cursor from .util import get_tu @@ -239,3 +240,19 @@ def test_get_tokens_gc(): del tokens gc.collect() gc.collect() # Just in case. + +def test_fail_from_source(): + path = os.path.join(kInputsDir, 'non-existent.cpp') + try: + tu = TranslationUnit.from_source(path) + except TranslationUnitLoadError: + tu = None + assert tu == None + +def test_fail_from_ast_file(): + path = os.path.join(kInputsDir, 'non-existent.ast') + try: + tu = TranslationUnit.from_ast_file(path) + except TranslationUnitLoadError: + tu = None + assert tu == None |