atp 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a0d850eca7f69b2f9c49af6e1192fc97d248cb8
4
- data.tar.gz: fcf7c3fa24bcca9d19eb3d590d68f6acef66ac83
3
+ metadata.gz: 30f27f563d7be5bb5ac2fdadeb075aff8254e631
4
+ data.tar.gz: 116ddc493b873bb4680a559e488de2e65cb62698
5
5
  SHA512:
6
- metadata.gz: 7b2cf5e3e8b7252884cdb9f45ef8cd57374b1eda91e1559f19f5303c10ccfb6c16b35fdf38a2fd5d7ca58a124034b6551964e59937227398ec67710125c9ab8d
7
- data.tar.gz: 88d0018049a88372325e2acbbec0fd729f872c70500ae15208001321da2504404814d5401886e8752d5ed8f3dc2cb50d6fb97bf63293697b9df986325cf3241f
6
+ metadata.gz: 1183ef2bc0e85b638c5d50c75b2dd9f433017ea71cdef4c92d7eadaf084d361448b3e36ba91fb674a1a145a1ca80e85bfaeec4d5be291b7cada572699813db15
7
+ data.tar.gz: b4b41aca1916c7053bc91b5851caf18d4a47aeba3e25e0c794d6f79b9c45d5cf52db9ac75e2ba223bb73d844074cbdd13c24a7f8f6effbb355745daf81a5af6a
@@ -1,7 +1,7 @@
1
1
  module ATP
2
2
  MAJOR = 1
3
3
  MINOR = 1
4
- BUGFIX = 0
4
+ BUGFIX = 1
5
5
  DEV = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, BUGFIX].join(".") + (DEV ? ".pre#{DEV}" : '')
@@ -77,9 +77,19 @@ module ATP
77
77
  children.find { |c| types.include?(c.try(:type)) }
78
78
  end
79
79
 
80
- # Returns an array containing all child nodes of the given type(s)
80
+ # Returns an array containing all child nodes of the given type(s), by default only considering
81
+ # the immediate children of the node on which this was called.
82
+ #
83
+ # To find all children of the given type by recursively searching through all child nodes, pass
84
+ # recursive: true when calling this method.
81
85
  def find_all(*types)
82
- children.select { |c| types.include?(c.try(:type)) }
86
+ options = types.pop if types.last.is_a?(Hash)
87
+ options ||= {}
88
+ if options[:recursive]
89
+ Extractor.new.process(self, types)
90
+ else
91
+ children.select { |c| types.include?(c.try(:type)) }
92
+ end
83
93
  end
84
94
 
85
95
  # Returns an array containing all flags which are set within the given node
@@ -4,8 +4,6 @@ module ATP
4
4
  class Flow
5
5
  attr_reader :program, :name
6
6
 
