Rewrite the tests from using plain 'assert' mixed with some nosetests methods to the standard unittest module layout. Improve the code to use the most canonical assertion methods whenever possible. This has a few major advantages: - the code uses standard methods now, resulting in a reduced number of WTFs whenever someone with basic Python knowledge gets to read it, - completely unnecessary dependency on nosetests is removed since the standard library supplies all that is necessary for the tests to run, - the tests can be run via any test runner, including the one built-in in Python, - the failure output for most of the tests is improved from 'assertion x == y failed' to actually telling the values. Differential Revision: https://reviews.llvm.org/D39763 llvm-svn: 317897
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
|
|
from clang.cindex import AccessSpecifier
|
|
from clang.cindex import Cursor
|
|
from clang.cindex import TranslationUnit
|
|
|
|
from .util import get_cursor
|
|
from .util import get_tu
|
|
|
|
import unittest
|
|
|
|
|
|
class TestAccessSpecifiers(unittest.TestCase):
|
|
def test_access_specifiers(self):
|
|
"""Ensure that C++ access specifiers are available on cursors"""
|
|
|
|
tu = get_tu("""
|
|
class test_class {
|
|
public:
|
|
void public_member_function();
|
|
protected:
|
|
void protected_member_function();
|
|
private:
|
|
void private_member_function();
|
|
};
|
|
""", lang = 'cpp')
|
|
|
|
test_class = get_cursor(tu, "test_class")
|
|
self.assertEqual(test_class.access_specifier, AccessSpecifier.INVALID)
|
|
|
|
public = get_cursor(tu.cursor, "public_member_function")
|
|
self.assertEqual(public.access_specifier, AccessSpecifier.PUBLIC)
|
|
|
|
protected = get_cursor(tu.cursor, "protected_member_function")
|
|
self.assertEqual(protected.access_specifier, AccessSpecifier.PROTECTED)
|
|
|
|
private = get_cursor(tu.cursor, "private_member_function")
|
|
self.assertEqual(private.access_specifier, AccessSpecifier.PRIVATE)
|