(original_dname, testdir, history_fname, test_files)
| 979 | |
| 980 | |
| 981 | def run_unit_tests(original_dname, testdir, history_fname, test_files): |
| 982 | timeout = 60 * 3 |
| 983 | |
| 984 | # Map of file extensions to test commands |
| 985 | TEST_COMMANDS = { |
| 986 | ".py": ["pytest"], |
| 987 | ".rs": ["cargo", "test", "--", "--include-ignored"], |
| 988 | ".go": ["go", "test", "./..."], |
| 989 | ".js": ["/aider/benchmark/npm-test.sh"], |
| 990 | ".cpp": ["/aider/benchmark/cpp-test.sh"], |
| 991 | ".java": ["./gradlew", "test"], |
| 992 | } |
| 993 | |
| 994 | # Get unique file extensions from test files |
| 995 | extensions = {Path(f).suffix for f in test_files} |
| 996 | |
| 997 | # Find matching test command |
| 998 | command = None |
| 999 | for ext in extensions: |
| 1000 | if ext in TEST_COMMANDS: |
| 1001 | command = TEST_COMMANDS[ext] |
| 1002 | break |
| 1003 | |
| 1004 | if not command: |
| 1005 | raise ValueError(f"No test command found for files with extensions: {extensions}") |
| 1006 | |
| 1007 | # Copy test files from original directory |
| 1008 | for file_path in test_files: |
| 1009 | src = original_dname / Path(*testdir.parts[-4:]) / file_path |
| 1010 | dst = testdir / file_path |
| 1011 | if src.exists(): |
| 1012 | print("copying", src, dst) |
| 1013 | os.makedirs(dst.parent, exist_ok=True) |
| 1014 | shutil.copy(src, dst) |
| 1015 | |
| 1016 | # Remove @Disabled annotations from Java test files |
| 1017 | for file_path in test_files: |
| 1018 | if file_path.endswith(".java"): |
| 1019 | test_file = testdir / file_path |
| 1020 | if test_file.exists(): |
| 1021 | content = test_file.read_text() |
| 1022 | content = re.sub(r"@Disabled\([^)]*\)\s*\n", "", content) |
| 1023 | test_file.write_text(content) |
| 1024 | |
| 1025 | print(" ".join(command)) |
| 1026 | |
| 1027 | result = subprocess.run( |
| 1028 | command, |
| 1029 | stdout=subprocess.PIPE, |
| 1030 | stderr=subprocess.STDOUT, |
| 1031 | text=True, |
| 1032 | timeout=timeout, |
| 1033 | cwd=testdir, |
| 1034 | encoding="utf-8", |
| 1035 | errors="replace", |
| 1036 | ) |
| 1037 | |
| 1038 | success = result.returncode == 0 |
no test coverage detected