Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / histogram / test / check_odr_test.py
1 # Copyright 2019 Hans Dembinski, Henry Schreiner
2 #
3 # Distributed under the Boost Software License, Version 1.0.
4 # (See accompanying file LICENSE_1_0.txt
5 # or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 import os
8 import sys
9 import re
10
11 this_path = os.path.dirname(__file__)
12
13 all_headers = set()
14 include_path = os.path.join(this_path, "..", "include")
15 for root, dirs, files in os.walk(include_path):
16     for fn in files:
17         fn = os.path.join(root, fn)
18         assert fn.startswith(include_path)
19         fn = fn[len(include_path) + 1 :]
20         all_headers.add(fn)
21
22
23 def get_headers(filename):
24     with open(filename) as f:
25         for hdr in re.findall('^#include [<"]([^>"]+)[>"]', f.read(), re.MULTILINE):
26             if not hdr.startswith("boost/histogram"):
27                 continue
28             yield hdr.replace("/", os.path.sep)  # adapt the paths for Windows
29
30
31 included_headers = set()
32 unread_headers = set()
33 for hdr in get_headers(os.path.join(this_path, "odr_test.cpp")):
34     unread_headers.add(hdr)
35
36 while unread_headers:
37     included_headers.update(unread_headers)
38     for hdr in tuple(unread_headers):  # copy needed because unread_headers is modified
39         unread_headers.remove(hdr)
40         for hdr2 in get_headers(os.path.join(include_path, hdr)):
41             if hdr2 not in included_headers:
42                 unread_headers.add(hdr2)
43
44 diff = sorted(all_headers - set(included_headers))
45
46 if not diff:
47     sys.exit(0)
48
49
50 print("Header not included in odr_test.cpp:")
51 for fn in diff:
52     print(fn)
53
54 sys.exit(1)