Index: bindings/python/tests/cindex/INPUTS/windows/compile_commands.json =================================================================== --- /dev/null +++ bindings/python/tests/cindex/INPUTS/windows/compile_commands.json @@ -0,0 +1,17 @@ +[ +{ + "directory": "C:/home/john.doe/MyProject", + "command": "clang++ -o project.o -c C:\\home\\john.doe\\MyProject\\project.cpp", + "file": "C:\\home\\john.doe\\MyProject\\project.cpp" +}, +{ + "directory": "C:/home/john.doe/MyProjectA", + "command": "clang++ -o project2.o -c C:\\home\\john.doe\\MyProject\\project2.cpp", + "file": "C:\\home\\john.doe\\MyProject\\project2.cpp" +}, +{ + "directory": "C:/home/john.doe/MyProjectB", + "command": "clang++ -DFEATURE=1 -o project2-feature.o -c C:\\home\\john.doe\\MyProject\\project2.cpp", + "file": "C:\\home\\john.doe\\MyProject\\project2.cpp" +} +] Index: bindings/python/tests/cindex/test_cdb.py =================================================================== --- bindings/python/tests/cindex/test_cdb.py +++ bindings/python/tests/cindex/test_cdb.py @@ -5,7 +5,20 @@ import os import gc -kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS') +if os.name == 'nt': + kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS', 'windows') + kProjectFile = 'C:\\home\\john.doe\\MyProject\\project.cpp' + kProject2File = 'C:\\home\\john.doe\\MyProject\\project2.cpp' + kProjectDir = 'C:/home/john.doe/MyProject' + kProjectADir = 'C:/home/john.doe/MyProjectA' + kProjectBDir = 'C:/home/john.doe/MyProjectB' +else: + kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS') + kProjectFile = '/home/john.doe/MyProject/project.cpp' + kProject2File = '/home/john.doe/MyProject/project2.cpp' + kProjectDir = '/home/john.doe/MyProject' + kProjectADir = '/home/john.doe/MyProjectA' + kProjectBDir = '/home/john.doe/MyProjectB' def test_create_fail(): """Check we fail loading a database with an assertion""" @@ -29,7 +42,7 @@ def test_lookup_succeed(): """Check we get some results if the file exists in the db""" cdb = CompilationDatabase.fromDirectory(kInputsDir) - cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp') + cmds = cdb.getCompileCommands(kProjectFile) assert len(cmds) != 0 def test_all_compilecommand(): @@ -38,18 +51,18 @@ cmds = cdb.getAllCompileCommands() assert len(cmds) == 3 expected = [ - { 'wd': '/home/john.doe/MyProject', - 'file': '/home/john.doe/MyProject/project.cpp', + { 'wd': kProjectDir, + 'file': kProjectFile, 'line': ['clang++', '-o', 'project.o', '-c', - '/home/john.doe/MyProject/project.cpp']}, - { 'wd': '/home/john.doe/MyProjectA', - 'file': '/home/john.doe/MyProject/project2.cpp', + kProjectFile]}, + { 'wd': kProjectADir, + 'file': kProject2File, 'line': ['clang++', '-o', 'project2.o', '-c', - '/home/john.doe/MyProject/project2.cpp']}, - { 'wd': '/home/john.doe/MyProjectB', - 'file': '/home/john.doe/MyProject/project2.cpp', + kProject2File]}, + { 'wd': kProjectBDir, + 'file': kProject2File, 'line': ['clang++', '-DFEATURE=1', '-o', 'project2-feature.o', '-c', - '/home/john.doe/MyProject/project2.cpp']}, + kProject2File]}, ] for i in range(len(cmds)): @@ -61,28 +74,28 @@ def test_1_compilecommand(): """Check file with single compile command""" cdb = CompilationDatabase.fromDirectory(kInputsDir) - file = '/home/john.doe/MyProject/project.cpp' + file = kProjectFile cmds = cdb.getCompileCommands(file) assert len(cmds) == 1 - assert cmds[0].directory == os.path.dirname(file) + assert os.path.normpath(cmds[0].directory) == os.path.dirname(file) assert cmds[0].filename == file expected = [ 'clang++', '-o', 'project.o', '-c', - '/home/john.doe/MyProject/project.cpp'] + kProjectFile] for arg, exp in zip(cmds[0].arguments, expected): assert arg == exp def test_2_compilecommand(): """Check file with 2 compile commands""" cdb = CompilationDatabase.fromDirectory(kInputsDir) - cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project2.cpp') + cmds = cdb.getCompileCommands(kProject2File) assert len(cmds) == 2 expected = [ - { 'wd': '/home/john.doe/MyProjectA', + { 'wd': kProjectADir, 'line': ['clang++', '-o', 'project2.o', '-c', - '/home/john.doe/MyProject/project2.cpp']}, - { 'wd': '/home/john.doe/MyProjectB', + kProject2File]}, + { 'wd': kProjectBDir, 'line': ['clang++', '-DFEATURE=1', '-o', 'project2-feature.o', '-c', - '/home/john.doe/MyProject/project2.cpp']} + kProject2File]} ] for i in range(len(cmds)): assert cmds[i].directory == expected[i]['wd'] @@ -93,14 +106,14 @@ """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'): + for cmd in cdb.getCompileCommands(kProject2File): count += 1 assert count <= 2 def test_compilationDB_references(): """Ensure CompilationsCommands are independent of the database""" cdb = CompilationDatabase.fromDirectory(kInputsDir) - cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp') + cmds = cdb.getCompileCommands(kProject2File) del cdb gc.collect() workingdir = cmds[0].directory @@ -108,7 +121,7 @@ def test_compilationCommands_references(): """Ensure CompilationsCommand keeps a reference to CompilationCommands""" cdb = CompilationDatabase.fromDirectory(kInputsDir) - cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp') + cmds = cdb.getCompileCommands(kProjectFile) del cdb cmd0 = cmds[0] del cmds Index: bindings/python/tests/cindex/test_cursor.py =================================================================== --- bindings/python/tests/cindex/test_cursor.py +++ bindings/python/tests/cindex/test_cursor.py @@ -295,7 +295,7 @@ assert enum.kind == CursorKind.ENUM_DECL enum_type = enum.enum_type - assert enum_type.kind == TypeKind.UINT + assert enum_type.kind in (TypeKind.UINT, TypeKind.INT) def test_enum_type_cpp(): tu = get_tu('enum TEST : long long { FOO=1, BAR=2 };', lang="cpp") @@ -451,4 +451,4 @@ # all valid manglings. # [c-index-test handles this by running the source through clang, emitting # an AST file and running libclang on that AST file] - assert foo.mangled_name in ('_Z3fooii', '__Z3fooii', '?foo@@YAHHH') + assert foo.mangled_name in ('_Z3fooii', '__Z3fooii', '?foo@@YAHHH@Z') 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 @@ -94,7 +94,9 @@ Returns the filename it was saved to. """ - _, path = tempfile.mkstemp() + fd, path = tempfile.mkstemp() + # On Windows, if a file is open it cannot be replaced or deleted. + os.close(fd) tu.save(path) return path @@ -142,6 +144,7 @@ # Just in case there is an open file descriptor somewhere. del tu2 + del foo os.unlink(path)