-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use parameterized tests for standard library includes
- Loading branch information
Showing
5 changed files
with
80 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
clang==14 | ||
mypy | ||
parameterized | ||
pre-commit | ||
pytype |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters