Skip to content

Commit bb4e33e

Browse files
committed
Add proper tests for on-disk and in-memory files
1 parent f0bc427 commit bb4e33e

File tree

1 file changed

+39
-59
lines changed

1 file changed

+39
-59
lines changed

clang/bindings/python/tests/cindex/test_file.py

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,74 +19,54 @@ def test_file(self):
1919
self.assertEqual(repr(file), "<File: t.c>")
2020

2121
def test_file_eq(self):
22-
path = os.path.join(inputs_dir, "hello.cpp")
23-
header_path = os.path.join(inputs_dir, "header3.h")
22+
path = os.path.join(inputs_dir, "testfile.c")
23+
path_a = os.path.join(inputs_dir, "a.inc")
24+
path_b = os.path.join(inputs_dir, "b.inc")
2425
tu = TranslationUnit.from_source(path)
25-
file1 = File.from_name(tu, path)
26-
file2 = File.from_name(tu, header_path)
27-
file2_2 = File.from_name(tu, header_path)
28-
29-
self.assertEqual(file1, file1)
30-
self.assertEqual(file2, file2_2)
31-
self.assertNotEqual(file1, file2)
32-
self.assertNotEqual(file1, "t.c")
33-
34-
def test_file_eq_failing(self):
35-
index = Index.create()
36-
tu = index.parse(
37-
"t.c",
38-
unsaved_files=[
39-
("t.c", "int a = 729;"),
40-
("s.c", "int a = 729;"),
41-
],
42-
)
43-
file1 = File.from_name(tu, "t.c")
44-
file2 = File.from_name(tu, "s.c")
45-
# FIXME: These files are not supposed to be equal
46-
self.assertEqual(file1, file2)
26+
print(tu.spelling, tu.cursor.spelling)
27+
main_file = File.from_name(tu, path)
28+
a_file = File.from_name(tu, path_a)
29+
a_file2 = File.from_name(tu, path_a)
30+
b_file = File.from_name(tu, path_b)
4731

48-
def test_file_eq_failing_2(self):
49-
index = Index.create()
50-
tu = index.parse(
51-
"t.c",
52-
unsaved_files=[
53-
("t.c", "int a = 729;"),
54-
("s.c", "int a = 728;"),
55-
],
56-
)
57-
file1 = File.from_name(tu, "t.c")
58-
file2 = File.from_name(tu, "s.c")
59-
# FIXME: These files are not supposed to be equal
60-
self.assertEqual(file1, file2)
32+
self.assertEqual(a_file, a_file2)
33+
self.assertNotEqual(a_file, b_file)
34+
self.assertNotEqual(main_file, a_file)
35+
self.assertNotEqual(main_file, b_file)
36+
self.assertNotEqual(main_file, "t.c")
6137

62-
def test_file_eq_failing_3(self):
63-
index = Index.create()
64-
tu = index.parse(
65-
"t.c",
38+
def test_file_eq_in_memory(self):
39+
tu = TranslationUnit.from_source(
40+
"testfile.c",
6641
unsaved_files=[
67-
("t.c", '#include "a.c"\n#include "b.c";'),
68-
("a.c", "int a = 729;"),
69-
("b.c", "int b = 729;"),
42+
(
43+
"testfile.c",
44+
"""
45+
int a[] = {
46+
#include "a.inc"
47+
};
48+
int b[] = {
49+
#include "b.inc"
50+
};
51+
""",
52+
),
53+
("a.inc", "1,2,3"),
54+
("b.inc", "1,2,3"),
7055
],
7156
)
72-
file1 = File.from_name(tu, "t.c")
73-
file2 = File.from_name(tu, "a.c")
74-
file3 = File.from_name(tu, "b.c")
75-
# FIXME: These files are not supposed to be equal
76-
self.assertEqual(file2, file3)
77-
self.assertEqual(file1, file2)
78-
self.assertEqual(file1, file3)
7957

80-
def test_file_eq_failing_4(self):
8158
path = os.path.join(inputs_dir, "testfile.c")
8259
path_a = os.path.join(inputs_dir, "a.inc")
8360
path_b = os.path.join(inputs_dir, "b.inc")
8461
tu = TranslationUnit.from_source(path)
8562
print(tu.spelling, tu.cursor.spelling)
86-
file1 = File.from_name(tu, path)
87-
file2 = File.from_name(tu, path_a)
88-
file3 = File.from_name(tu, path_b)
89-
# FIXME: These files are not supposed to be equal
90-
self.assertEqual(file2, file3)
91-
self.assertEqual(file1, file2)
92-
self.assertEqual(file1, file3)
63+
main_file = File.from_name(tu, path)
64+
a_file = File.from_name(tu, path_a)
65+
a_file2 = File.from_name(tu, path_a)
66+
b_file = File.from_name(tu, path_b)
67+
68+
self.assertEqual(a_file, a_file2)
69+
self.assertNotEqual(a_file, b_file)
70+
self.assertNotEqual(main_file, a_file)
71+
self.assertNotEqual(main_file, b_file)
72+
self.assertNotEqual(main_file, "a.inc")

0 commit comments

Comments
 (0)