packspec 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cli.rb +93 -113
  3. data/packspec.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0531ed015b0fcc81e3aa62bac12011f33b69ce9b
4
- data.tar.gz: cc8de8f4ac4d27cc08b2fa006bce54a6400c918d
3
+ metadata.gz: 9a04e0536fc0d222d75d7644e31fe6e313245a46
4
+ data.tar.gz: 6e51a159a6a8e96b5a49bf91d175422b4c47e54d
5
5
  SHA512:
6
- metadata.gz: e924e041feab6d6b9c1befc1db57246e3597509eebbf8ee09fe3af06a77c461ad2cf05ef8d605a50b7a076e5339cd47f0bc45288ff01129fb1c3c82540bbdc9f
7
- data.tar.gz: a41c8cfd6b471370cba5fe506898ddfdc3fb98c9d8d25243b559be03e023d3fcc8fa6af871d2e647e2d1b6e430b8757ff57fb7f22741a60b47d9f2644493f441
6
+ metadata.gz: 7186eedf6caa1337a6608f9d8d53c8f335814d7058562d7d0d5cd57fd72921386a947ad72ab745397b1cb2e46336a755a1e2fb0f1d3ee2fdef1aa6306cb9b3f0
7
+ data.tar.gz: cf96960d06e597534089e744ea606715c1614d51004ea5c7f28f9976c29bdc83cc6cf79e01019474985b52f0f061391189550c15425e3ff937b3de55197f5c51
data/lib/cli.rb CHANGED
@@ -1,70 +1,36 @@
1
- require 'pp'
2
1
  require 'json'
3
2
  require 'yaml'
4
3
  require 'emoji'
5
4
  require 'colorize'
6
- require 'test/unit'
7
- extend Test::Unit::Assertions
8
5
 
9
6
 
10
7
  # Helpers
11
8
 
12
9
  def parse_specs(path)
13
10
 
14
- # Specs
15
- specmap = {}
16
- for filepath in Dir.glob("#{path}/**/*.yml")
17
- spec = parse_spec(File.read(filepath))
18
- if !spec
19
- next
20
- elsif !specmap.include?(spec['package'])
21
- specmap[spec['package']] = spec
22
- else
23
- specmap[spec['package']]['features'].merge!(spec['features'])
24
- specmap[spec['package']]['scope'].merge!(spec['scope'])
11
+ # Paths
12
+ paths = []
13
+ if !path
14
+ paths = Dir.glob('package.*')
15
+ if paths.empty?
16
+ path = 'packspec'
25
17
  end
26
18
  end
27
-
28
- # Hooks
29
- hookmap = {}
30
- for filepath in Dir.glob("#{path}/**/packspec.rb")
31
- begin
32
- eval(File.read(filepath))
33
- hook_scope = Packspec::User.new()
34
- for name in hook_scope.public_methods
35
- # TODO: filter ruby builtin methods
36
- hookmap["$#{name}"] = hook_scope.public_method(name)
37
- end
38
- rescue Exception
19
+ if File.file?(path)
20
+ paths = [path]
21
+ elsif File.directory?(path)
22
+ for path in Dir.glob("#{path}/*.*")
23
+ paths.push(path)
39
24
  end
40
25
  end
41
26
 
42
- # Result
43
- specs = Array(specmap.sort.to_h.each_value)
44
- for spec in specs
45
- skip = false
46
- spec['ready'] = !spec['scope'].empty?
47
- spec['stats'] = {'features' => 0, 'comments' => 0, 'skipped' => 0, 'tests' => 0}
48
- for feature, index in spec['features'].dup.each_with_index
49
- if feature['assign'] == 'PACKAGE'
50
- if index > 0
51
- spec['features'].delete_at(index)
52
- end
53
- end
54
- spec['stats']['features'] += 1
55
- if feature['comment']
56
- skip = feature['skip']
57
- spec['stats']['comments'] += 1
58
- end
59
- feature['skip'] = skip || feature['skip']
60
- if !feature['comment']
61
- spec['stats']['tests'] += 1
62
- if feature['skip']
63
- spec['stats']['skipped'] += 1
64
- end
65
- end
27
+ # Specs
28
+ specs = []
29
+ for path in paths
30
+ spec = parse_spec(path)
31
+ if spec
32
+ specs.push(spec)
66
33
  end
