From 5853cb8e502359c3a9cc00b84e316c663b46577b Mon Sep 17 00:00:00 2001 From: Joost Rijneveld Date: Tue, 9 Apr 2019 16:45:41 +0200 Subject: [PATCH] Test for preprocessor conditionals --- test/test_preprocessor.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/test_preprocessor.py diff --git a/test/test_preprocessor.py b/test/test_preprocessor.py new file mode 100644 index 00000000..64e0b1f4 --- /dev/null +++ b/test/test_preprocessor.py @@ -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()