packspec 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cli.rb +93 -113
- data/packspec.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a04e0536fc0d222d75d7644e31fe6e313245a46
|
4
|
+
data.tar.gz: 6e51a159a6a8e96b5a49bf91d175422b4c47e54d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if
|
19
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
#
|
43
|
-
specs =
|
44
|
-
for
|
45
|
-
|
46
|
-
|
47
|
-
|
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(
|
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
|
-
|
79
|
-
|
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
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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 = /^(
|
112
|
+
match = /^(?:\((.*)\))?(\w.*)$/.match(feature)
|
143
113
|
skip, comment = match[1], match[2]
|
144
114
|
if !!skip
|
145
|
-
|
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 = /^(
|
123
|
+
match = /^(?:\((.*)\))?(?:([^=]*)=)?([^=].*)?$/.match(left)
|
155
124
|
skip, assign, property = match[1], match[2], match[3]
|
156
125
|
if !!skip
|
157
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
362
|
-
|
363
|
-
|
364
|
-
require(
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
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
|
data/packspec.gemspec
CHANGED
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.
|
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-
|
12
|
+
date: 2017-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|