test_cpp.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import json
  2. import os
  3. import subprocess
  4. import pytest
  5. import yaml
  6. import yatest
  7. from library.python.testing.style import rules
  8. import library.python.resource as lpr
  9. STYLE_CONFIG_JSON = json.dumps(yaml.safe_load(lpr.find('resfs/file/config.clang-format')))
  10. RES_FILE_PREFIX = '/cpp_style/files/'
  11. CHECKED_PATHS = list(lpr.iterkeys(RES_FILE_PREFIX, strip_prefix=True))
  12. def check_style(filename, actual_source):
  13. clang_format_binary = yatest.common.binary_path('contrib/libs/clang14/tools/clang-format/clang-format')
  14. config = STYLE_CONFIG_JSON
  15. command = [clang_format_binary, '-assume-filename=' + filename, '-style=' + config]
  16. styled_source = subprocess.check_output(command, input=actual_source)
  17. assert actual_source.decode() == styled_source.decode()
  18. @pytest.mark.parametrize('path', CHECKED_PATHS)
  19. def test_cpp_style(path):
  20. data = lpr.find(RES_FILE_PREFIX + path)
  21. skip_reason = rules.get_skip_reason(path, data, skip_links=False)
  22. if skip_reason:
  23. raise pytest.skip("style check is omitted: {}".format(skip_reason))
  24. else:
  25. check_style(os.path.basename(path), data)