From c4c135e678e27590eab5505bd61b917d3f60805d Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 17 Dec 2024 16:49:46 -0800 Subject: [PATCH] refactor: Use dict for test commands based on file extensions --- benchmark/benchmark.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index c36ebc0c2..363921dde 100755 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -789,9 +789,27 @@ def run_test_real( def run_unit_tests(testdir, history_fname, test_files): timeout = 60 - # Choose test command based on test file extensions - is_rust = any(Path(f).suffix == ".rs" for f in test_files) - command = "cargo test -- --include-ignored".split() if is_rust else ["pytest"] + # Map of file extensions to test commands + TEST_COMMANDS = { + '.py': ['pytest'], + '.rs': ['cargo', 'test', '--', '--include-ignored'], + '.cs': ['dotnet', 'test'], + '.go': ['go', 'test', './...'], + '.js': ['npm', 'test'], + } + + # Get unique file extensions from test files + extensions = {Path(f).suffix for f in test_files} + + # Find matching test command + command = None + for ext in extensions: + if ext in TEST_COMMANDS: + command = TEST_COMMANDS[ext] + break + + if not command: + raise ValueError(f"No test command found for files with extensions: {extensions}") print(" ".join(command)) result = subprocess.run(