shark 0.0.0.4 → 0.0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,17 +1,17 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in shark.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shark.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -1,29 +1,29 @@
1
- # Shark
2
-
3
- Shark is a simple testing tool for file operations.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'shark'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install shark
18
-
19
- ## Usage
20
-
21
- It has a cucumber like syntax and is intended to be used to test file operations.
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
1
+ # Shark
2
+
3
+ Shark is a simple testing tool for file operations.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'shark'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install shark
18
+
19
+ ## Usage
20
+
21
+ It has a cucumber like syntax and is intended to be used to test file operations.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
data/bin/Shark CHANGED
@@ -112,15 +112,19 @@ class Shark
112
112
 
113
113
  modified_scenarios = scenarios.dup
114
114
 
115
+ scenario_names = []
116
+
115
117
  scenarios.each_with_index do |s,index|
116
118
 
117
119
  scenario_steps = s[0].split(" ")[1..-1]
118
120
 
121
+ scenario_names << s[0].split(" ")[0]
122
+
119
123
  modified_scenarios[index] << scenario_steps
120
124
 
121
125
  end
122
126
 
123
- return feature_name,modified_scenarios
127
+ return feature_name,scenario_names,modified_scenarios
124
128
 
125
129
  end
126
130
 
@@ -418,11 +422,13 @@ class Shark
418
422
 
419
423
  feature_contents,configurations,config_values = extract_configurations(feature_contents)
420
424
 
421
- feature_name,scenarios = parse_feature(feature_contents)
425
+ feature_name,scenario_names,scenarios = parse_feature(feature_contents)
422
426
 
423
427
  puts feature_name
424
428
 
425
- scenarios.each do |scenario|
429
+ scenarios.each_with_index do |scenario,index|
430
+
431
+ puts "\n#{scenario_names[index]}"
426
432
 
427
433
  scenario[1] = scenario[1].collect{|element| element.sub("input","$input")}
428
434
 
@@ -436,10 +442,12 @@ class Shark
436
442
 
437
443
  output = parse_and_test_steps(scenario[1],@files_directory,configurations,config_values,@base_path)
438
444
 
439
- puts output + "\n\n"
445
+ puts output
440
446
 
441
447
  end
442
448
 
449
+ puts "\n"
450
+
443
451
  end
444
452
 
445
453
  end
