Files
clang-p2996/clang/test/bindings/python/tests/cindex/test_comment.py
Rainer Orth 90c9cc2c98 [clang][python][test] Move python binding tests to lit framework (#145855)
As discussed in PR #142353, the current testsuite of the `clang` Python
bindings has several issues:

- If `libclang.so` cannot be loaded into `python` to run the testsuite,
the whole `ninja check-all` aborts.
- The result of running the testsuite isn't report like the `lit`-based
tests, rendering them almost invisible.
- The testsuite is disabled in a non-obvious way (`RUN_PYTHON_TESTS`) in
`tests/CMakeLists.txt`, which again doesn't show up in the test results.

All these issues can be avoided by integrating the Python bindings tests
with `lit`, which is what this patch does:

- The actual test lives in `clang/test/bindings/python/bindings.sh` and
is run by `lit`.
- The current `clang/bindings/python/tests` directory (minus the
now-superfluous `CMakeLists.txt`) is moved into the same directory.
- The check if `libclang` is loadable (originally from PR #142353) is
now handled via a new `lit` feature, `libclang-loadable`.
- The various ways to disable the tests have been turned into `XFAIL`s
as appropriate.
- AArch64 doesn't `FAIL` any longer, so no `XFAIL` is necessary.
- It keeps the `check-clang-python` target for use by the Clang Python
CI.

Tested on `sparc-sun-solaris2.11`, `sparcv9-sun-solaris2.11`,
`i386-pc-solaris2.11`, `amd64-pc-solaris2.11`, `i686-pc-linux-gnu`, and
`x86_64-pc-linux-gnu`.
2025-06-26 16:34:10 +02:00

58 lines
1.3 KiB
Python

import os
from clang.cindex import Config, TranslationUnit
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
import unittest
from .util import get_cursor
class TestComment(unittest.TestCase):
def test_comment(self):
files = [
(
"fake.c",
"""
/// Aaa.
int test1;
/// Bbb.
/// x
void test2(void);
void f() {
}
""",
)
]
# make a comment-aware TU
tu = TranslationUnit.from_source(
"fake.c",
["-std=c99"],
unsaved_files=files,
options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION,
)
test1 = get_cursor(tu, "test1")
self.assertIsNotNone(test1, "Could not find test1.")
self.assertTrue(test1.type.is_pod())
raw = test1.raw_comment
brief = test1.brief_comment
self.assertEqual(raw, """/// Aaa.""")
self.assertEqual(brief, """Aaa.""")
test2 = get_cursor(tu, "test2")
raw = test2.raw_comment
brief = test2.brief_comment
self.assertEqual(raw, """/// Bbb.\n/// x""")
self.assertEqual(brief, """Bbb. x""")
f = get_cursor(tu, "f")
raw = f.raw_comment
brief = f.brief_comment
self.assertEqual(raw, "")
self.assertEqual(brief, "")