1#!/usr/bin/env python3 2 3# Copyright 2019 Hans Dembinski, Henry Schreiner 4# 5# Distributed under the Boost Software License, Version 1.0. 6# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 7 8""" 9This test makes sure that all boost.histogram headers are included in the ODR test carried out in odr_main_test.cpp. See that file for details on why this test needed. 10""" 11 12import os 13import sys 14import re 15 16this_path = os.path.dirname(__file__) 17 18all_headers = set() 19# Includes are either in this_path/../include for the standalone version or ... 20include_path = os.path.join(this_path, "..", "include", "boost", "histogram") 21if not os.path.exists(include_path): 22 # ... in this_path/../../.. for the bundled boost release 23 include_path = os.path.join(this_path, "..", "..", "..", "boost", "histogram") 24 assert os.path.exists(include_path) 25 26# this has to be rindex, because any leading path could also be called boost 27root_include_path = include_path[: include_path.rindex("boost")] 28 29for root, dirs, files in os.walk(include_path): 30 for fn in files: 31 fn = os.path.join(root, fn) 32 fn = fn[len(root_include_path) :] 33 all_headers.add(fn) 34 35 36def get_headers(filename): 37 with open(filename) as f: 38 for hdr in re.findall('^#include [<"]([^>"]+)[>"]', f.read(), re.MULTILINE): 39 if not hdr.startswith("boost/histogram"): 40 continue 41 yield hdr.replace("/", os.path.sep) # adapt the paths for Windows 42 43 44included_headers = set() 45unread_headers = set() 46for hdr in get_headers(os.path.join(this_path, "odr_test.cpp")): 47 unread_headers.add(hdr) 48 49while unread_headers: 50 included_headers.update(unread_headers) 51 for hdr in tuple(unread_headers): # copy needed because unread_headers is modified 52 unread_headers.remove(hdr) 53 for hdr2 in get_headers(os.path.join(root_include_path, hdr)): 54 if hdr2 not in included_headers: 55 unread_headers.add(hdr2) 56 57diff = sorted(all_headers - set(included_headers)) 58 59if not diff: 60 sys.exit(0) 61 62 63print("Header not included in odr_test.cpp:") 64for fn in diff: 65 print(fn) 66 67sys.exit(1) 68