2019-03-01 10:44:22 +00:00
|
|
|
import os
|
2019-07-30 09:21:11 +01:00
|
|
|
import platform
|
2019-04-11 18:22:50 +01:00
|
|
|
import unittest
|
2019-07-29 09:38:25 +01:00
|
|
|
from glob import glob
|
|
|
|
|
|
|
|
import pytest
|
2019-03-01 10:44:22 +00:00
|
|
|
|
2019-04-10 22:03:02 +01:00
|
|
|
import helpers
|
2019-07-29 09:38:25 +01:00
|
|
|
import pqclean
|
2019-03-01 10:44:22 +00:00
|
|
|
|
2019-04-06 12:57:35 +01:00
|
|
|
additional_flags = []
|
|
|
|
|
2019-03-01 10:44:22 +00:00
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'implementation',
|
|
|
|
pqclean.Scheme.all_implementations(),
|
|
|
|
ids=str,
|
|
|
|
)
|
2019-04-17 01:59:37 +01:00
|
|
|
@helpers.skip_windows()
|
2019-07-29 09:38:25 +01:00
|
|
|
@helpers.filtered_test
|
|
|
|
def test_clang_tidy(implementation: pqclean.Implementation):
|
2019-07-30 09:21:11 +01:00
|
|
|
if platform.machine() in ['i386']:
|
|
|
|
raise unittest.SkipTest("Clang-tidy has false-positives on i386")
|
2019-04-10 22:03:02 +01:00
|
|
|
helpers.ensure_available('clang-tidy')
|
2019-04-11 18:22:50 +01:00
|
|
|
cfiles = implementation.cfiles()
|
2019-03-01 10:44:22 +00:00
|
|
|
common_files = glob(os.path.join('..', 'common', '*.c'))
|
2019-04-11 18:22:50 +01:00
|
|
|
(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")
|
2019-07-29 09:38:25 +01:00
|
|
|
|
|
|
|
assert returncode == 0, "Clang-tidy returned %d" % returncode
|
2019-03-01 10:44:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-07-29 09:38:25 +01:00
|
|
|
import sys
|
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']
|
2019-07-29 09:38:25 +01:00
|
|
|
del sys.argv[1]
|
|
|
|
|
|
|
|
pytest.main(sys.argv)
|