Run similarity-csharp and return (report path, group count, total lines).
(output_dir: Path, threshold: float)
| 157 | |
| 158 | |
| 159 | def run_similarity(output_dir: Path, threshold: float) -> tuple[Path, int, int]: |
| 160 | """Run similarity-csharp and return (report path, group count, total lines).""" |
| 161 | report_path = output_dir / "similarity.txt" |
| 162 | assets_dir = TEST_PROJECT / "Assets" |
| 163 | |
| 164 | cmd = [ |
| 165 | "similarity-csharp", |
| 166 | "-p", |
| 167 | str(assets_dir), |
| 168 | "--min-lines", |
| 169 | "5", |
| 170 | "--threshold", |
| 171 | str(threshold), |
| 172 | "-o", |
| 173 | str(report_path), |
| 174 | ] |
| 175 | print(f"Running: {' '.join(cmd)}") |
| 176 | result = subprocess.run(cmd, capture_output=True, text=True) |
| 177 | if result.returncode != 0: |
| 178 | print(f"similarity-csharp failed (exit {result.returncode}):") |
| 179 | if result.stderr: |
| 180 | print(result.stderr) |
| 181 | return report_path, 0, 0 |
| 182 | |
| 183 | if not report_path.exists(): |
| 184 | print("similarity-csharp produced no output") |
| 185 | return report_path, 0, 0 |
| 186 | |
| 187 | groups, total_lines = parse_similarity_report(report_path) |
| 188 | return report_path, groups, total_lines |
| 189 | |
| 190 | |
| 191 | def parse_similarity_report(report_path: Path) -> tuple[int, int]: |
no test coverage detected