data/lib/shark/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Shark
2
- VERSION = "0.0.0.4"
3
- end
1
+ module Shark
2
+ VERSION = "0.0.0.5"
3
+ end
data/lib/shark.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "shark/version"
2
-
3
- module Shark
4
- # Your code goes here...
5
- end
1
+ require "shark/version"
2
+
3
+ module Shark
4
+ # Your code goes here...
5
+ end
data/shark.gemspec CHANGED
@@ -1,23 +1,23 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'shark/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "shark"
8
- spec.version = Shark::VERSION
9
- spec.authors = ["Adhithya Rajasekaran"]
10
- spec.email = ["adhithyan15@gmail.com"]
11
- spec.description = %q{Shark is a simple testing tool}
12
- spec.summary = %q{Shark is a testing tool focused on testing file operations}
13
- spec.homepage = "http://adhithyan15.github.io/shark"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shark/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shark"
8
+ spec.version = Shark::VERSION
9
+ spec.authors = ["Adhithya Rajasekaran"]
10
+ spec.email = ["adhithyan15@gmail.com"]
11
+ spec.description = %q{Shark is a simple testing tool}
12
+ spec.summary = %q{Shark is a testing tool focused on testing file operations}
13
+ spec.homepage = "http://adhithyan15.github.io/shark"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/src/shark ADDED
@@ -0,0 +1,523 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #Shark is a simple testing tool for testing file system operations. It is still under development
4
+
5
+ require 'optparse'
6
+ require 'fileutils'
7
+
8
+ class Shark
9
+
10
+ def initialize(a1,a2,a3)
11
+
12
+ @features_directory = a1
13
+
14
+ @files_directory = a2
15
+
16
+ @base_path = a3
17
+
18
+ end
19
+
20
+ def start_test
21
+
22
+ def read_file_line_by_line(input_path)
23
+
24
+ file_id = open(input_path)
25
+
26
+ file_line_by_line = file_id.readlines()
27
+
28
+ file_id.close
29
+
30
+ return file_line_by_line
31
+
32
+ end
33
+
34
+ def find_file_name(input_path, file_extension)
35
+
36
+ extension_remover = input_path.split(file_extension)
37
+
38
+ remaining_string = extension_remover[0].reverse
39
+
40
+ path_finder = remaining_string.index("/")
41
+
42
+ remaining_string = remaining_string.reverse
43
+
44
+ return remaining_string[remaining_string.length-path_finder..-1]
45
+
46
+ end
47
+
48
+ def parse_feature(input_feature_contents)
49
+
50
+ #This method extracts scenarios from a feature file
51
+
52
+ #Input:
53
+ #input_feature_contents => An array containing the contents of a feature file
54
+
55
+ #Output:
56
+ #feature_name => Name and description of the feature described in the file
57
+ #modified_scenarios => An array containing scenario descriptions and scenario steps
58
+
59
+ def find_all_matching_indices(input_string,pattern)
60
+
61
+ locations = []
62
+
63
+ index = input_string.index(pattern)
64
+
65
+ while index != nil
66
+
67
+ locations << index
68
+
69
+ index = input_string.index(pattern,index+1)
70
+
71
+
72
+ end
73
+
74
+ return locations
75
+
76
+
77
+ end
78
+
79
+ while input_feature_contents[0].eql?("\n")
80
+
81
+ input_feature_contents.delete_at(0)
82
+
83
+ end
84
+
85
+ feature_contents_string = input_feature_contents.join
86
+
87
+ feature_name = ""
88
+
89
+ if feature_contents_string.include?("Scenario:")
90
+
91
+ feature_name = feature_contents_string[feature_contents_string.index("Feature:")...feature_contents_string.index("Scenario:")].rstrip
92
+
93
+ else
94
+
95
+ feature_name = feature_contents_string.rstrip
96
+
97
+ end
98
+
99
+ scenarios = []
100
+
101
+ scenarios_index = find_all_matching_indices(feature_contents_string,"Scenario:")
102
+
103
+ scenarios_index << -1
104
+
105
+ for x in 0...scenarios_index.length-1
106
+
107
+ scenario = feature_contents_string[scenarios_index[x]...scenarios_index[x+1]]
108
+
109
+ scenarios << [scenario.lstrip]
110
+
111
+ end
112
+
113
+ modified_scenarios = scenarios.dup
114
+
115
+ scenario_names = []
116
+
117
+ scenarios.each_with_index do |s,index|
118
+
119
+ scenario_steps = s[0].split(" ")[1..-1]
120
+
121
+ scenario_names << s[0].split(" ")[0]
122
+
123
+ modified_scenarios[index] << scenario_steps
124
+
125
+ end
126
+
127
+ return feature_name,scenario_names,modified_scenarios
128
+
129
+ end
130
+
131
+ def parse_and_test_steps(input_steps,test_files_directory,configuration,config_variables,base_path)
132
+
133
+ #This method parses the steps for a given scenario and produces a result using the following keywords
134
+
135
+ #Keywords
136
+
137
+ #Input
138
+ #File
139
+ #When
140
+ #Run
141
+ #Output
142
+ #Equal
143
+
144
+ #Input:
145
+ #input_steps => An array containing the steps
146
+
147
+ #Output:
148
+ #test_result => A string and a boolean containing the results of the test
149
+
150
+ def read_file_line_by_line(input_path)
151
+
152
+ file_id = open(input_path)
153
+
154
+ file_line_by_line = file_id.readlines()
155
+
156
+ file_id.close
157
+
158
+ return file_line_by_line
159
+
160
+ end
161
+
162
+ input_procedures = input_steps.reject {|element| !element.include?("$input")}
163
+
164
+ input_file_names = []
165
+
166
+ input_procedures.each do |procedure|
167
+
168
+ if procedure.include? "$file"
169
+
170
+ opening_quotes = procedure.index("\"")
171
+
172
+ file_name = procedure[opening_quotes...procedure.index("\"",opening_quotes+1)]
173
+
174
+ input_file_names << file_name
175
+
176
+ end
177
+
178
+ end
179
+
180
+ input_file_contents = input_steps.dup
181
+
182
+ test_files_directory = test_files_directory.sub(Dir.pwd,"").sub("/","")
183
+
184
+ input_file_names = input_file_names.collect{|element| test_files_directory+element[1..-1]}
185
+
186
+ run_procedures = input_file_contents.reject{ |element| !element.include?("$run")}
187
+
188
+ run_keywords = ["$cliusage"]
189
+
190
+ configuration_vars = config_variables.keys
191
+
192
+ modified_keyword_usage = nil
193
+
194
+ executable_statements = [[]]*configuration_vars.length
195
+
196
+ run_keywords.each do |keyword|
197
+
198
+ keyword_usage = configuration.reject { |element| !element.include?(keyword)}
199
+
200
+ modified_keyword_usage = keyword_usage.dup
201
+
202
+ keyword_usage.each_with_index do |line,index|
203
+
204
+ configuration_vars.each_with_index do |var,var_index|
205
+
206
+ modified_keyword_usage[index] = modified_keyword_usage[index].gsub(var,"#{config_variables[var]}")
207
+
208
+ statement_split = modified_keyword_usage[index].split("=>")
209
+
210
+ executable_statements[var_index] << statement_split[1].lstrip.rstrip
211
+
212
+ end
213
+
214
+ end
215
+
216
+ end
217
+
218
+ configuration_vars.each_with_index do |var,index|
219
+
220
+ current_var_run_procedures = run_procedures.reject{|element| !element.include?(var)}
221
+
222
+ current_var_run_procedures.each do |run|
223
+
224
+ current_executable_statements = executable_statements[index]
225
+
226
+ current_executable_statements.each do |executable|
227
+
228
+ input_file_names.each do |file_name|
229
+
230
+ current_executable_statement = executable.gsub("$file",file_name)
231
+
232
+ cli_output = `#{current_executable_statement.strip.lstrip.rstrip}`
233
+
234
+ end
235
+
236
+ end
237
+
238
+ end
239
+
240
+
241
+ end
242
+
243
+ output_procedures = input_steps.reject {|element| !element.include?("$output")}
244
+
245
+ matching_file_names = []
246
+
247
+ output_file_names = []
248
+
249
+ output_procedures.each do |procedure|
250
+
251
+ if procedure.include?("$equal") and procedure.include?("$file")
252
+
253
+ opening_quotes = procedure.index("\"")
254
+
255
+ file_name = procedure[opening_quotes...procedure.index("\"",opening_quotes+1)]
256
+
257
+ matching_file_names << file_name
258
+
259
+ else
260
+
261
+ opening_quotes = procedure.index("\"")
262
+
263
+ file_name = procedure[opening_quotes...procedure.index("\"",opening_quotes+1)]
264
+
265
+ output_file_names << file_name
266
+
267
+ end
268
+
269
+ end
270
+
271
+ output_file_names = output_file_names.collect {|element| test_files_directory + element[1..-1]}
272
+
273
+ matching_file_names = matching_file_names.collect {|element| test_files_directory+element[1..-1]}
274
+
275
+ output_file_contents = output_file_names.collect{ |element| read_file_line_by_line(element)}
276
+
277
+ matching_file_contents = matching_file_names.collect{ |element| read_file_line_by_line(element)}
278
+
279
+ test_results = []
280
+
281
+ false_results = []
282
+
283
+ matching_file_contents.each_with_index do |matching_file,matching_index|
284
+
285
+ false_results << [matching_file_names[matching_index]]
286
+
287
+ output_file_contents.each_with_index do |output_file,index|
288
+
289
+ if matching_file.eql?(output_file)
290
+
291
+ test_results << true
292
+
293
+ else
294
+
295
+ test_results << false
296
+
297
+ false_results[-1] << [output_file_names[index]]
298
+
299
+ end
300
+
301
+ end
302
+
303
+ end
304
+
305
+ if test_results.include?(false)
306
+
307
+ output_string = "\nThe test failed!\n\nA detailed breakdown of the failing files have been given below."
308
+
309
+ output_string = output_string + "\n\n"
310
+
311
+ detailed_fail_list = ""
312
+
313
+ false_results.each do |result|
314
+
315
+ detailed_fail_list = detailed_fail_list + "The following files failed in comparison with #{result[0]}"
316
+
317
+ failed_files = result[1]
318
+
319
+ failed_files.each do |file|
320
+
321
+ detailed_fail_list = detailed_fail_list + "\n\n" + "* #{file}\n"
322
+
323
+ end
324
+
325
+ end
326
+
327
+ return output_string = output_string + detailed_fail_list
328
+
329
+ else
330
+
331
+ return "\nYour test file(s) passed the feature test.\n\n"
332
+
333
+ end
334
+
335
+ end
336
+
337
+ def extract_configurations(feature_contents)
338
+
339
+ config_start_index = 0
340
+
341
+ feature_contents.each_with_index do |line,index|
342
+
343
+ if line.include?("Configurations:")
344
+
345
+ config_start_index = index
346
+
347
+ end
348
+
349
+ end
350
+
351
+ modified_feature_contents = feature_contents[0...config_start_index]
352
+
353
+ configurations = feature_contents[config_start_index..-1]
354
+
355
+ configuration_variables = configurations.join.match(/~\w{1,}/).to_a
356
+
357
+ configuration_variable_index = [[]]*configuration_variables.length
358
+
359
+ configurations.each_with_index do |line,index|
360
+
361
+ configuration_variables.each_with_index do |variable,var_index|
362
+
363
+ if line.include?(variable)
364
+
365
+ configuration_variable_index[var_index] << index
366
+
367
+ end
368
+
369
+ end
370
+
371
+ end
372
+
373
+ configuration_variable_index = configuration_variable_index.collect{ |element| element[0]}
374
+
375
+ configuration_variable_index << configurations.length-1
376
+
377
+ modified_configurations = configurations.dup
378
+
379
+ for x in 0...configuration_variable_index.length-1
380
+
381
+ current_index = configuration_variable_index[x]
382
+
383
+ current_variable = configuration_variables[x]
384
+
385
+ for y in current_index..configuration_variable_index[x+1]
386
+
387
+ modified_configurations[y] = configurations[y].gsub(":v",current_variable)
388
+
389
+ end
390
+
391
+ end
392
+
393
+ configuration_var_values = []
394
+
395
+ configuration_variable_index.delete_at(1)
396
+
397
+ configuration_variable_index.each do |index|
398
+
399
+ var_split = modified_configurations[index].split("=>")
400
+
401
+ var_value = var_split[1].lstrip.rstrip
402
+
403
+ configuration_var_values << var_value
404
+
405
+ end
406
+
407
+ configuration_values = Hash[configuration_variables.zip(configuration_var_values)]
408
+
409
+ return modified_feature_contents,modified_configurations,configuration_values
410
+
411
+ end
412
+
413
+ list_of_features = []
414
+
415
+ Dir.foreach(@features_directory) { |x| list_of_features << @features_directory+"#{x}" }
416
+
417
+ list_of_features.delete_at(0); list_of_features.delete_at(0)
418
+
419
+ list_of_features.each do |feature_path|
420
+
421
+ feature_contents = read_file_line_by_line(feature_path)
422
+
423
+ feature_contents,configurations,config_values = extract_configurations(feature_contents)
424
+
425
+ feature_name,scenario_names,scenarios = parse_feature(feature_contents)
426
+
427
+ puts feature_name
428
+
429
+ scenarios.each_with_index do |scenario,index|
430
+
431
+ puts "\n#{scenario_names[index]}"
432
+
433
+ scenario[1] = scenario[1].collect{|element| element.sub("input","$input")}
434
+
435
+ scenario[1] = scenario[1].collect{|element| element.sub("file","$file")}
436
+
437
+ scenario[1] = scenario[1].collect{|element| element.sub("run","$run")}
438
+
439
+ scenario[1] = scenario[1].collect{|element| element.sub("output","$output")}
440
+
441
+ scenario[1] = scenario[1].collect{|element| element.sub("equal","$equal")}
442
+
443
+ output = parse_and_test_steps(scenario[1],@files_directory,configurations,config_values,@base_path)
444
+
445
+ puts output
446
+
447
+ end
448
+
449
+ puts "\n"
450
+
451
+ end
452
+
453
+ end
454
+
455
+ end
456
+
457
+ def create_mac_executable(input_file)
458
+
459
+ def read_file_line_by_line(input_path)
460
+
461
+ file_id = open(input_path)
462
+
463
+ file_line_by_line = file_id.readlines()
464
+
465
+ file_id.close
466
+
467
+ return file_line_by_line
468
+
469
+ end
470
+
471
+ mac_file_contents = ["#!/usr/bin/env ruby\n\n"] + read_file_line_by_line(input_file)
472
+
473
+ mac_file_path = input_file.sub(".rb","")
474
+
475
+ file_id = open(mac_file_path,"w")
476
+
477
+ file_id.write(mac_file_contents.join)
478
+
479
+ file_id.close
480
+
481
+ end
482
+
483
+ OptionParser.new do |opts|
484
+
485
+ opts.banner = "Usage: shark [options]"
486
+
487
+ opts.on("-t", "--test", "Start Test") do
488
+
489
+ current_directory = Dir.pwd + "/shark/"
490
+
491
+ base_path = Dir.pwd
492
+
493
+ features_directory = current_directory + "features/"
494
+
495
+ test_files_directory = current_directory + "test_files/"
496
+
497
+ tester = Shark.new(features_directory, test_files_directory, base_path)
498
+
499
+ tester.start_test()
500
+
501
+ end
502
+
503
+ opts.on("-i","--init","Initialize Shark in this project") do
504
+
505
+ FileUtils.mkdir_p "Shark\\features"
506
+
507
+ FileUtils.mkdir_p "Shark\\test_files"
508
+
509
+ puts "Shark has been successfully initialized!"
510
+
511
+ end
512
+
513
+ opts.on("-m", "--buildmac", "Builds Mac Executables") do
514
+
515
+ file_path = Dir.pwd + "/shark.rb"
516
+
517
+ create_mac_executable(file_path)
518
+
519
+ puts "Build Successful!"
520
+
521
+ end
522
+
523
+ end.parse!
data/src/shark.rb ADDED
@@ -0,0 +1,521 @@
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
+ configuration_variable_index = configuration_variable_index.collect{ |element| element[0]}
372
+
373
+ configuration_variable_index << configurations.length-1
374
+
375
+ modified_configurations = configurations.dup
376
+
377
+ for x in 0...configuration_variable_index.length-1
378
+
379
+ current_index = configuration_variable_index[x]
380
+
381
+ current_variable = configuration_variables[x]
382
+
383
+ for y in current_index..configuration_variable_index[x+1]
384
+
385
+ modified_configurations[y] = configurations[y].gsub(":v",current_variable)
386
+
387
+ end
388
+
389
+ end
390
+
391
+ configuration_var_values = []
392
+
393
+ configuration_variable_index.delete_at(1)
394
+
395
+ configuration_variable_index.each do |index|
396
+
397
+ var_split = modified_configurations[index].split("=>")
398
+
399
+ var_value = var_split[1].lstrip.rstrip
400
+
401
+ configuration_var_values << var_value
402
+
403
+ end
404
+
405
+ configuration_values = Hash[configuration_variables.zip(configuration_var_values)]
406
+
407
+ return modified_feature_contents,modified_configurations,configuration_values
408
+
409
+ end
410
+
411
+ list_of_features = []
412
+
413
+ Dir.foreach(@features_directory) { |x| list_of_features << @features_directory+"#{x}" }
414
+
415
+ list_of_features.delete_at(0); list_of_features.delete_at(0)
416
+
417
+ list_of_features.each do |feature_path|
418
+
419
+ feature_contents = read_file_line_by_line(feature_path)
420
+
421
+ feature_contents,configurations,config_values = extract_configurations(feature_contents)
422
+
423
+ feature_name,scenario_names,scenarios = parse_feature(feature_contents)
424
+
425
+ puts feature_name
426
+
427
+ scenarios.each_with_index do |scenario,index|
428
+
429
+ puts "\n#{scenario_names[index]}"
430
+
431
+ scenario[1] = scenario[1].collect{|element| element.sub("input","$input")}
432
+
433
+ scenario[1] = scenario[1].collect{|element| element.sub("file","$file")}
434
+
435
+ scenario[1] = scenario[1].collect{|element| element.sub("run","$run")}
436
+
437
+ scenario[1] = scenario[1].collect{|element| element.sub("output","$output")}
438
+
439
+ scenario[1] = scenario[1].collect{|element| element.sub("equal","$equal")}
440
+
441
+ output = parse_and_test_steps(scenario[1],@files_directory,configurations,config_values,@base_path)
442
+
443
+ puts output
444
+
445
+ end
446
+
447
+ puts "\n"
448
+
449
+ end
450
+
451
+ end
452
+
453
+ end
454
+
455
+ def create_mac_executable(input_file)
456
+
457
+ def read_file_line_by_line(input_path)
458
+
459
+ file_id = open(input_path)
460
+
461
+ file_line_by_line = file_id.readlines()
462
+
463
+ file_id.close
464
+
465
+ return file_line_by_line
466
+
467
+ end
468
+
469
+ mac_file_contents = ["#!/usr/bin/env ruby\n\n"] + read_file_line_by_line(input_file)
470
+
471
+ mac_file_path = input_file.sub(".rb","")
472
+
473
+ file_id = open(mac_file_path,"w")
474
+
475
+ file_id.write(mac_file_contents.join)
476
+
477
+ file_id.close
478
+
479
+ end
480
+
481
+ OptionParser.new do |opts|
482
+
483
+ opts.banner = "Usage: shark [options]"
484
+
485
+ opts.on("-t", "--test", "Start Test") do
486
+
487
+ current_directory = Dir.pwd + "/shark/"
488
+
489
+ base_path = Dir.pwd
490
+
491
+ features_directory = current_directory + "features/"
492
+
493
+ test_files_directory = current_directory + "test_files/"
494
+
495
+ tester = Shark.new(features_directory, test_files_directory, base_path)
496
+
497
+ tester.start_test()
498
+
499
+ end
500
+
501
+ opts.on("-i","--init","Initialize Shark in this project") do
502
+
503
+ FileUtils.mkdir_p "Shark\\features"
504
+
505
+ FileUtils.mkdir_p "Shark\\test_files"
506
+
507
+ puts "Shark has been successfully initialized!"
508
+
509
+ end
510
+
511
+ opts.on("-m", "--buildmac", "Builds Mac Executables") do
512
+
513
+ file_path = Dir.pwd + "/shark.rb"
514
+
515
+ create_mac_executable(file_path)
516
+
517
+ puts "Build Successful!"
518
+
519
+ end
520
+
521
+ end.parse!
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.4
4
+ version: 0.0.0.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Adhithya Rajasekaran
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-06-14 00:00:00.000000000 Z
12
+ date: 2013-06-23 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,15 +30,17 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  description: Shark is a simple testing tool
@@ -56,29 +61,31 @@ files:
56
61
  - lib/shark.rb
