summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/tools/clang/bindings/python/tests
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2017-01-14 19:55:43 +0000
committerpatrick <patrick@openbsd.org>2017-01-14 19:55:43 +0000
commitbd3306aecb3a15e8967143b8cdbbccf2b1b19b74 (patch)
tree309a8132b44564b9e634c0da6815187ce8eab27c /gnu/llvm/tools/clang/bindings/python/tests
parentkillp -a should not kill the window if only one pane. (diff)
downloadwireguard-openbsd-bd3306aecb3a15e8967143b8cdbbccf2b1b19b74.tar.xz
wireguard-openbsd-bd3306aecb3a15e8967143b8cdbbccf2b1b19b74.zip
Import LLVM 3.9.1 including clang and lld.
Diffstat (limited to 'gnu/llvm/tools/clang/bindings/python/tests')
-rw-r--r--gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cdb.py17
-rw-r--r--gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cursor.py82
-rw-r--r--gnu/llvm/tools/clang/bindings/python/tests/cindex/test_diagnostics.py12
3 files changed, 106 insertions, 5 deletions
diff --git a/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cdb.py b/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cdb.py
index e1f824f797f..35fe3e108a1 100644
--- a/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cdb.py
+++ b/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cdb.py
@@ -38,27 +38,34 @@ def test_all_compilecommand():
cmds = cdb.getAllCompileCommands()
assert len(cmds) == 3
expected = [
+ { 'wd': '/home/john.doe/MyProject',
+ 'file': '/home/john.doe/MyProject/project.cpp',
+ 'line': ['clang++', '-o', 'project.o', '-c',
+ '/home/john.doe/MyProject/project.cpp']},
{ 'wd': '/home/john.doe/MyProjectA',
+ 'file': '/home/john.doe/MyProject/project2.cpp',
'line': ['clang++', '-o', 'project2.o', '-c',
'/home/john.doe/MyProject/project2.cpp']},
{ 'wd': '/home/john.doe/MyProjectB',
+ 'file': '/home/john.doe/MyProject/project2.cpp',
'line': ['clang++', '-DFEATURE=1', '-o', 'project2-feature.o', '-c',
'/home/john.doe/MyProject/project2.cpp']},
- { 'wd': '/home/john.doe/MyProject',
- 'line': ['clang++', '-o', 'project.o', '-c',
- '/home/john.doe/MyProject/project.cpp']}
+
]
for i in range(len(cmds)):
assert cmds[i].directory == expected[i]['wd']
+ assert cmds[i].filename == expected[i]['file']
for arg, exp in zip(cmds[i].arguments, expected[i]['line']):
assert arg == exp
def test_1_compilecommand():
"""Check file with single compile command"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)
- cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp')
+ file = '/home/john.doe/MyProject/project.cpp'
+ cmds = cdb.getCompileCommands(file)
assert len(cmds) == 1
- assert cmds[0].directory == '/home/john.doe/MyProject'
+ assert cmds[0].directory == os.path.dirname(file)
+ assert cmds[0].filename == file
expected = [ 'clang++', '-o', 'project.o', '-c',
'/home/john.doe/MyProject/project.cpp']
for arg, exp in zip(cmds[0].arguments, expected):
diff --git a/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cursor.py b/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cursor.py
index c5ea50516ad..6c8230d4283 100644
--- a/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_cursor.py
@@ -112,6 +112,88 @@ def test_is_const_method():
assert foo.is_const_method()
assert not bar.is_const_method()
+def test_is_converting_constructor():
+ """Ensure Cursor.is_converting_constructor works."""
+ source = 'class X { explicit X(int); X(double); X(); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+
+ assert len(xs) == 4
+ assert xs[0].kind == CursorKind.CLASS_DECL
+ cs = xs[1:]
+ assert cs[0].kind == CursorKind.CONSTRUCTOR
+ assert cs[1].kind == CursorKind.CONSTRUCTOR
+ assert cs[2].kind == CursorKind.CONSTRUCTOR
+
+ assert not cs[0].is_converting_constructor()
+ assert cs[1].is_converting_constructor()
+ assert not cs[2].is_converting_constructor()
+
+
+def test_is_copy_constructor():
+ """Ensure Cursor.is_copy_constructor works."""
+ source = 'class X { X(); X(const X&); X(X&&); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+ assert xs[0].kind == CursorKind.CLASS_DECL
+ cs = xs[1:]
+ assert cs[0].kind == CursorKind.CONSTRUCTOR
+ assert cs[1].kind == CursorKind.CONSTRUCTOR
+ assert cs[2].kind == CursorKind.CONSTRUCTOR
+
+ assert not cs[0].is_copy_constructor()
+ assert cs[1].is_copy_constructor()
+ assert not cs[2].is_copy_constructor()
+
+def test_is_default_constructor():
+ """Ensure Cursor.is_default_constructor works."""
+ source = 'class X { X(); X(int); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+ assert xs[0].kind == CursorKind.CLASS_DECL
+ cs = xs[1:]
+ assert cs[0].kind == CursorKind.CONSTRUCTOR
+ assert cs[1].kind == CursorKind.CONSTRUCTOR
+
+ assert cs[0].is_default_constructor()
+ assert not cs[1].is_default_constructor()
+
+def test_is_move_constructor():
+ """Ensure Cursor.is_move_constructor works."""
+ source = 'class X { X(); X(const X&); X(X&&); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+ assert xs[0].kind == CursorKind.CLASS_DECL
+ cs = xs[1:]
+ assert cs[0].kind == CursorKind.CONSTRUCTOR
+ assert cs[1].kind == CursorKind.CONSTRUCTOR
+ assert cs[2].kind == CursorKind.CONSTRUCTOR
+
+ assert not cs[0].is_move_constructor()
+ assert not cs[1].is_move_constructor()
+ assert cs[2].is_move_constructor()
+
+def test_is_default_method():
+ """Ensure Cursor.is_default_method works."""
+ source = 'class X { X() = default; }; class Y { Y(); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+ ys = get_cursors(tu, 'Y')
+
+ assert len(xs) == 2
+ assert len(ys) == 2
+
+ xc = xs[1]
+ yc = ys[1]
+
+ assert xc.is_default_method()
+ assert not yc.is_default_method()
+
def test_is_mutable_field():
"""Ensure Cursor.is_mutable_field works."""
source = 'class X { int x_; mutable int y_; };'
diff --git a/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_diagnostics.py b/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_diagnostics.py
index 48ab6176fd1..ba6e545e8b1 100644
--- a/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_diagnostics.py
+++ b/gnu/llvm/tools/clang/bindings/python/tests/cindex/test_diagnostics.py
@@ -80,3 +80,15 @@ def test_diagnostic_option():
assert d.option == '-Wunused-parameter'
assert d.disable_option == '-Wno-unused-parameter'
+
+def test_diagnostic_children():
+ tu = get_tu('void f(int x) {} void g() { f(); }')
+ assert len(tu.diagnostics) == 1
+ d = tu.diagnostics[0]
+
+ children = d.children
+ assert len(children) == 1
+ assert children[0].severity == Diagnostic.Note
+ assert children[0].spelling.endswith('declared here')
+ assert children[0].location.line == 1
+ assert children[0].location.column == 1