7
- attr_accessor :source_file, :source_line_number, :description
8
-
9
7
  CONDITION_KEYS = {
10
8
  if_enabled: :if_enabled,
11
9
  if_enable: :if_enabled,
@@ -64,10 +62,14 @@ module ATP
64
62
 
65
63
  def initialize(program, name = nil, options = {})
66
64
  name, options = nil, name if name.is_a?(Hash)
67
- extract_meta!(options)
65
+ @source_file = []
66
+ @source_line_number = []
67
+ @description = []
68
68
  @program = program
69
69
  @name = name
70
- @pipeline = [n1(:flow, n1(:name, name))]
70
+ extract_meta!(options) do
71
+ @pipeline = [n1(:flow, n1(:name, name))]
72
+ end
71
73
  end
72
74
 
73
75
  # @api private
@@ -213,14 +215,15 @@ module ATP
213
215
  # flow.test ...
214
216
  # end
215
217
  def group(name, options = {})
216
- extract_meta!(options)
217
- apply_conditions(options) do
218
- children = [n1(:name, name)]
219
- children << id(options[:id]) if options[:id]
220
- children << on_fail(options[:on_fail]) if options[:on_fail]
221
- children << on_pass(options[:on_pass]) if options[:on_pass]
222
- g = n(:group, children)
223
- append_to(g) { yield }
218
+ extract_meta!(options) do
219
+ apply_conditions(options) do
220
+ children = [n1(:name, name)]
221
+ children << id(options[:id]) if options[:id]
222
+ children << on_fail(options[:on_fail]) if options[:on_fail]
223
+ children << on_pass(options[:on_pass]) if options[:on_pass]
224
+ g = n(:group, children)
225
+ append_to(g) { yield }
226
+ end
224
227
  end
225
228
  end
226
229
 
@@ -234,130 +237,131 @@ module ATP
234
237
  # @option options [Hash] :on_pass What action to take if the test passes
235
238
  # @option options [Hash] :conditions What conditions must be met to execute the test
236
239
  def test(instance, options = {})
237
- extract_meta!(options)
238
- apply_conditions(options) do
239
- # Allows any continue, bin, or soft bin argument passed in at the options top-level to be assumed
240
- # to be the action to take if the test fails
241
- if b = options.delete(:bin)
242
- options[:on_fail] ||= {}
243
- options[:on_fail][:bin] = b
244
- end
245
- if b = options.delete(:bin_description)
246
- options[:on_fail] ||= {}
247
- options[:on_fail][:bin_description] = b
248
- end
249
- if b = options.delete(:softbin) || b = options.delete(:sbin) || b = options.delete(:soft_bin)
250
- options[:on_fail] ||= {}
251
- options[:on_fail][:softbin] = b
252
- end
253
- if b = options.delete(:softbin_description) || options.delete(:sbin_description) || options.delete(:soft_bin_description)
254
- options[:on_fail] ||= {}
255
- options[:on_fail][:softbin_description] = b
256
- end
257
- if options.delete(:continue)
258
- options[:on_fail] ||= {}
259
- options[:on_fail][:continue] = true
260
- end
261
- if options.key?(:delayed)
262
- options[:on_fail] ||= {}
263
- options[:on_fail][:delayed] = options.delete(:delayed)
264
- end
265
- if f = options.delete(:flag_pass)
266
- options[:on_pass] ||= {}
267
- options[:on_pass][:set_flag] = f
268
- end
269
- if f = options.delete(:flag_fail)
270
- options[:on_fail] ||= {}
271
- options[:on_fail][:set_flag] = f
272
- end
240
+ extract_meta!(options) do
241
+ apply_conditions(options) do
242
+ # Allows any continue, bin, or soft bin argument passed in at the options top-level to be assumed
243
+ # to be the action to take if the test fails
244
+ if b = options.delete(:bin)
245
+ options[:on_fail] ||= {}
246
+ options[:on_fail][:bin] = b
247
+ end
248
+ if b = options.delete(:bin_description)
249
+ options[:on_fail] ||= {}
250
+ options[:on_fail][:bin_description] = b
251
+ end
252
+ if b = options.delete(:softbin) || b = options.delete(:sbin) || b = options.delete(:soft_bin)
253
+ options[:on_fail] ||= {}
254
+ options[:on_fail][:softbin] = b
255
+ end
256
+ if b = options.delete(:softbin_description) || options.delete(:sbin_description) || options.delete(:soft_bin_description)
257
+ options[:on_fail] ||= {}
258
+ options[:on_fail][:softbin_description] = b
259
+ end
260
+ if options.delete(:continue)
261
+ options[:on_fail] ||= {}
262
+ options[:on_fail][:continue] = true
263
+ end
264
+ if options.key?(:delayed)
265
+ options[:on_fail] ||= {}
266
+ options[:on_fail][:delayed] = options.delete(:delayed)
267
+ end
268
+ if f = options.delete(:flag_pass)
269
+ options[:on_pass] ||= {}
270
+ options[:on_pass][:set_flag] = f
271
+ end
272
+ if f = options.delete(:flag_fail)
273
+ options[:on_fail] ||= {}
274
+ options[:on_fail][:set_flag] = f
275
+ end
273
276
 
274
- children = [n1(:object, instance)]
277
+ children = [n1(:object, instance)]
275
278
 
276
- name = (options[:name] || options[:tname] || options[:test_name])
277
- unless name
278
- [:name, :tname, :test_name].each do |m|
279
- name ||= instance.respond_to?(m) ? instance.send(m) : nil
279
+ name = (options[:name] || options[:tname] || options[:test_name])
280
+ unless name
281
+ [:name, :tname, :test_name].each do |m|
282
+ name ||= instance.respond_to?(m) ? instance.send(m) : nil
283
+ end
280
284
  end
281
- end
282
- children << n1(:name, name) if name
285
+ children << n1(:name, name) if name
283
286
 
284
- num = (options[:number] || options[:num] || options[:tnum] || options[:test_number])
285
- unless num
286
- [:number, :num, :tnum, :test_number].each do |m|
287
- num ||= instance.respond_to?(m) ? instance.send(m) : nil
287
+ num = (options[:number] || options[:num] || options[:tnum] || options[:test_number])
288
+ unless num
289
+ [:number, :num, :tnum, :test_number].each do |m|
290
+ num ||= instance.respond_to?(m) ? instance.send(m) : nil
291
+ end
288
292
  end
289
- end
290
- children << number(num) if num
293
+ children << number(num) if num
291
294
 
292
- children << id(options[:id]) if options[:id]
295
+ children << id(options[:id]) if options[:id]
293
296
 
294
- if levels = options[:level] || options[:levels]
295
- levels = [levels] unless levels.is_a?(Array)
296
- levels.each do |l|
297
- children << level(l[:name], l[:value], l[:unit] || l[:units])
297
+ if levels = options[:level] || options[:levels]
298
+ levels = [levels] unless levels.is_a?(Array)
299
+ levels.each do |l|
300
+ children << level(l[:name], l[:value], l[:unit] || l[:units])
301
+ end
298
302
  end
299
- end
300
303
 
301
- lims = options[:limit] || options[:limits]
302
- if lims || options[:lo] || options[:low] || options[:hi] || options[:high]
303
- if lims == :none || lims == 'none'
304
- children << n0(:nolimits)
305
- else
306
- lims = Array(lims) unless lims.is_a?(Array)
307
- if lo = options[:lo] || options[:low]
308
- lims << { value: lo, rule: :gte }
309
- end
310
- if hi = options[:hi] || options[:high]
311
- lims << { value: hi, rule: :lte }
312
- end
313
- lims.each do |l|
314
- if l.is_a?(Hash)
315
- children << n(:limit, [l[:value], l[:rule], l[:unit] || l[:units], l[:selector]])
304
+ lims = options[:limit] || options[:limits]
305
+ if lims || options[:lo] || options[:low] || options[:hi] || options[:high]
306
+ if lims == :none || lims == 'none'
307
+ children << n0(:nolimits)
308
+ else
309
+ lims = Array(lims) unless lims.is_a?(Array)
310
+ if lo = options[:lo] || options[:low]
311
+ lims << { value: lo, rule: :gte }
312
+ end
313
+ if hi = options[:hi] || options[:high]
314
+ lims << { value: hi, rule: :lte }
315
+ end
316
+ lims.each do |l|
317
+ if l.is_a?(Hash)
318
+ children << n(:limit, [l[:value], l[:rule], l[:unit] || l[:units], l[:selector]])
319
+ end
316
320
  end
317
321
  end
318
322
  end
319
- end
320
323
 
321
- if pins = options[:pin] || options[:pins]
322
- pins = [pins] unless pins.is_a?(Array)
323
- pins.each do |p|
324
- if p.is_a?(Hash)
325
- children << pin(p[:name])
326
- else
327
- children << pin(p)
324
+ if pins = options[:pin] || options[:pins]
325
+ pins = [pins] unless pins.is_a?(Array)
326
+ pins.each do |p|
327
+ if p.is_a?(Hash)
328
+ children << pin(p[:name])
329
+ else
330
+ children << pin(p)
331
+ end
328
332
  end
329
333
  end
330
- end
331
334
 
332
- if pats = options[:pattern] || options[:patterns]
333
- pats = [pats] unless pats.is_a?(Array)
334
- pats.each do |p|
335
- if p.is_a?(Hash)
336
- children << pattern(p[:name], p[:path])
337
- else
338
- children << pattern(p)
335
+ if pats = options[:pattern] || options[:patterns]
336
+ pats = [pats] unless pats.is_a?(Array)
337
+ pats.each do |p|
338
+ if p.is_a?(Hash)
339
+ children << pattern(p[:name], p[:path])
340
+ else
341
+ children << pattern(p)
342
+ end
339
343
  end
340
344
  end
341
- end
342
345
 
343
- if options[:meta]
344
- attrs = []
345
- options[:meta].each { |k, v| attrs << attribute(k, v) }
346
- children << n(:meta, attrs)
347
- end
346
+ if options[:meta]
347
+ attrs = []
348
+ options[:meta].each { |k, v| attrs << attribute(k, v) }
349
+ children << n(:meta, attrs)
350
+ end
348
351
 
349
- if subs = options[:sub_test] || options[:sub_tests]
350
- subs = [subs] unless subs.is_a?(Array)
351
- subs.each do |s|
352
- children << s.updated(:sub_test, nil)
352
+ if subs = options[:sub_test] || options[:sub_tests]
353
+ subs = [subs] unless subs.is_a?(Array)
354
+ subs.each do |s|
355
+ children << s.updated(:sub_test, nil)
356
+ end
353
357
  end
354
- end
355
358
 
356
- children << on_fail(options[:on_fail]) if options[:on_fail]
357
- children << on_pass(options[:on_pass]) if options[:on_pass]
359
+ children << on_fail(options[:on_fail]) if options[:on_fail]
360
+ children << on_pass(options[:on_pass]) if options[:on_pass]
358
361
 
359
- save_conditions
360
- n(:test, children)
362
+ save_conditions
363
+ n(:test, children)
364
+ end
361
365
  end
362
366
  end
363
367
 
@@ -374,12 +378,13 @@ module ATP
374
378
  fail 'The bin number must be passed as the first argument'
375
379
  end
376
380
  options[:bin_description] ||= options.delete(:description)
377
- extract_meta!(options)
378
- apply_conditions(options) do
379
- options[:type] ||= :fail
380
- options[:bin] = number
381
- options[:softbin] ||= options[:soft_bin] || options[:sbin]
382
- set_result(options[:type], options)
381
+ extract_meta!(options) do
382
+ apply_conditions(options) do
383
+ options[:type] ||= :fail
384
+ options[:bin] = number
385
+ options[:softbin] ||= options[:soft_bin] || options[:sbin]
386
+ set_result(options[:type], options)
387
+ end
383
388
  end
384
389
  end
385
390
 
@@ -392,57 +397,64 @@ module ATP
392
397
  end
393
398
 
394
399
  def cz(instance, cz_setup, options = {})
395
- extract_meta!(options)
396
- apply_conditions(options) do
397
- node = n1(:cz, cz_setup)
398
- append_to(node) { test(instance, options) }
400
+ extract_meta!(options) do
401
+ apply_conditions(options) do
402
+ node = n1(:cz, cz_setup)
403
+ append_to(node) { test(instance, options) }
404
+ end
399
405
  end
400
406
  end
401
407
  alias_method :characterize, :cz
402
408
 
403
409
  # Append a log message line to the flow
404
410
  def log(message, options = {})
405
- extract_meta!(options)
406
- apply_conditions(options) do
407
- n1(:log, message.to_s)
411
+ extract_meta!(options) do
412
+ apply_conditions(options) do
413
+ n1(:log, message.to_s)
414
+ end
408
415
  end
409
416
  end
410
417
 
411
418
  # Enable a flow control variable
412
419
  def enable(var, options = {})
413
- extract_meta!(options)
414
- apply_conditions(options) do
415
- n1(:enable, var)
420
+ extract_meta!(options) do
421
+ apply_conditions(options) do
422
+ n1(:enable, var)
423
+ end
416
424
  end
417
425
  end
418
426
 
419
427
  # Disable a flow control variable
420
428
  def disable(var, options = {})
421
- extract_meta!(options)
422
- apply_conditions(options) do
423
- n1(:disable, var)
429
+ extract_meta!(options) do
430
+ apply_conditions(options) do
431
+ n1(:disable, var)
432
+ end
424
433
  end
425
434
  end
426
435
 
427
436
  def set_flag(flag, options = {})
428
- extract_meta!(options)
429
- apply_conditions(options) do
430
- set_flag_node(flag)
437
+ extract_meta!(options) do
438
+ apply_conditions(options) do
439
+ set_flag_node(flag)
440
+ end
431
441
  end
432
442
  end
433
443
 
434
444
  # Insert explicitly rendered content in to the flow
435
445
  def render(str, options = {})
436
- extract_meta!(options)
437
- apply_conditions(options) do
438
- n1(:render, str)
446
+ extract_meta!(options) do
447
+ apply_conditions(options) do
448
+ n1(:render, str)
449
+ end
439
450
  end
440
451
  end
441
452
 
442
453
  def continue(options = {})
443
- extract_meta!(options)
444
- apply_conditions(options) do
445
- n0(:continue)
454
+ extract_meta!(options) do
455
+ apply_conditions(options) do
456
+ n0(:continue)
457
+ end
446
458
  end
447
459
  end
448
460
 
@@ -489,37 +501,50 @@ module ATP
489
501
 
490
502
  private
491
503
 
504
+ def description
505
+ @description.last
506
+ end
507
+
508
+ def source_file
509
+ @source_file.last
510
+ end
511
+
512
+ def source_line_number
513
+ @source_line_number.last
514
+ end
515
+
492
516
  def flow_control_method(name, flag, options = {}, &block)
493
- extract_meta!(options)
494
- if flag.is_a?(Array)
495
- if name == :if_passed
496
- fail 'if_passed only accepts one ID, use if_any_passed or if_all_passed for multiple IDs'
497
- end
498
- if name == :if_failed
499
- fail 'if_failed only accepts one ID, use if_any_failed or if_all_failed for multiple IDs'
500
- end
501
- end
502
- apply_conditions(options) do
503
- if block
504
- node = n1(name, flag)
505
- open_conditions << [name, flag]
506
- node = append_to(node) { block.call }
507
- open_conditions.pop
508
- else
509
- unless options[:then] || options[:else]
510
- fail "You must supply a :then or :else option when calling #{name} like this!"
517
+ extract_meta!(options) do
518
+ if flag.is_a?(Array)
519
+ if name == :if_passed
520
+ fail 'if_passed only accepts one ID, use if_any_passed or if_all_passed for multiple IDs'
511
521
  end
512
- node = n1(name, flag)
513
- if options[:then]
514
- node = append_to(node) { options[:then].call }
522
+ if name == :if_failed
523
+ fail 'if_failed only accepts one ID, use if_any_failed or if_all_failed for multiple IDs'
515
524
  end
516
- if options[:else]
517
- e = n0(:else)
518
- e = append_to(e) { options[:else].call }
519
- node = node.updated(nil, node.children + [e])
525
+ end
526
+ apply_conditions(options) do
527
+ if block
528
+ node = n1(name, flag)
529
+ open_conditions << [name, flag]
530
+ node = append_to(node) { block.call }
531
+ open_conditions.pop
532
+ else
533
+ unless options[:then] || options[:else]
534
+ fail "You must supply a :then or :else option when calling #{name} like this!"
535
+ end
536
+ node = n1(name, flag)
537
+ if options[:then]
538
+ node = append_to(node) { options[:then].call }
539
+ end
540
+ if options[:else]
541
+ e = n0(:else)
542
+ e = append_to(e) { options[:else].call }
543
+ node = node.updated(nil, node.children + [e])
544
+ end
520
545
  end
546
+ node
521
547
  end
522
- node
523
548
  end
524
549
  end
525
550
 
@@ -629,9 +654,13 @@ module ATP
629
654
  end
630
655
 
631
656
  def extract_meta!(options)
632
- self.source_file = options.delete(:source_file)
633
- self.source_line_number = options.delete(:source_line_number)
634
- self.description = options.delete(:description)
657
+ @source_file << options.delete(:source_file)
658
+ @source_line_number << options.delete(:source_line_number)
659
+ @description << options.delete(:description)
660
+ yield
661
+ @source_file.pop
662
+ @source_line_number.pop
663
+ @description.pop
635
664
  end
636
665
 
637
666
  def id(name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen McGinty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-31 00:00:00.000000000 Z
11
+ date: 2018-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: origen