57
62
  - lib/shark/version.rb
58
63
  - shark.gemspec
64
+ - src/shark
65
+ - src/shark.rb
59
66
  homepage: http://adhithyan15.github.io/shark
60
67
  licenses:
61
68
  - MIT
62
- metadata: {}
63
69
  post_install_message:
64
70
  rdoc_options: []
65
71
  require_paths:
66
72
  - lib
67
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
68
75
  requirements:
69
- - - '>='
76
+ - - ! '>='
70
77
  - !ruby/object:Gem::Version
71
78
  version: '0'
72
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
73
81
  requirements:
74
- - - '>='
82
+ - - ! '>='
75
83
  - !ruby/object:Gem::Version
76
84
  version: '0'
77
85
  requirements: []
78
86
  rubyforge_project:
79
- rubygems_version: 2.0.2
87
+ rubygems_version: 1.8.24
80
88
  signing_key:
81
- specification_version: 4
89
+ specification_version: 3
82
90
  summary: Shark is a testing tool focused on testing file operations
83
91
  test_files: []
84
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: c0239ec5e56ea07ae039258c1ad4a3ccede47dfa
4
- data.tar.gz: 2e5e865dc9a324b91b52a89d810d56f6f11799af
5
- SHA512:
6
- metadata.gz: 0d69b01d69a848275c6ced2fcc3cb3976c01436e66836d1deb539f846a1ecf028319834c34cf1f104cf54e94ecbd85c11e2b3c92c95d218698bff8b626ab6cba
7
- data.tar.gz: 9f41b26e02fb52560f453615599c5567e5c1e0b22396a48a0a707c3c836728bd296c81380e20220dcf947e76463985ac8e600f62289891603036ac97c15aaca0