67
- spec['scope'].merge!(hookmap)
68
34
  end
69
35
 
70
36
  return specs
@@ -72,64 +38,68 @@ def parse_specs(path)
72
38
  end
73
39
 
74
40
 
75
- def parse_spec(spec)
41
+ def parse_spec(path)
42
+
43
+ # Documents
44
+ documents = []
45
+ if !path.end_with?('.yml')
46
+ return nil
47
+ end
48
+ contents = File.read(path)
49
+ YAML.load_stream(contents) do |document|
50
+ documents.push(document)
51
+ end
76
52
 
77
53
  # Package
78
- contents = YAML.load(spec)
79
- begin
80
- feature = parse_feature(contents[0])
81
- package = feature['result']
82
- assert_equal(feature['assign'], 'PACKAGE')
83
- assert_equal(feature['skip'], nil)
84
- if package.is_a?(String)
85
- package = {'default' => [package]}
86
- elsif package.is_a?(Array)
87
- package = {'default' => package}
88
- elsif package.is_a?(Hash)
89
- for key, value in package.each_pair()
90
- package[key] = value.is_a?(Array) ? value : [value]
91
- end
92
- end
93
- rescue Exception
54
+ feature = parse_feature(documents[0][0])
55
+ if feature['skip']
94
56
  return nil
95
57
  end
58
+ package = feature['comment']
96
59
 
97
60
  # Features
61
+ skip = false
98
62
  features = []
99
- for feature in contents
63
+ for feature in documents[0]
100
64
  feature = parse_feature(feature)
101
65
  features.push(feature)
66
+ if feature['comment']
67
+ skip = feature['skip']
68
+ end
69
+ feature['skip'] = skip || feature['skip']
102
70
  end
103
71
 
104
72
  # Scope
105
73
  scope = {}
106
- packages = []
107
- attributes = {}
108
- for namespace, module_names in package.each_pair
109
- packages.push(*module_names)
110
- namespace_scope = scope
111
- if namespace != 'default'
112
- if !scope.key?(namespace) then scope[namespace] = {} end
113
- namespace_scope = scope[namespace]
74
+ scope['$import'] = BuiltinFunctions.new().public_method(:builtin_import)
75
+ if documents.length > 1 && documents[1]['rb']
76
+ eval(documents[1]['rb'])
77
+ hook_scope = Functions.new()
78
+ for name in hook_scope.public_methods
79
+ # TODO: filter ruby builtin methods
80
+ scope["$#{name}"] = hook_scope.public_method(name)
114
81
  end
115
- for module_name in module_names
116
- attributes = get_module_attributes(module_name)
117
- namespace_scope.merge!(attributes)
118
- if !attributes.empty?
119
- break
82
+ end
83
+
84
+ # Stats
85
+ stats = {'features' => 0, 'comments' => 0, 'skipped' => 0, 'tests' => 0}
86
+ for feature in features
87
+ stats['features'] += 1
88
+ if feature['comment']
89
+ stats['comments'] += 1
90
+ else
91
+ stats['tests'] += 1
92
+ if feature['skip']
93
+ stats['skipped'] += 1
120
94
  end
121
95
  end
122
- if attributes.empty?
123
- scope = {}
124
- break
125
- end
126
96
  end
127
- package = packages.sort().join('/')
128
97
 
129
98
  return {
130
99
  'package' => package,
131
100
  'features' => features,
132
101
  'scope' => scope,
102
+ 'stats' => stats,
133
103
  }
134
104
 
135
105
  end
@@ -139,11 +109,10 @@ def parse_feature(feature)
139
109
 
140
110
  # General
141
111
  if feature.is_a?(String)
142
- match = /^(?:(.*):)?(\w.*)$/.match(feature)
112
+ match = /^(?:\((.*)\))?(\w.*)$/.match(feature)
143
113
  skip, comment = match[1], match[2]
144
114
  if !!skip
145
- filters = skip.split(':')
146
- skip = (filters[0] == 'not') == (filters.include?('rb'))
115
+ skip = !skip.split(':').include?('rb')
147
116
  end
148
117
  return {'assign' => nil, 'comment' => comment, 'skip' => skip}
