-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_cli_complete.py
More file actions
219 lines (179 loc) · 6.84 KB
/
test_cli_complete.py
File metadata and controls
219 lines (179 loc) · 6.84 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/env python3
"""Complete CLI test for all command options."""
import subprocess
import tempfile
from pathlib import Path
# Test errors
TEST_ERRORS = {
'python': '''Traceback (most recent call last):
File "app.py", line 42, in process_data
result = data.get_value()
AttributeError: 'NoneType' object has no attribute 'get_value'
''',
'javascript': '''TypeError: Cannot read property 'name' of undefined
at UserProfile (UserProfile.js:15:23)
at renderWithHooks (react-dom.development.js:14985:18)
''',
'typescript': '''error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
src/calculator.ts:25:15
''',
}
def run_command(cmd, input_data=None):
"""Run command and return result."""
result = subprocess.run(
cmd,
input=input_data,
capture_output=True,
text=True,
shell=False
)
return result
def test_basic_commands():
"""Test basic command functionality."""
print("=" * 60)
print("Testing Basic Commands")
print("=" * 60)
tests = [
# Help
("Help", ["python3", "-m", "claudecode_debugger.cli_new", "--help"]),
# List templates
("List Templates", ["python3", "-m", "claudecode_debugger.cli_new", "--list-templates"]),
# Basic error - English
("Basic Error (EN)", ["python3", "-m", "claudecode_debugger.cli_new", TEST_ERRORS['python'], "--lang", "en"]),
# Basic error - Chinese
("Basic Error (ZH)", ["python3", "-m", "claudecode_debugger.cli_new", TEST_ERRORS['python'], "--lang", "zh"]),
]
for name, cmd in tests:
print(f"\n[{name}]")
result = run_command(cmd)
print(f"Exit code: {result.returncode}")
if result.returncode != 0:
print(f"Error: {result.stderr[:200]}")
else:
print("✅ Success")
def test_analysis_features():
"""Test advanced analysis features."""
print("\n" + "=" * 60)
print("Testing Analysis Features")
print("=" * 60)
tests = [
# Stack trace analysis
("Stack Analysis", ["python3", "-m", "claudecode_debugger.cli_new",
TEST_ERRORS['javascript'], "--analyze-stack"]),
# Suggestions
("Suggestions", ["python3", "-m", "claudecode_debugger.cli_new",
TEST_ERRORS['python'], "--suggest"]),
# Verbose mode
("Verbose Mode", ["python3", "-m", "claudecode_debugger.cli_new",
TEST_ERRORS['typescript'], "--verbose"]),
# Combined features
("Combined Features", ["python3", "-m", "claudecode_debugger.cli_new",
TEST_ERRORS['python'], "--lang", "zh",
"--analyze-stack", "--suggest", "--verbose"]),
]
for name, cmd in tests:
print(f"\n[{name}]")
result = run_command(cmd)
print(f"Exit code: {result.returncode}")
if result.returncode != 0:
print(f"Error: {result.stderr[:200]}")
else:
print("✅ Success")
def test_file_operations():
"""Test file input/output operations."""
print("\n" + "=" * 60)
print("Testing File Operations")
print("=" * 60)
# Create temp files
with tempfile.NamedTemporaryFile(mode='w', suffix='.log', delete=False) as f:
f.write(TEST_ERRORS['python'])
error_file = f.name
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
output_file = f.name
tests = [
# Read from file
("Read from File", ["python3", "-m", "claudecode_debugger.cli_new",
"-f", error_file]),
# Output to file
("Output to File", ["python3", "-m", "claudecode_debugger.cli_new",
TEST_ERRORS['javascript'], "-o", output_file]),
# Read and output
("Read & Output", ["python3", "-m", "claudecode_debugger.cli_new",
"-f", error_file, "-o", output_file, "--lang", "zh"]),
]
for name, cmd in tests:
print(f"\n[{name}]")
result = run_command(cmd)
print(f"Exit code: {result.returncode}")
if result.returncode != 0:
print(f"Error: {result.stderr[:200]}")
else:
print("✅ Success")
# Check output file
if Path(output_file).exists():
content = Path(output_file).read_text()
print(f"\nOutput file created: {len(content)} bytes")
# Cleanup
Path(error_file).unlink()
Path(output_file).unlink()
def test_interactive_mode():
"""Test interactive mode."""
print("\n" + "=" * 60)
print("Testing Interactive Mode")
print("=" * 60)
# Test interactive mode with input
cmd = ["python3", "-m", "claudecode_debugger.cli_new", "-i"]
print("[Interactive Mode - Basic]")
result = run_command(cmd, input_data=TEST_ERRORS['python'])
print(f"Exit code: {result.returncode}")
if result.returncode != 0:
print(f"Error: {result.stderr[:200]}")
else:
print("✅ Success")
# Test with analysis options
cmd = ["python3", "-m", "claudecode_debugger.cli_new", "-i", "--suggest", "--lang", "zh"]
print("\n[Interactive Mode - With Options]")
result = run_command(cmd, input_data=TEST_ERRORS['javascript'])
print(f"Exit code: {result.returncode}")
if result.returncode != 0:
print(f"Error: {result.stderr[:200]}")
else:
print("✅ Success")
def test_edge_cases():
"""Test edge cases and error handling."""
print("\n" + "=" * 60)
print("Testing Edge Cases")
print("=" * 60)
tests = [
# Empty input
("Empty Input", ["python3", "-m", "claudecode_debugger.cli_new", ""]),
# Invalid language
("Invalid File", ["python3", "-m", "claudecode_debugger.cli_new",
"-f", "nonexistent.log"]),
# Multiple errors
("Multiple Errors", ["python3", "-m", "claudecode_debugger.cli_new",
TEST_ERRORS['python'] + "\n" + TEST_ERRORS['javascript']]),
]
for name, cmd in tests:
print(f"\n[{name}]")
result = run_command(cmd)
print(f"Exit code: {result.returncode}")
# These might fail, which is expected
if result.returncode == 0:
print("✅ Handled gracefully")
else:
print("❌ Expected failure")
def main():
"""Run all CLI tests."""
print("ClaudeCode-Debugger Complete CLI Test")
print("=" * 60)
test_basic_commands()
test_analysis_features()
test_file_operations()
test_interactive_mode()
test_edge_cases()
print("\n" + "=" * 60)
print("All CLI tests completed!")
print("=" * 60)
if __name__ == "__main__":
main()