1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-27 01:41:40 +00:00
pqcrypto/test/test_linter.py

55 lines
1.4 KiB
Python
Raw Normal View History

import os
from glob import glob
2019-04-06 12:57:35 +01:00
import sys
import unittest
import pqclean
import helpers
2019-04-06 12:57:35 +01:00
additional_flags = []
def test_clang_tidy():
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
yield check_tidy, implementation
@helpers.filtered_test
2019-04-17 01:59:37 +01:00
@helpers.skip_windows()
def check_tidy(implementation: pqclean.Implementation):
helpers.ensure_available('clang-tidy')
cfiles = implementation.cfiles()
common_files = glob(os.path.join('..', 'common', '*.c'))
(returncode, _) = helpers.run_subprocess(
['clang-tidy',
'-quiet',
'-header-filter=.*',
*additional_flags,
*cfiles,
*common_files,
'--',
'-iquote', os.path.join('..', 'common'),
'-iquote', implementation.path()],
expected_returncode=None,
)
# Detect and gracefully avoid segfaults
if returncode == -11:
raise unittest.SkipTest("clang-tidy segfaulted")
else:
assert returncode == 0, "Clang-tidy returned %d" % returncode
if __name__ == "__main__":
2019-04-06 12:57:35 +01:00
# allow a user to specify --fix-errors, to immediately fix errors
if len(sys.argv) >= 2 and sys.argv[1] == '-fix-errors':
additional_flags = ['-fix-errors']
sys.argv = sys.argv[0:1] + sys.argv[2:]
try:
import nose2
nose2.main()
except ImportError:
import nose
nose.runmodule()