149
118
  end
@@ -151,11 +120,10 @@ def parse_feature(feature)
151
120
 
152
121
  # Left side
153
122
  call = false
154
- match = /^(?:(.*):)?(?:([^=]*)=)?([^=].*)?$/.match(left)
123
+ match = /^(?:\((.*)\))?(?:([^=]*)=)?([^=].*)?$/.match(left)
155
124
  skip, assign, property = match[1], match[2], match[3]
156
125
  if !!skip
157
- filters = skip.split(':')
158
- skip = (filters[0] == 'not') == (filters.include?('rb'))
126
+ skip = !skip.split(':').include?('rb')
159
127
  end
160
128
  if !assign && !property
161
129
  raise Exception.new('Non-valid feature')
@@ -226,21 +194,31 @@ end
226
194
 
227
195
 
228
196
  def test_specs(specs)
229
- success = true
197
+
198
+ # Message
230
199
  message = "\n # Ruby\n".bold
231
200
  puts(message)
201
+
202
+ # Test specs
203
+ success = true
232
204
  for spec in specs
233
205
  spec_success = test_spec(spec)
234
206
  success = success && spec_success
235
207
  end
208
+
236
209
  return success
210
+
237
211
  end
238
212
 
239
213
 
240
214
  def test_spec(spec)
241
- passed = 0
215
+
216
+ # Message
242
217
  message = Emoji.find_by_alias('heavy_minus_sign').raw * 3 + "\n\n"
243
218
  puts(message)
219
+
220
+ # Test spec
221
+ passed = 0
244
222
  for feature in spec['features']
245
223
  result = test_feature(feature, spec['scope'])
246
224
  if result
@@ -248,6 +226,8 @@ def test_spec(spec)
248
226
  end
249
227
  end
250
228
  success = (passed == spec['stats']['features'])
229
+
230
+ # Message
251
231
  color = 'green'
252
232
  message = ("\n " + Emoji.find_by_alias('heavy_check_mark').raw + ' ').green.bold
253
233
  if !success
@@ -256,7 +236,9 @@ def test_spec(spec)
256
236
  end
257
237
  message += "#{spec['package']}: #{passed - spec['stats']['comments'] - spec['stats']['skipped']}/#{spec['stats']['tests'] - spec['stats']['skipped']}\n".colorize(color).bold
258
238
  puts(message)
239
+
259
240
  return success
241
+
260
242
  end
261
243
 
262
244
 
@@ -358,26 +340,24 @@ def test_feature(feature, scope)
358
340
  end
359
341
 
360
342
 
361
- def get_module_attributes(module_name)
362
- attributes = {}
363
- begin
364
- require(module_name)
365
- rescue Exception
366
- return {}
367
- end
368
- for item in ObjectSpace.each_object
369
- if module_name == String(item).downcase
370
- begin
371
- module_scope = Kernel.const_get(item)
372
- rescue Exception
373
- next
374
- end
375
- for name in module_scope.constants
376
- attributes[String(name)] = module_scope.const_get(name)
343
+ class BuiltinFunctions
344
+ def builtin_import(package)
345
+ attributes = {}
346
+ require(package)
347
+ for item in ObjectSpace.each_object
348
+ if package == String(item).downcase
349
+ begin
350
+ scope = Kernel.const_get(item)
351
+ rescue Exception
352
+ next
353
+ end
354
+ for name in scope.constants
355
+ attributes[String(name)] = scope.const_get(name)
356
+ end
377
357
  end
378
358
  end
359
+ return attributes
379
360
  end
380
- return attributes
381
361
  end
382
362
 
383
363
 
@@ -428,7 +408,7 @@ end
428
408
 
429
409
  # Main program
430
410
 
431
- path = ARGV[0] || '.'
411
+ path = ARGV[0] || nil
432
412
  specs = parse_specs(path)
433
413
  success = test_specs(specs)
434
414
  if !success
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "packspec"
7
- spec.version = "0.1.5"
7
+ spec.version = "0.1.6"
8
8
  spec.authors = ["Evgeny Karev\n"]
9
9
  spec.email = ["eskarev@gmail.com"]
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - |
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-13 00:00:00.000000000 Z
12
+ date: 2017-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler