-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·67 lines (56 loc) · 2.87 KB
/
run_tests.py
File metadata and controls
executable file
·67 lines (56 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""
Test runner for BASIC programs in the test_suite directory.
Finds all .bas files, runs them with the BASIC interpreter,
and verifies they return the expected exit code.
"""
import sys
import os
import argparse
from test_runner_common import run_test_suite
def python_command_generator(program_path):
"""Generate command to run a BASIC program with the Python interpreter."""
return [sys.executable, "-m", "trekbasicpy.basic", program_path]
def main():
parser = argparse.ArgumentParser(description='Run BASIC interpreter tests.')
parser.add_argument('--include-dir', '-d', action='append', dest='additional_dirs',
help='Additional directory to search for .bas files (can be used multiple times)')
parser.add_argument('--only-dir', '-o',
help='Only run tests from this directory (skip test_suite)')
parser.add_argument('--test-suite-dir', '-t', type=str, default=None,
help='Directory containing BASIC test programs (default: directory containing this script)')
args = parser.parse_args()
# Determine test suite directory
if args.test_suite_dir is not None:
test_suite_dir = args.test_suite_dir
else:
test_suite_dir = os.path.dirname(os.path.abspath(__file__))
overall_success = True
if args.only_dir:
# Only run tests from the specified directory
if not os.path.exists(args.only_dir):
print(f"Error: Directory '{args.only_dir}' does not exist")
sys.exit(1)
success = run_test_suite(args.only_dir, f"Python Interpreter ({os.path.basename(args.only_dir)})", python_command_generator)
overall_success = success
else:
# Run the main test suite
if not os.path.exists(test_suite_dir):
print(f"Error: Test suite directory '{test_suite_dir}' does not exist. Use --test-suite-dir to specify a different directory.")
sys.exit(1)
success = run_test_suite(test_suite_dir, f"Python Interpreter ({os.path.basename(test_suite_dir)})", python_command_generator)
overall_success = success
# Run additional directories if specified
if args.additional_dirs:
for additional_dir in args.additional_dirs:
if not os.path.exists(additional_dir):
print(f"Warning: Directory '{additional_dir}' does not exist, skipping")
continue
print() # Add blank line between test suites
dir_name = os.path.basename(additional_dir)
success = run_test_suite(additional_dir, f"Python Interpreter ({dir_name})", python_command_generator)
overall_success = overall_success and success
# Exit with appropriate status
sys.exit(0 if overall_success else 1)
if __name__ == "__main__":
main()