|
| 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 | + tests: Dict[str, TestProp] = {} |
| 76 | + for tp in p.glob("regression-tests/*.cpp2"): |
| 77 | + aftp = try_account_for(tp) |
| 78 | + assert aftp |
| 79 | + |
| 80 | + name = tp.name[:-5] |
| 81 | + cppfront_lowered_output = trp / (name + ".cpp") |
| 82 | + cppfront_output = trp / (name + ".cpp2.output") |
| 83 | + |
| 84 | + assert name not in tests |
| 85 | + t = tests[name] = TestProp( |
| 86 | + has_lowered_output=try_account_for(cppfront_lowered_output), |
| 87 | + has_cppfront_output=try_account_for(cppfront_output), |
| 88 | + ) |
| 89 | + |
| 90 | + for target in TARGETS_MAPPING.keys(): |
| 91 | + cep = trp / target / (name + ".cpp.execution") |
| 92 | + if try_account_for(cep): |
| 93 | + t.targets_with_cpp_exec[target] = hash(open(cep).read()) |
| 94 | + cop = trp / target / (name + ".cpp.output") |
| 95 | + if try_account_for(cop): |
| 96 | + t.targets_with_cpp_output[target] = hash(open(cop).read()) |
| 97 | + |
| 98 | + files_accounted_for_set = set([f for f in files_accounted_for]) |
| 99 | + assert len(files_accounted_for_set) == len(files_accounted_for) |
| 100 | + |
| 101 | + all_files = set(fp for fp in p.glob("regression-tests/**/*") if not fp.is_dir()) |
| 102 | + |
| 103 | + redundant_file_count = len(all_files) - len(files_accounted_for) |
| 104 | + |
| 105 | + print(f"Files unnacounted for ({redundant_file_count}):") |
| 106 | + for f in sorted(all_files - files_accounted_for_set): |
| 107 | + print(f"\t{f}") |
| 108 | + print() |
| 109 | + |
| 110 | + for k,v in sorted(tests.items()): |
| 111 | + rk1 = _count_redundant_keys(v.targets_with_cpp_exec) |
| 112 | + rk2 = _count_redundant_keys(v.targets_with_cpp_output) |
| 113 | + redundant_file_count += rk1 + rk2 |
| 114 | + |
| 115 | + print(k) |
| 116 | + pprint.pp(v) |
| 117 | + print(f"-> {rk1}, {rk2}") |
| 118 | + print() |
| 119 | + |
| 120 | + print(f"Total redundant files: {redundant_file_count}") |
| 121 | + |
| 122 | +def _count_redundant_keys(d): |
| 123 | + counts = {} |
| 124 | + for k,v in d.items(): |
| 125 | + counts[v] = counts.get(v,0)+1 |
| 126 | + total = 0 |
| 127 | + for v in counts.values(): |
| 128 | + total += v - 1 |
| 129 | + return total |
| 130 | + |
| 131 | +if __name__ == "__main__": |
| 132 | + main() |
0 commit comments