Repository navigation
Expand file tree
/
Copy pathdoc_coverage.py
More file actions
executable file
·79 lines (69 loc) · 2.76 KB
/
Copy pathdoc_coverage.py
File metadata and controls
executable file
·79 lines (69 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os, sys, re
def check_doc_coverage(verbose=False):
total = 0
documented = 0
pattern_struct = re.compile(
r"^\s*(?:struct|class)\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*[{:]", re.MULTILINE
)
for root, _, files in os.walk("src"):
for file in files:
if not file.endswith(".hpp") or "tests" in root:
continue
with open(os.path.join(root, file), "r") as f:
content = f.read()
lines = content.split("\n")
for i, line in enumerate(lines):
stripped = line.strip()
if not stripped:
continue
if (
stripped.startswith("//")
or stripped.startswith("/*")
or stripped.startswith("*")
or stripped.startswith("#")
or stripped.startswith("}")
):
continue
is_decl = False
if (
"struct " in stripped or "class " in stripped
) and "{" in stripped:
is_decl = True
elif re.match(
r"^(?:template\s*<[^>]+>\s*)?(?:virtual\s+)?(?:(?:inline|static|explicit)\s+)?(?:[a-zA-Z_:-<>]+\s+)+[a-zA-Z_~:]+\s*\([^;{]*\)\s*(?:const)?\s*(?:noexcept)?\s*(?:=\s*0|=\s*default|=\s*delete)?\s*(?:;|{)",
stripped,
):
if (
" main(" in stripped
or "return " in stripped
or "if (" in stripped
or "else " in stripped
or "for (" in stripped
or "while (" in stripped
or "switch (" in stripped
):
continue
is_decl = True
if is_decl:
total += 1
if i > 0 and (
"///" in lines[i - 1]
or "*/" in lines[i - 1]
or "//" in lines[i - 1]
):
documented += 1
else:
if verbose:
print(f"UNDOC: {root}/{file}:{i + 1}: {stripped}")
if total == 0:
total = 1
if verbose:
print(f"Total: {total}, Documented: {documented}")
cov = documented / total * 100
print(f"{cov:.2f}")
return cov
if __name__ == "__main__":
import sys
cov = check_doc_coverage(False)
if cov < 100.0:
sys.exit(1)