shark 0.0.0.5.2 → 0.0.0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -17
- data/Gemfile +4 -4
- data/README.md +30 -29
- data/Rakefile +1 -1
- data/bin/Shark +544 -544
- data/lib/shark/version.rb +3 -3
- data/lib/shark.rb +5 -5
- data/shark.gemspec +23 -23
- data/src/shark.rb +578 -542
- metadata +9 -15
data/src/shark.rb
CHANGED
@@ -1,543 +1,579 @@
|
|
1
|
-
#Shark is a simple testing tool for testing file system operations. It is still under development
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
class Shark
|
7
|
-
|
8
|
-
def initialize(a1,a2,a3)
|
9
|
-
|
10
|
-
@features_directory = a1
|
11
|
-
|
12
|
-
@files_directory = a2
|
13
|
-
|
14
|
-
@base_path = a3
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def start_test
|
19
|
-
|
20
|
-
def read_file_line_by_line(input_path)
|
21
|
-
|
22
|
-
file_id = open(input_path)
|
23
|
-
|
24
|
-
file_line_by_line = file_id.readlines()
|
25
|
-
|
26
|
-
file_id.close
|
27
|
-
|
28
|
-
return file_line_by_line
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def find_file_name(input_path, file_extension)
|
33
|
-
|
34
|
-
extension_remover = input_path.split(file_extension)
|
35
|
-
|
36
|
-
remaining_string = extension_remover[0].reverse
|
37
|
-
|
38
|
-
path_finder = remaining_string.index("/")
|
39
|
-
|
40
|
-
remaining_string = remaining_string.reverse
|
41
|
-
|
42
|
-
return remaining_string[remaining_string.length-path_finder..-1]
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def parse_feature(input_feature_contents)
|
47
|
-
|
48
|
-
#This method extracts scenarios from a feature file
|
49
|
-
|
50
|
-
#Input:
|
51
|
-
#input_feature_contents => An array containing the contents of a feature file
|
52
|
-
|
53
|
-
#Output:
|
54
|
-
#feature_name => Name and description of the feature described in the file
|
55
|
-
#modified_scenarios => An array containing scenario descriptions and scenario steps
|
56
|
-
|
57
|
-
def find_all_matching_indices(input_string,pattern)
|
58
|
-
|
59
|
-
locations = []
|
60
|
-
|
61
|
-
index = input_string.index(pattern)
|
62
|
-
|
63
|
-
while index != nil
|
64
|
-
|
65
|
-
locations << index
|
66
|
-
|
67
|
-
index = input_string.index(pattern,index+1)
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
return locations
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
while input_feature_contents[0].eql?("\n")
|
78
|
-
|
79
|
-
input_feature_contents.delete_at(0)
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
feature_contents_string = input_feature_contents.join
|
84
|
-
|
85
|
-
feature_name = ""
|
86
|
-
|
87
|
-
if feature_contents_string.include?("Scenario:")
|
88
|
-
|
89
|
-
feature_name = feature_contents_string[feature_contents_string.index("Feature:")...feature_contents_string.index("Scenario:")].rstrip
|
90
|
-
|
91
|
-
else
|
92
|
-
|
93
|
-
feature_name = feature_contents_string.rstrip
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
scenarios = []
|
98
|
-
|
99
|
-
scenarios_index = find_all_matching_indices(feature_contents_string,"Scenario:")
|
100
|
-
|
101
|
-
scenarios_index << -1
|
102
|
-
|
103
|
-
for x in 0...scenarios_index.length-1
|
104
|
-
|
105
|
-
scenario = feature_contents_string[scenarios_index[x]...scenarios_index[x+1]]
|
106
|
-
|
107
|
-
scenarios << [scenario.lstrip]
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
modified_scenarios = scenarios.dup
|
112
|
-
|
113
|
-
scenario_names = []
|
114
|
-
|
115
|
-
scenarios.each_with_index do |s,index|
|
116
|
-
|
117
|
-
scenario_steps = s[0].split(" ")[1..-1]
|
118
|
-
|
119
|
-
scenario_names << s[0].split(" ")[0]
|
120
|
-
|
121
|
-
modified_scenarios[index] << scenario_steps
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
return feature_name,scenario_names,modified_scenarios
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
def parse_and_test_steps(input_steps,test_files_directory,configuration,config_variables,base_path)
|
130
|
-
|
131
|
-
#This method parses the steps for a given scenario and produces a result using the following keywords
|
132
|
-
|
133
|
-
#Keywords
|
134
|
-
|
135
|
-
#Input
|
136
|
-
#File
|
137
|
-
#When
|
138
|
-
#Run
|
139
|
-
#Output
|
140
|
-
#Equal
|
141
|
-
|
142
|
-
#Input:
|
143
|
-
#input_steps => An array containing the steps
|
144
|
-
|
145
|
-
#Output:
|
146
|
-
#test_result => A string and a boolean containing the results of the test
|
147
|
-
|
148
|
-
def read_file_line_by_line(input_path)
|
149
|
-
|
150
|
-
file_id = open(input_path)
|
151
|
-
|
152
|
-
file_line_by_line = file_id.readlines()
|
153
|
-
|
154
|
-
file_id.close
|
155
|
-
|
156
|
-
return file_line_by_line
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
input_procedures = input_steps.reject {|element| !element.include?("$input")}
|
161
|
-
|
162
|
-
input_file_names = []
|
163
|
-
|
164
|
-
input_procedures.each do |procedure|
|
165
|
-
|
166
|
-
if procedure.include? "$file"
|
167
|
-
|
168
|
-
opening_quotes = procedure.index("\"")
|
169
|
-
|
170
|
-
file_name = procedure[opening_quotes...procedure.index("\"",opening_quotes+1)]
|
171
|
-
|
172
|
-
input_file_names << file_name
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
input_file_contents = input_steps.dup
|
179
|
-
|
180
|
-
test_files_directory = test_files_directory.sub(Dir.pwd,"").sub("/","")
|
181
|
-
|
182
|
-
input_file_names = input_file_names.collect{|element| test_files_directory+element[1..-1]}
|
183
|
-
|
184
|
-
run_procedures = input_file_contents.reject{ |element| !element.include?("$run")}
|
185
|
-
|
186
|
-
run_keywords = ["$cliusage"]
|
187
|
-
|
188
|
-
configuration_vars = config_variables.keys
|
189
|
-
|
190
|
-
modified_keyword_usage = nil
|
191
|
-
|
192
|
-
executable_statements = [[]]*configuration_vars.length
|
193
|
-
|
194
|
-
run_keywords.each do |keyword|
|
195
|
-
|
196
|
-
keyword_usage = configuration.reject { |element| !element.include?(keyword)}
|
197
|
-
|
198
|
-
modified_keyword_usage = keyword_usage.dup
|
199
|
-
|
200
|
-
keyword_usage.each_with_index do |line,index|
|
201
|
-
|
202
|
-
configuration_vars.each_with_index do |var,var_index|
|
203
|
-
|
204
|
-
modified_keyword_usage[index] = modified_keyword_usage[index].gsub(var,"#{config_variables[var]}")
|
205
|
-
|
206
|
-
statement_split = modified_keyword_usage[index].split("=>")
|
207
|
-
|
208
|
-
executable_statements[var_index] << statement_split[1].lstrip.rstrip
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
end
|
213
|
-
|
214
|
-
end
|
215
|
-
|
216
|
-
configuration_vars.each_with_index do |var,index|
|
217
|
-
|
218
|
-
current_var_run_procedures = run_procedures.reject{|element| !element.include?(var)}
|
219
|
-
|
220
|
-
current_var_run_procedures.each do |run|
|
221
|
-
|
222
|
-
current_executable_statements = executable_statements[index]
|
223
|
-
|
224
|
-
current_executable_statements.each do |executable|
|
225
|
-
|
226
|
-
input_file_names.each do |file_name|
|
227
|
-
|
228
|
-
current_executable_statement = executable.gsub("$file",file_name)
|
229
|
-
|
230
|
-
cli_output = `#{current_executable_statement.strip.lstrip.rstrip}`
|
231
|
-
|
232
|
-
end
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
end
|
237
|
-
|
238
|
-
|
239
|
-
end
|
240
|
-
|
241
|
-
output_procedures = input_steps.reject {|element| !element.include?("$output")}
|
242
|
-
|
243
|
-
matching_file_names = []
|
244
|
-
|
245
|
-
output_file_names = []
|
246
|
-
|
247
|
-
output_procedures.each do |procedure|
|
248
|
-
|
249
|
-
if procedure.include?("$equal") and procedure.include?("$file")
|
250
|
-
|
251
|
-
opening_quotes = procedure.index("\"")
|
252
|
-
|
253
|
-
file_name = procedure[opening_quotes...procedure.index("\"",opening_quotes+1)]
|
254
|
-
|
255
|
-
matching_file_names << file_name
|
256
|
-
|
257
|
-
else
|
258
|
-
|
259
|
-
opening_quotes = procedure.index("\"")
|
260
|
-
|
261
|
-
file_name = procedure[opening_quotes...procedure.index("\"",opening_quotes+1)]
|
262
|
-
|
263
|
-
output_file_names << file_name
|
264
|
-
|
265
|
-
end
|
266
|
-
|
267
|
-
end
|
268
|
-
|
269
|
-
output_file_names = output_file_names.collect {|element| test_files_directory + element[1..-1]}
|
270
|
-
|
271
|
-
matching_file_names = matching_file_names.collect {|element| test_files_directory+element[1..-1]}
|
272
|
-
|
273
|
-
output_file_contents = output_file_names.collect{ |element| read_file_line_by_line(element)}
|
274
|
-
|
275
|
-
matching_file_contents = matching_file_names.collect{ |element| read_file_line_by_line(element)}
|
276
|
-
|
277
|
-
test_results = []
|
278
|
-
|
279
|
-
false_results = []
|
280
|
-
|
281
|
-
matching_file_contents.each_with_index do |matching_file,matching_index|
|
282
|
-
|
283
|
-
false_results << [matching_file_names[matching_index]]
|
284
|
-
|
285
|
-
output_file_contents.each_with_index do |output_file,index|
|
286
|
-
|
287
|
-
if matching_file.eql?(output_file)
|
288
|
-
|
289
|
-
test_results << true
|
290
|
-
|
291
|
-
else
|
292
|
-
|
293
|
-
test_results << false
|
294
|
-
|
295
|
-
false_results[-1] << [output_file_names[index]]
|
296
|
-
|
297
|
-
end
|
298
|
-
|
299
|
-
end
|
300
|
-
|
301
|
-
end
|
302
|
-
|
303
|
-
if test_results.include?(false)
|
304
|
-
|
305
|
-
output_string = "\nThe test failed!\n\nA detailed breakdown of the failing files have been given below."
|
306
|
-
|
307
|
-
output_string = output_string + "\n\n"
|
308
|
-
|
309
|
-
detailed_fail_list = ""
|
310
|
-
|
311
|
-
false_results.each do |result|
|
312
|
-
|
313
|
-
detailed_fail_list = detailed_fail_list + "The following files failed in comparison with #{result[0]}"
|
314
|
-
|
315
|
-
failed_files = result[1]
|
316
|
-
|
317
|
-
failed_files.each do |file|
|
318
|
-
|
319
|
-
detailed_fail_list = detailed_fail_list + "\n\n" + "* #{file}\n"
|
320
|
-
|
321
|
-
end
|
322
|
-
|
323
|
-
end
|
324
|
-
|
325
|
-
return output_string = output_string + detailed_fail_list
|
326
|
-
|
327
|
-
else
|
328
|
-
|
329
|
-
return "\nYour test file(s) passed the feature test.\n\n"
|
330
|
-
|
331
|
-
end
|
332
|
-
|
333
|
-
end
|
334
|
-
|
335
|
-
def extract_configurations(feature_contents)
|
336
|
-
|
337
|
-
config_start_index = 0
|
338
|
-
|
339
|
-
feature_contents.each_with_index do |line,index|
|
340
|
-
|
341
|
-
if line.include?("Configurations:")
|
342
|
-
|
343
|
-
config_start_index = index
|
344
|
-
|
345
|
-
end
|
346
|
-
|
347
|
-
end
|
348
|
-
|
349
|
-
modified_feature_contents = feature_contents[0...config_start_index]
|
350
|
-
|
351
|
-
configurations = feature_contents[config_start_index..-1]
|
352
|
-
|
353
|
-
configuration_variables = configurations.join.match(/~\w{1,}/).to_a
|
354
|
-
|
355
|
-
configuration_variable_index = [[]]*configuration_variables.length
|
356
|
-
|
357
|
-
configurations.each_with_index do |line,index|
|
358
|
-
|
359
|
-
configuration_variables.each_with_index do |variable,var_index|
|
360
|
-
|
361
|
-
if line.include?(variable)
|
362
|
-
|
363
|
-
configuration_variable_index[var_index] << index
|
364
|
-
|
365
|
-
end
|
366
|
-
|
367
|
-
end
|
368
|
-
|
369
|
-
end
|
370
|
-
|
371
|
-
def reset_test_files_directory(original_file_list,after_file_list)
|
372
|
-
|
373
|
-
added_files = after_file_list-original_file_list
|
374
|
-
|
375
|
-
added_files.each do |file_name|
|
376
|
-
|
377
|
-
File.delete(file_name)
|
378
|
-
|
379
|
-
end
|
380
|
-
|
381
|
-
end
|
382
|
-
|
383
|
-
configuration_variable_index = configuration_variable_index.collect{ |element| element[0]}
|
384
|
-
|
385
|
-
configuration_variable_index << configurations.length-1
|
386
|
-
|
387
|
-
modified_configurations = configurations.dup
|
388
|
-
|
389
|
-
for x in 0...configuration_variable_index.length-1
|
390
|
-
|
391
|
-
current_index = configuration_variable_index[x]
|
392
|
-
|
393
|
-
current_variable = configuration_variables[x]
|
394
|
-
|
395
|
-
for y in current_index..configuration_variable_index[x+1]
|
396
|
-
|
397
|
-
modified_configurations[y] = configurations[y].gsub(":v",current_variable)
|
398
|
-
|
399
|
-
end
|
400
|
-
|
401
|
-
end
|
402
|
-
|
403
|
-
configuration_var_values = []
|
404
|
-
|
405
|
-
configuration_variable_index.delete_at(1)
|
406
|
-
|
407
|
-
configuration_variable_index.each do |index|
|
408
|
-
|
409
|
-
var_split = modified_configurations[index].split("=>")
|
410
|
-
|
411
|
-
var_value = var_split[1].lstrip.rstrip
|
412
|
-
|
413
|
-
configuration_var_values << var_value
|
414
|
-
|
415
|
-
end
|
416
|
-
|
417
|
-
configuration_values = Hash[configuration_variables.zip(configuration_var_values)]
|
418
|
-
|
419
|
-
return modified_feature_contents,modified_configurations,configuration_values
|
420
|
-
|
421
|
-
end
|
422
|
-
|
423
|
-
list_of_features = []
|
424
|
-
|
425
|
-
Dir.foreach(@features_directory) { |x| list_of_features << @features_directory+"#{x}" }
|
426
|
-
|
427
|
-
initial_files_list = []
|
428
|
-
|
429
|
-
Dir.foreach(@files_directory) { |x| initial_files_list << @files_directory+"#{x}" }
|
430
|
-
|
431
|
-
list_of_features = list_of_features.reject { |path| !path.include?(".feature")}
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
scenarios
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
scenario[1] = scenario[1].collect{|element| element.sub("
|
452
|
-
|
453
|
-
scenario[1] = scenario[1].collect{|element| element.sub("
|
454
|
-
|
455
|
-
scenario[1] = scenario[1].collect{|element| element.sub("
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
end
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
1
|
+
#Shark is a simple testing tool for testing file system operations. It is still under development
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
class Shark
|
7
|
+
|
8
|
+
def initialize(a1,a2,a3)
|
9
|
+
|
10
|
+
@features_directory = a1
|
11
|
+
|
12
|
+
@files_directory = a2
|
13
|
+
|
14
|
+
@base_path = a3
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def start_test
|
19
|
+
|
20
|
+
def read_file_line_by_line(input_path)
|
21
|
+
|
22
|
+
file_id = open(input_path)
|
23
|
+
|
24
|
+
file_line_by_line = file_id.readlines()
|
25
|
+
|
26
|
+
file_id.close
|
27
|
+
|
28
|
+
return file_line_by_line
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_file_name(input_path, file_extension)
|
33
|
+
|
34
|
+
extension_remover = input_path.split(file_extension)
|
35
|
+
|
36
|
+
remaining_string = extension_remover[0].reverse
|
37
|
+
|
38
|
+
path_finder = remaining_string.index("/")
|
39
|
+
|
40
|
+
remaining_string = remaining_string.reverse
|
41
|
+
|
42
|
+
return remaining_string[remaining_string.length-path_finder..-1]
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_feature(input_feature_contents)
|
47
|
+
|
48
|
+
#This method extracts scenarios from a feature file
|
49
|
+
|
50
|
+
#Input:
|
51
|
+
#input_feature_contents => An array containing the contents of a feature file
|
52
|
+
|
53
|
+
#Output:
|
54
|
+
#feature_name => Name and description of the feature described in the file
|
55
|
+
#modified_scenarios => An array containing scenario descriptions and scenario steps
|
56
|
+
|
57
|
+
def find_all_matching_indices(input_string,pattern)
|
58
|
+
|
59
|
+
locations = []
|
60
|
+
|
61
|
+
index = input_string.index(pattern)
|
62
|
+
|
63
|
+
while index != nil
|
64
|
+
|
65
|
+
locations << index
|
66
|
+
|
67
|
+
index = input_string.index(pattern,index+1)
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
return locations
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
while input_feature_contents[0].eql?("\n")
|
78
|
+
|
79
|
+
input_feature_contents.delete_at(0)
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
feature_contents_string = input_feature_contents.join
|
84
|
+
|
85
|
+
feature_name = ""
|
86
|
+
|
87
|
+
if feature_contents_string.include?("Scenario:")
|
88
|
+
|
89
|
+
feature_name = feature_contents_string[feature_contents_string.index("Feature:")...feature_contents_string.index("Scenario:")].rstrip
|
90
|
+
|
91
|
+
else
|
92
|
+
|
93
|
+
feature_name = feature_contents_string.rstrip
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
scenarios = []
|
98
|
+
|
99
|
+
scenarios_index = find_all_matching_indices(feature_contents_string,"Scenario:")
|
100
|
+
|
101
|
+
scenarios_index << -1
|
102
|
+
|
103
|
+
for x in 0...scenarios_index.length-1
|
104
|
+
|
105
|
+
scenario = feature_contents_string[scenarios_index[x]...scenarios_index[x+1]]
|
106
|
+
|
107
|
+
scenarios << [scenario.lstrip]
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
modified_scenarios = scenarios.dup
|
112
|
+
|
113
|
+
scenario_names = []
|
114
|
+
|
115
|
+
scenarios.each_with_index do |s,index|
|
116
|
+
|
117
|
+
scenario_steps = s[0].split(" ")[1..-1]
|
118
|
+
|
119
|
+
scenario_names << s[0].split(" ")[0]
|
120
|
+
|
121
|
+
modified_scenarios[index] << scenario_steps
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
return feature_name,scenario_names,modified_scenarios
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
def parse_and_test_steps(input_steps,test_files_directory,configuration,config_variables,base_path)
|
130
|
+
|
131
|
+
#This method parses the steps for a given scenario and produces a result using the following keywords
|
132
|
+
|
133
|
+
#Keywords
|
134
|
+
|
135
|
+
#Input
|
136
|
+
#File
|
137
|
+
#When
|
138
|
+
#Run
|
139
|
+
#Output
|
140
|
+
#Equal
|
141
|
+
|
142
|
+
#Input:
|
143
|
+
#input_steps => An array containing the steps
|
144
|
+
|
145
|
+
#Output:
|
146
|
+
#test_result => A string and a boolean containing the results of the test
|
147
|
+
|
148
|
+
def read_file_line_by_line(input_path)
|
149
|
+
|
150
|
+
file_id = open(input_path)
|
151
|
+
|
152
|
+
file_line_by_line = file_id.readlines()
|
153
|
+
|
154
|
+
file_id.close
|
155
|
+
|
156
|
+
return file_line_by_line
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
input_procedures = input_steps.reject {|element| !element.include?("$input")}
|
161
|
+
|
162
|
+
input_file_names = []
|
163
|
+
|
164
|
+
input_procedures.each do |procedure|
|
165
|
+
|
166
|
+
if procedure.include? "$file"
|
167
|
+
|
168
|
+
opening_quotes = procedure.index("\"")
|
169
|
+
|
170
|
+
file_name = procedure[opening_quotes...procedure.index("\"",opening_quotes+1)]
|
171
|
+
|
172
|
+
input_file_names << file_name
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
input_file_contents = input_steps.dup
|
179
|
+
|
180
|
+
test_files_directory = test_files_directory.sub(Dir.pwd,"").sub("/","")
|
181
|
+
|
182
|
+
input_file_names = input_file_names.collect{|element| test_files_directory+element[1..-1]}
|
183
|
+
|
184
|
+
run_procedures = input_file_contents.reject{ |element| !element.include?("$run")}
|
185
|
+
|
186
|
+
run_keywords = ["$cliusage"]
|
187
|
+
|
188
|
+
configuration_vars = config_variables.keys
|
189
|
+
|
190
|
+
modified_keyword_usage = nil
|
191
|
+
|
192
|
+
executable_statements = [[]]*configuration_vars.length
|
193
|
+
|
194
|
+
run_keywords.each do |keyword|
|
195
|
+
|
196
|
+
keyword_usage = configuration.reject { |element| !element.include?(keyword)}
|
197
|
+
|
198
|
+
modified_keyword_usage = keyword_usage.dup
|
199
|
+
|
200
|
+
keyword_usage.each_with_index do |line,index|
|
201
|
+
|
202
|
+
configuration_vars.each_with_index do |var,var_index|
|
203
|
+
|
204
|
+
modified_keyword_usage[index] = modified_keyword_usage[index].gsub(var,"#{config_variables[var]}")
|
205
|
+
|
206
|
+
statement_split = modified_keyword_usage[index].split("=>")
|
207
|
+
|
208
|
+
executable_statements[var_index] << statement_split[1].lstrip.rstrip
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
configuration_vars.each_with_index do |var,index|
|
217
|
+
|
218
|
+
current_var_run_procedures = run_procedures.reject{|element| !element.include?(var)}
|
219
|
+
|
220
|
+
current_var_run_procedures.each do |run|
|
221
|
+
|
222
|
+
current_executable_statements = executable_statements[index]
|
223
|
+
|
224
|
+
current_executable_statements.each do |executable|
|
225
|
+
|
226
|
+
input_file_names.each do |file_name|
|
227
|
+
|
228
|
+
current_executable_statement = executable.gsub("$file",file_name)
|
229
|
+
|
230
|
+
cli_output = `#{current_executable_statement.strip.lstrip.rstrip}`
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
output_procedures = input_steps.reject {|element| !element.include?("$output")}
|
242
|
+
|
243
|
+
matching_file_names = []
|
244
|
+
|
245
|
+
output_file_names = []
|
246
|
+
|
247
|
+
output_procedures.each do |procedure|
|
248
|
+
|
249
|
+
if procedure.include?("$equal") and procedure.include?("$file")
|
250
|
+
|
251
|
+
opening_quotes = procedure.index("\"")
|
252
|
+
|
253
|
+
file_name = procedure[opening_quotes...procedure.index("\"",opening_quotes+1)]
|
254
|
+
|
255
|
+
matching_file_names << file_name
|
256
|
+
|
257
|
+
else
|
258
|
+
|
259
|
+
opening_quotes = procedure.index("\"")
|
260
|
+
|
261
|
+
file_name = procedure[opening_quotes...procedure.index("\"",opening_quotes+1)]
|
262
|
+
|
263
|
+
output_file_names << file_name
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
output_file_names = output_file_names.collect {|element| test_files_directory + element[1..-1]}
|
270
|
+
|
271
|
+
matching_file_names = matching_file_names.collect {|element| test_files_directory+element[1..-1]}
|
272
|
+
|
273
|
+
output_file_contents = output_file_names.collect{ |element| read_file_line_by_line(element)}
|
274
|
+
|
275
|
+
matching_file_contents = matching_file_names.collect{ |element| read_file_line_by_line(element)}
|
276
|
+
|
277
|
+
test_results = []
|
278
|
+
|
279
|
+
false_results = []
|
280
|
+
|
281
|
+
matching_file_contents.each_with_index do |matching_file,matching_index|
|
282
|
+
|
283
|
+
false_results << [matching_file_names[matching_index]]
|
284
|
+
|
285
|
+
output_file_contents.each_with_index do |output_file,index|
|
286
|
+
|
287
|
+
if matching_file.eql?(output_file)
|
288
|
+
|
289
|
+
test_results << true
|
290
|
+
|
291
|
+
else
|
292
|
+
|
293
|
+
test_results << false
|
294
|
+
|
295
|
+
false_results[-1] << [output_file_names[index]]
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
if test_results.include?(false)
|
304
|
+
|
305
|
+
output_string = "\nThe test failed!\n\nA detailed breakdown of the failing files have been given below."
|
306
|
+
|
307
|
+
output_string = output_string + "\n\n"
|
308
|
+
|
309
|
+
detailed_fail_list = ""
|
310
|
+
|
311
|
+
false_results.each do |result|
|
312
|
+
|
313
|
+
detailed_fail_list = detailed_fail_list + "The following files failed in comparison with #{result[0]}"
|
314
|
+
|
315
|
+
failed_files = result[1]
|
316
|
+
|
317
|
+
failed_files.each do |file|
|
318
|
+
|
319
|
+
detailed_fail_list = detailed_fail_list + "\n\n" + "* #{file}\n"
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
return output_string = output_string + detailed_fail_list, false
|
326
|
+
|
327
|
+
else
|
328
|
+
|
329
|
+
return "\nYour test file(s) passed the feature test.\n\n", true
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
end
|
334
|
+
|
335
|
+
def extract_configurations(feature_contents)
|
336
|
+
|
337
|
+
config_start_index = 0
|
338
|
+
|
339
|
+
feature_contents.each_with_index do |line,index|
|
340
|
+
|
341
|
+
if line.include?("Configurations:")
|
342
|
+
|
343
|
+
config_start_index = index
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
end
|
348
|
+
|
349
|
+
modified_feature_contents = feature_contents[0...config_start_index]
|
350
|
+
|
351
|
+
configurations = feature_contents[config_start_index..-1]
|
352
|
+
|
353
|
+
configuration_variables = configurations.join.match(/~\w{1,}/).to_a
|
354
|
+
|
355
|
+
configuration_variable_index = [[]]*configuration_variables.length
|
356
|
+
|
357
|
+
configurations.each_with_index do |line,index|
|
358
|
+
|
359
|
+
configuration_variables.each_with_index do |variable,var_index|
|
360
|
+
|
361
|
+
if line.include?(variable)
|
362
|
+
|
363
|
+
configuration_variable_index[var_index] << index
|
364
|
+
|
365
|
+
end
|
366
|
+
|
367
|
+
end
|
368
|
+
|
369
|
+
end
|
370
|
+
|
371
|
+
def reset_test_files_directory(original_file_list,after_file_list)
|
372
|
+
|
373
|
+
added_files = after_file_list-original_file_list
|
374
|
+
|
375
|
+
added_files.each do |file_name|
|
376
|
+
|
377
|
+
File.delete(file_name)
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
end
|
382
|
+
|
383
|
+
configuration_variable_index = configuration_variable_index.collect{ |element| element[0]}
|
384
|
+
|
385
|
+
configuration_variable_index << configurations.length-1
|
386
|
+
|
387
|
+
modified_configurations = configurations.dup
|
388
|
+
|
389
|
+
for x in 0...configuration_variable_index.length-1
|
390
|
+
|
391
|
+
current_index = configuration_variable_index[x]
|
392
|
+
|
393
|
+
current_variable = configuration_variables[x]
|
394
|
+
|
395
|
+
for y in current_index..configuration_variable_index[x+1]
|
396
|
+
|
397
|
+
modified_configurations[y] = configurations[y].gsub(":v",current_variable)
|
398
|
+
|
399
|
+
end
|
400
|
+
|
401
|
+
end
|
402
|
+
|
403
|
+
configuration_var_values = []
|
404
|
+
|
405
|
+
configuration_variable_index.delete_at(1)
|
406
|
+
|
407
|
+
configuration_variable_index.each do |index|
|
408
|
+
|
409
|
+
var_split = modified_configurations[index].split("=>")
|
410
|
+
|
411
|
+
var_value = var_split[1].lstrip.rstrip
|
412
|
+
|
413
|
+
configuration_var_values << var_value
|
414
|
+
|
415
|
+
end
|
416
|
+
|
417
|
+
configuration_values = Hash[configuration_variables.zip(configuration_var_values)]
|
418
|
+
|
419
|
+
return modified_feature_contents,modified_configurations,configuration_values
|
420
|
+
|
421
|
+
end
|
422
|
+
|
423
|
+
list_of_features = []
|
424
|
+
|
425
|
+
Dir.foreach(@features_directory) { |x| list_of_features << @features_directory+"#{x}" }
|
426
|
+
|
427
|
+
initial_files_list = []
|
428
|
+
|
429
|
+
Dir.foreach(@files_directory) { |x| initial_files_list << @files_directory+"#{x}" }
|
430
|
+
|
431
|
+
list_of_features = list_of_features.reject { |path| !path.include?(".feature")}
|
432
|
+
|
433
|
+
test_results = []
|
434
|
+
|
435
|
+
failed_tests = []
|
436
|
+
|
437
|
+
list_of_features.each do |feature_path|
|
438
|
+
|
439
|
+
feature_contents = read_file_line_by_line(feature_path)
|
440
|
+
|
441
|
+
feature_contents,configurations,config_values = extract_configurations(feature_contents)
|
442
|
+
|
443
|
+
feature_name,scenario_names,scenarios = parse_feature(feature_contents)
|
444
|
+
|
445
|
+
puts feature_name
|
446
|
+
|
447
|
+
scenarios.each_with_index do |scenario,index|
|
448
|
+
|
449
|
+
puts "\n#{scenario_names[index]}"
|
450
|
+
|
451
|
+
scenario[1] = scenario[1].collect{|element| element.sub("input","$input")}
|
452
|
+
|
453
|
+
scenario[1] = scenario[1].collect{|element| element.sub("file","$file")}
|
454
|
+
|
455
|
+
scenario[1] = scenario[1].collect{|element| element.sub("run","$run")}
|
456
|
+
|
457
|
+
scenario[1] = scenario[1].collect{|element| element.sub("output","$output")}
|
458
|
+
|
459
|
+
scenario[1] = scenario[1].collect{|element| element.sub("equal","$equal")}
|
460
|
+
|
461
|
+
output,test_result = parse_and_test_steps(scenario[1],@files_directory,configurations,config_values,@base_path)
|
462
|
+
|
463
|
+
test_results << test_result
|
464
|
+
|
465
|
+
unless test_result
|
466
|
+
|
467
|
+
failed_tests << feature_name
|
468
|
+
|
469
|
+
end
|
470
|
+
|
471
|
+
puts output
|
472
|
+
|
473
|
+
end
|
474
|
+
|
475
|
+
puts "\n"
|
476
|
+
|
477
|
+
end
|
478
|
+
|
479
|
+
puts "Test Statistics:\n\n"
|
480
|
+
|
481
|
+
puts "Total Number of Tests: #{test_results.length}\n"
|
482
|
+
|
483
|
+
puts "Passing: #{test_results.length-failed_tests.length}\n"
|
484
|
+
|
485
|
+
unless failed_tests.empty?
|
486
|
+
|
487
|
+
puts "Failing: #{failed_tests.length}\n"
|
488
|
+
|
489
|
+
puts "The following feature tests failed:\n\n"
|
490
|
+
|
491
|
+
failed_tests.each do |tes|
|
492
|
+
|
493
|
+
puts tes + "\n"
|
494
|
+
|
495
|
+
end
|
496
|
+
|
497
|
+
else
|
498
|
+
|
499
|
+
puts "All of your tests passed!\n"
|
500
|
+
|
501
|
+
end
|
502
|
+
|
503
|
+
after_files_list = []
|
504
|
+
|
505
|
+
Dir.foreach(@files_directory) { |x| after_files_list << @files_directory+"#{x}" }
|
506
|
+
|
507
|
+
reset_test_files_directory(initial_files_list,after_files_list)
|
508
|
+
|
509
|
+
end
|
510
|
+
|
511
|
+
end
|
512
|
+
|
513
|
+
def create_mac_executable(input_file)
|
514
|
+
|
515
|
+
def read_file_line_by_line(input_path)
|
516
|
+
|
517
|
+
file_id = open(input_path)
|
518
|
+
|
519
|
+
file_line_by_line = file_id.readlines()
|
520
|
+
|
521
|
+
file_id.close
|
522
|
+
|
523
|
+
return file_line_by_line
|
524
|
+
|
525
|
+
end
|
526
|
+
|
527
|
+
mac_file_contents = ["#!/usr/bin/env ruby\n\n"] + read_file_line_by_line(input_file)
|
528
|
+
|
529
|
+
mac_file_path = input_file.sub(".rb","")
|
530
|
+
|
531
|
+
file_id = open(mac_file_path,"w")
|
532
|
+
|
533
|
+
file_id.write(mac_file_contents.join)
|
534
|
+
|
535
|
+
file_id.close
|
536
|
+
|
537
|
+
end
|
538
|
+
|
539
|
+
OptionParser.new do |opts|
|
540
|
+
|
541
|
+
opts.banner = "Usage: shark [options]"
|
542
|
+
|
543
|
+
opts.on("-t", "--test", "Start Test") do
|
544
|
+
|
545
|
+
current_directory = Dir.pwd + "/shark/"
|
546
|
+
|
547
|
+
base_path = Dir.pwd
|
548
|
+
|
549
|
+
features_directory = current_directory + "features/"
|
550
|
+
|
551
|
+
test_files_directory = current_directory + "test_files/"
|
552
|
+
|
553
|
+
tester = Shark.new(features_directory, test_files_directory, base_path)
|
554
|
+
|
555
|
+
tester.start_test()
|
556
|
+
|
557
|
+
end
|
558
|
+
|
559
|
+
opts.on("-i","--init","Initialize Shark in this project") do
|
560
|
+
|
561
|
+
FileUtils.mkdir_p "Shark\\features"
|
562
|
+
|
563
|
+
FileUtils.mkdir_p "Shark\\test_files"
|
564
|
+
|
565
|
+
puts "Shark has been successfully initialized!"
|
566
|
+
|
567
|
+
end
|
568
|
+
|
569
|
+
opts.on("-m", "--buildmac", "Builds Mac Executables") do
|
570
|
+
|
571
|
+
file_path = Dir.pwd + "/shark.rb"
|
572
|
+
|
573
|
+
create_mac_executable(file_path)
|
574
|
+
|
575
|
+
puts "Build Successful!"
|
576
|
+
|
577
|
+
end
|
578
|
+
|
543
579
|
end.parse!
|