Skip to content

Commit 3d150db

Browse files
committed
add python script to count and later rename tests
1 parent 9ac6069 commit 3d150db

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed

account_tests.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import pprint
2+
from typing import Dict
3+
from pathlib import Path
4+
from dataclasses import dataclass, field
5+
6+
TARGETS_MAPPING: Dict[str, str] = {
7+
"apple-clang-14-c++2b" : "TBD01",
8+
"apple-clang-15-c++2b" : "TBD02",
9+
"clang-12-c++20" : "TBD03",
10+
"clang-15-c++20" : "TBD04",
11+
"clang-15-c++20-libcpp": "TBD05",
12+
"clang-18-c++20" : "TBD06",
13+
"clang-18-c++23-libcpp": "TBD07",
14+
"gcc-10-c++20" : "TBD08",
15+
"gcc-13-c++2b" : "TBD09",
16+
"gcc-14-c++2b" : "TBD10",
17+
"msvc-2022-c++20" : "TBD11",
18+
"msvc-2022-c++latest" : "TBD12",
19+
}
20+
21+
@dataclass
22+
class TestProp:
23+
has_lowered_output: bool
24+
has_cppfront_output: bool
25+
targets_with_cpp_exec: Dict[str, int] = field(default_factory=dict)
26+
targets_with_cpp_output: Dict[str, int] = field(default_factory=dict)
27+
28+
def main():
29+
if not Path("README.md").is_file():
30+
print("CWD should be root of the cppfront repo")
31+
exit()
32+
33+
p = Path(".")
34+
trp = p / "regression-tests" / "test-results"
35+
36+
files_accounted_for = []
37+
def try_account_for(pp):
38+
if pp.is_file():
39+
files_accounted_for.append(pp)
40+
return True
41+
return False
42+
43+
# Account for cppfront version
44+
afcftp = try_account_for(trp / "version")
45+
assert afcftp
46+
47+
# Account for target compiler versions
48+
for target in TARGETS_MAPPING.keys():
49+
compiler_prefix = "clang"
50+
if "gcc" in target:
51+
compiler_prefix = "gcc"
52+
if "msvc" in target:
53+
compiler_prefix = "MSVC"
54+
afcvp = try_account_for(trp / target / (compiler_prefix + "-version.output"))
55+
assert afcvp
56+
57+
# Account for extraneous files (disable once fixed)
58+
if True:
59+
for efs in (
60+
"regression-tests/test-results/clang-18-c++20/pure2-bugfix-for-ufcs-arguments.cpp copy.execution",
61+
"regression-tests/test-results/clang-18-c++23-libcpp/pure2-bugfix-for-ufcs-arguments.cpp copy.execution",
62+
"regression-tests/test-results/apple-clang-14-c++2b/pure2-regex_13_posessive_modifier.cpp.execution",
63+
"regression-tests/test-results/apple-clang-15-c++2b/pure2-regex_13_posessive_modifier.cpp.execution",
64+
"regression-tests/test-results/clang-15-c++20-libcpp/pure2-regex_13_posessive_modifier.cpp.execution",
65+
"regression-tests/test-results/clang-15-c++20/pure2-regex_13_posessive_modifier.cpp.execution",
66+
"regression-tests/test-results/clang-18-c++20/pure2-regex_13_posessive_modifier.cpp.execution",
67+
"regression-tests/test-results/clang-18-c++23-libcpp/pure2-regex_13_posessive_modifier.cpp.execution",
68+
"regression-tests/test-results/gcc-13-c++2b/pure2-regex_13_posessive_modifier.cpp.execution",
69+
"regression-tests/test-results/msvc-2022-c++20/pure2-regex_13_posessive_modifier.cpp.execution",
70+
"regression-tests/test-results/msvc-2022-c++20/pure2-regex_13_posessive_modifier.cpp.output",
71+
):
72+
afefp = try_account_for(Path(efs))
73+
assert afefp
74+
75+
removable_msvc_files_count = 0
76+
tests: Dict[str, TestProp] = {}
77+
for tp in p.glob("regression-tests/*.cpp2"):
78+
aftp = try_account_for(tp)
79+
assert aftp
80+
81+
name = tp.name[:-5]
82+
cppfront_lowered_output = trp / (name + ".cpp")
83+
cppfront_output = trp / (name + ".cpp2.output")
84+
85+
assert name not in tests
86+
t = tests[name] = TestProp(
87+
has_lowered_output=try_account_for(cppfront_lowered_output),
88+
has_cppfront_output=try_account_for(cppfront_output),
89+
)
90+
91+
for target in TARGETS_MAPPING.keys():
92+
cep = trp / target / (name + ".cpp.execution")
93+
if try_account_for(cep):
94+
t.targets_with_cpp_exec[target] = hash(open(cep).read())
95+
cop = trp / target / (name + ".cpp.output")
96+
if try_account_for(cop):
97+
# t.targets_with_cpp_output[target] = hash(open(cop).read())
98+
fcontent = open(cop).read()
99+
if fcontent.strip() != (name + ".cpp"):
100+
t.targets_with_cpp_output[target] = hash(fcontent)
101+
else:
102+
removable_msvc_files_count += 1
103+
104+
files_accounted_for_set = set([f for f in files_accounted_for])
105+
assert len(files_accounted_for_set) == len(files_accounted_for)
106+
107+
all_files = set(fp for fp in p.glob("regression-tests/**/*") if not fp.is_dir())
108+
109+
redundant_file_count = len(all_files) - len(files_accounted_for)
110+
111+
print(f"MSVC redundant removable files: {removable_msvc_files_count}\n")
112+
redundant_file_count += removable_msvc_files_count
113+
114+
print(f"Files unnacounted for ({redundant_file_count}):")
115+
for f in sorted(all_files - files_accounted_for_set):
116+
print(f"\t{f}")
117+
print()
118+
119+
print("All tests and their redundancy count:")
120+
for k,v in sorted(tests.items()):
121+
rk1 = _count_redundant_keys(v.targets_with_cpp_exec)
122+
rk2 = _count_redundant_keys(v.targets_with_cpp_output)
123+
redundant_file_count += rk1 + rk2
124+
125+
print(k)
126+
pprint.pp(v)
127+
print(f"-> {rk1}, {rk2}")
128+
print()
129+
print(f"Total redundant files = {redundant_file_count}")
130+
print()
131+
132+
tests_with_compiler_output = 0
133+
print("Tests with compiler output:")
134+
for k,v in sorted(tests.items()):
135+
if len(v.targets_with_cpp_output) == 0:
136+
continue
137+
tests_with_compiler_output += 1
138+
139+
print(k)
140+
pprint.pp(v)
141+
print()
142+
print(f"Total = {tests_with_compiler_output}")
143+
print()
144+
145+
def _count_redundant_keys(d):
146+
counts = {}
147+
for k,v in d.items():
148+
counts[v] = counts.get(v,0)+1
149+
total = 0
150+
for v in counts.values():
151+
total += v - 1
152+
return total
153+
154+
if __name__ == "__main__":
155+
main()

0 commit comments

Comments
 (0)