-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_parse_standard_library_includes.py
72 lines (60 loc) · 1.72 KB
/
test_parse_standard_library_includes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import clang
import os
import py_cppmodel
import unittest
from parameterized import parameterized
from ctypes.util import find_library
LIBCLANG_PATH = os.environ.get("PY_CPPMODEL_LIBCLANG_PATH")
if not LIBCLANG_PATH:
raise RuntimeError("PY_CPPMODEL_LIBCLANG_PATH is unset")
clang.cindex.Config.set_library_file(LIBCLANG_PATH) # type: ignore
from clang.cindex import TranslationUnit
COMPILER_ARGS = [
"-x",
"c++",
"-std=c++20",
"-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
"-I/Library/Developer/CommandLineTools/usr/include",
]
def _custom_name_func(testcase_func, _, param):
return "%s_%s" % (testcase_func.__name__, parameterized.to_safe_name(param.args[0]))
class TestStandardLibraryIncludes(unittest.TestCase):
@parameterized.expand(
[
"algorithm",
"any",
"array",
"deque",
"forward_list",
"functional",
"iterator",
"list",
"map",
"memory",
"numeric",
"optional",
"queue",
"set",
"stack",
"string",
"tuple",
"type_traits",
"unordered_map",
"unordered_set",
"utility",
"variant",
"vector",
],
name_func=_custom_name_func,
)
def test_include(self, include):
source = f"#include <{include}>"
tu = TranslationUnit.from_source(
"t.cc",
COMPILER_ARGS,
unsaved_files=[("t.cc", source)],
)
# This should not raise an exception.
self.model = py_cppmodel.Model(tu)
if __name__ == "__main__":
unittest.main()