shark 0.0.0.1

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