1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-22 15:39:07 +00:00

Test for preprocessor conditionals

This commit is contained in:
Joost Rijneveld 2019-04-09 16:45:41 +02:00
parent 8d1ed9afc0
commit 5853cb8e50
No known key found for this signature in database
GPG Key ID: A4FE39CF49CBC553

37
test/test_preprocessor.py Normal file
View File

@ -0,0 +1,37 @@
import os
from glob import glob
import pqclean
from helpers import run_subprocess, ensure_available
def test_preprocessor():
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
yield check_preprocessor, implementation
def check_preprocessor(implementation: pqclean.Implementation):
cfiles = implementation.cfiles()
hfiles = implementation.hfiles()
errors = []
for file in hfiles + cfiles:
with open(file) as f:
for i, line in enumerate(f):
line = line.strip()
if file in hfiles and i == 0 and line.startswith('#ifndef'):
continue
if line.startswith('#if'):
errors.append("\n at {}:{}".format(file, i+1))
if errors:
raise AssertionError(
"Prohibited use of preprocessor conditional" + "".join(errors)
)
if __name__ == "__main__":
try:
import nose2
nose2.main()
except ImportError:
import nose
nose.runmodule()