-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_commands.rb
More file actions
316 lines (280 loc) · 10 KB
/
test_commands.rb
File metadata and controls
316 lines (280 loc) · 10 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/usr/bin/env ruby
# Script de test des commandes STORM
require 'json'
class CommandTester
def initialize
@test_results = []
@commands_tested = 0
puts "=== STORM Command Functionality Tester ==="
puts "Testing all available commands\n\n"
end
def test_command_files
puts "1. Testing command file structure and basic functionality..."
command_categories = {
'Appearance' => [
'background_command.rb',
'color_command.rb',
'language_command.rb',
'list_colors_command.rb',
'stop_music_command.rb',
'text_color_command.rb',
'typography_command.rb'
],
'Chat_Management' => [
'banned_command.rb',
'clear_client_command.rb',
'clear_command.rb',
'history_command.rb',
'info_command.rb',
'list_command.rb'
],
'Media_Commands' => [
'file_command.rb',
'image_command.rb',
'music_command.rb',
'play_music_command.rb',
'upload_command.rb',
'volume_command.rb'
],
'Room_Management' => [
'ban_command.rb',
'change_password_command.rb',
'change_room_command.rb',
'create_room_command.rb',
'kick_command.rb',
'list_rooms_command.rb',
'power_transfer_command.rb'
],
'User_Management' => [
'accept_friend_command.rb',
'add_friend_command.rb',
'change_username_command.rb',
'decline_friend_command.rb',
'direct_message_command.rb',
'friends_list_command.rb',
'global_direct_message_command.rb',
'login_command.rb',
'pending_requests_command.rb',
'quit_command.rb',
'register_command.rb',
'remove_friend_command.rb',
'save_preferences_command.rb'
]
}
command_categories.each do |category, commands|
puts "\n Testing #{category} commands:"
commands.each do |command_file|
file_path = "Message/commands/#{category}/#{command_file}"
if File.exist?(file_path)
# Test file syntax
result = `ruby -c "#{file_path}" 2>&1`
if $?.success?
puts " ✓ #{command_file} - syntax OK"
# Try to analyze command structure
content = File.read(file_path)
# Check for required methods/structure
has_execute = content.include?('def execute') || content.include?('def call')
has_class = content.match(/class\s+\w+/)
if has_execute && has_class
puts " ✓ Has proper command structure"
@test_results << {
command: command_file,
category: category,
status: "PASS",
structure: "Complete"
}
else
puts " ! Missing execute method or class definition"
@test_results << {
command: command_file,
category: category,
status: "WARNING",
structure: "Incomplete"
}
end
@commands_tested += 1
else
puts " ✗ #{command_file} - syntax error"
@test_results << {
command: command_file,
category: category,
status: "FAIL",
error: result.strip
}
end
else
puts " ✗ #{command_file} - file missing"
@test_results << {
command: command_file,
category: category,
status: "MISSING"
}
end
end
end
puts
end
def test_base_command
puts "2. Testing base command structure..."
base_files = ['Message/commands/base_command.rb', 'Message/commands/help_command.rb']
base_files.each do |file|
if File.exist?(file)
result = `ruby -c "#{file}" 2>&1`
if $?.success?
puts " ✓ #{File.basename(file)} - syntax OK"
content = File.read(file)
if content.include?('class') && (content.include?('def') || content.include?('module'))
puts " ✓ Has proper structure"
@test_results << { command: File.basename(file), status: "PASS" }
else
puts " ! Structure may be incomplete"
@test_results << { command: File.basename(file), status: "WARNING" }
end
else
puts " ✗ #{File.basename(file)} - syntax error"
@test_results << { command: File.basename(file), status: "FAIL" }
end
else
puts " ✗ #{File.basename(file)} - missing"
@test_results << { command: File.basename(file), status: "MISSING" }
end
end
puts
end
def test_controllers
puts "3. Testing controller files..."
controllers = [
'Message/controllers/chat_controller.rb',
'Message/controllers/command_handler.rb',
'Message/controllers/language_manager.rb',
'Message/controllers/preference_manager.rb',
'Message/controllers/user_manager.rb'
]
controllers.each do |controller|
if File.exist?(controller)
result = `ruby -c "#{controller}" 2>&1`
if $?.success?
puts " ✓ #{File.basename(controller)} - syntax OK"
content = File.read(controller)
if content.include?('class') && content.include?('def')
puts " ✓ Has proper controller structure"
@test_results << { controller: File.basename(controller), status: "PASS" }
else
puts " ! Controller structure may be incomplete"
@test_results << { controller: File.basename(controller), status: "WARNING" }
end
else
puts " ✗ #{File.basename(controller)} - syntax error"
@test_results << { controller: File.basename(controller), status: "FAIL" }
end
else
puts " ✗ #{File.basename(controller)} - missing"
@test_results << { controller: File.basename(controller), status: "MISSING" }
end
end
puts
end
def analyze_command_coverage
puts "4. Analyzing command coverage based on README..."
expected_commands = {
'/cr' => 'create_room_command.rb',
'/cd' => 'change_room_command.rb',
'/info' => 'info_command.rb',
'/list' => 'list_command.rb',
'/help' => 'help_command.rb',
'/history' => 'history_command.rb',
'/dm' => 'direct_message_command.rb',
'/quit' => 'quit_command.rb',
'/color' => 'color_command.rb',
'/background' => 'background_command.rb',
'/typo' => 'typography_command.rb',
'/textcolor' => 'text_color_command.rb',
'/ban' => 'ban_command.rb',
'/kick' => 'kick_command.rb',
'/powerto' => 'power_transfer_command.rb',
'/register' => 'register_command.rb',
'/login' => 'login_command.rb'
}
puts " Expected commands from README:"
expected_commands.each do |command, file|
# Check if corresponding file exists in any category
found = false
['Appearance', 'Chat_Management', 'Media_Commands', 'Room_Management', 'User_Management'].each do |category|
if File.exist?("Message/commands/#{category}/#{file}")
puts " ✓ #{command} -> #{file} (found in #{category})"
found = true
break
end
end
unless found
puts " ✗ #{command} -> #{file} (not found)"
@test_results << { command: command, expected_file: file, status: "MISSING" }
end
end
puts
end
def generate_detailed_report
puts "=== DETAILED TEST REPORT ==="
total_tests = @test_results.length
passed = @test_results.count { |r| r[:status] == "PASS" }
warnings = @test_results.count { |r| r[:status] == "WARNING" }
failed = @test_results.count { |r| r[:status] == "FAIL" }
missing = @test_results.count { |r| r[:status] == "MISSING" }
puts "Commands tested: #{@commands_tested}"
puts "Total tests: #{total_tests}"
puts "✓ Passed: #{passed}"
puts "! Warnings: #{warnings}"
puts "✗ Failed: #{failed}"
puts "? Missing: #{missing}"
puts
if warnings > 0
puts "WARNINGS (may need attention):"
@test_results.select { |r| r[:status] == "WARNING" }.each do |result|
puts " - #{result[:command] || result[:controller]}: #{result[:structure] || 'Structure incomplete'}"
end
puts
end
if failed > 0
puts "FAILED TESTS:"
@test_results.select { |r| r[:status] == "FAIL" }.each do |result|
puts " - #{result[:command] || result[:controller]}: #{result[:error] || 'Failed'}"
end
puts
end
if missing > 0
puts "MISSING FILES:"
@test_results.select { |r| r[:status] == "MISSING" }.each do |result|
puts " - #{result[:command] || result[:expected_file] || result[:controller]}"
end
puts
end
puts "=== FUNCTIONALITY STATUS ==="
functionality_score = ((passed + warnings * 0.5) / total_tests * 100).round(1)
puts "Overall functionality score: #{functionality_score}%"
if functionality_score >= 90
puts "🟢 Excellent - Application is ready for testing"
elsif functionality_score >= 75
puts "🟡 Good - Minor issues to address"
elsif functionality_score >= 50
puts "🟠 Fair - Several issues need attention"
else
puts "🔴 Poor - Major issues need to be resolved"
end
puts "\n=== NEXT STEPS ==="
puts "1. Fix any syntax errors in failed files"
puts "2. Implement missing command files"
puts "3. Ensure all commands have proper execute methods"
puts "4. Test actual command execution with WebSocket connections"
puts "5. Verify database operations work correctly"
end
def run_all_tests
test_command_files
test_base_command
test_controllers
analyze_command_coverage
generate_detailed_report
end
end
# Run the command tests
tester = CommandTester.new
tester.run_all_tests