Class: ATP::Flow
- Inherits:
-
Object
- Object
- ATP::Flow
- Defined in:
- lib/atp/flow.rb
Overview
Implements the main user API for building and interacting with an abstract test program
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#program ⇒ Object
readonly
Returns the value of attribute program.
-
#raw ⇒ Object
readonly
Returns the raw AST.
Instance Method Summary collapse
-
#ast ⇒ Object
Returns a processed/optimized AST, this is the one that should be used to build and represent the given test flow.
- #bin(number, options = {}) ⇒ Object
- #context ⇒ Object
-
#context_changed?(options) ⇒ Boolean
Returns true if the test context generated from the supplied options + existing condition wrappers, is different from that which was applied to the previous test.
- #context_equal?(a, b) ⇒ Boolean
- #cz(instance, cz_setup, options = {}) ⇒ Object (also: #characterize)
-
#disable(var, options = {}) ⇒ Object
Disable a flow control variable.
-
#enable(var, options = {}) ⇒ Object
Enable a flow control variable.
-
#group(name, options = {}) ⇒ Object
Group all tests generated within the given block.
-
#initialize(program, name = nil, options = {}) ⇒ Flow
constructor
A new instance of Flow.
-
#log(message, options = {}) ⇒ Object
Append a log message line to the flow.
- #marshal_dump ⇒ Object private
- #marshal_load(array) ⇒ Object private
-
#render(str, options = {}) ⇒ Object
Insert explicitly rendered content in to the flow.
-
#run(options = {}) ⇒ Object
Execute the given flow in the console.
-
#test(instance, options = {}) ⇒ Object
Add a test line to the flow.
- #with_condition(options) ⇒ Object (also: #with_conditions)
Constructor Details
#initialize(program, name = nil, options = {}) ⇒ Flow
Returns a new instance of Flow.
10 11 12 13 14 15 16 |
# File 'lib/atp/flow.rb', line 10 def initialize(program, name = nil, = {}) name, = nil, name if name.is_a?(Hash) () @program = program @name = name @raw = builder.flow(name) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/atp/flow.rb', line 8 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/atp/flow.rb', line 5 def name @name end |
#program ⇒ Object (readonly)
Returns the value of attribute program.
5 6 7 |
# File 'lib/atp/flow.rb', line 5 def program @program end |
#raw ⇒ Object
Returns the raw AST
7 8 9 |
# File 'lib/atp/flow.rb', line 7 def raw @raw end |
Instance Method Details
#ast ⇒ Object
Returns a processed/optimized AST, this is the one that should be used to build and represent the given test flow
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/atp/flow.rb', line 30 def ast ast = Processors::PreCleaner.new.process(raw) # File.open("a1.txt", "w") { |f| f.write(ast) } ast = Processors::FlowID.new.run(ast, id) if id # File.open("a2.txt", "w") { |f| f.write(ast) } Validators::DuplicateIDs.new(self).process(ast) Validators::MissingIDs.new(self).process(ast) ast = Processors::Condition.new.process(ast) ast = Processors::Relationship.new.process(ast) ast = Processors::PostCleaner.new.process(ast) Validators::Jobs.new(self).process(ast) ast end |
#bin(number, options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/atp/flow.rb', line 99 def bin(number, = {}) () t = apply_open_conditions() do || fail 'A :type option set to :pass or :fail is required when calling bin' unless [:type] [:bin] = number [:softbin] ||= [:soft_bin] || [:sbin] builder.set_result([:type], ) end append(t) end |
#context ⇒ Object
176 177 178 |
# File 'lib/atp/flow.rb', line 176 def context builder.context end |
#context_changed?(options) ⇒ Boolean
Returns true if the test context generated from the supplied options + existing condition wrappers, is different from that which was applied to the previous test.
170 171 172 173 174 |
# File 'lib/atp/flow.rb', line 170 def context_changed?() a = context b = build_context() !context_equal?(a, b) end |
#context_equal?(a, b) ⇒ Boolean
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/atp/flow.rb', line 180 def context_equal?(a, b) if a.size == b.size a = clean_condition(a[:conditions]) b = clean_condition(b[:conditions]) if a.keys.sort == b.keys.sort a.all? do |key, value| value.flatten.uniq.sort == b[key].flatten.uniq.sort end end end end |
#cz(instance, cz_setup, options = {}) ⇒ Object Also known as: characterize
110 111 112 113 114 115 116 117 118 |
# File 'lib/atp/flow.rb', line 110 def cz(instance, cz_setup, = {}) () t = apply_open_conditions() do || conditions = .delete(:conditions) [:return] = true builder.cz(cz_setup, test(instance, .merge(dont_apply_conditions: true)), conditions: conditions) end append(t) end |
#disable(var, options = {}) ⇒ Object
Disable a flow control variable
140 141 142 143 144 145 146 |
# File 'lib/atp/flow.rb', line 140 def disable(var, = {}) () t = apply_open_conditions() do || builder.disable_flow_flag(var, ) end append(t) end |
#enable(var, options = {}) ⇒ Object
Enable a flow control variable
131 132 133 134 135 136 137 |
# File 'lib/atp/flow.rb', line 131 def enable(var, = {}) () t = apply_open_conditions() do || builder.enable_flow_flag(var, ) end append(t) end |
#group(name, options = {}) ⇒ Object
Group all tests generated within the given block
51 52 53 54 55 56 |
# File 'lib/atp/flow.rb', line 51 def group(name, = {}) open_groups.push([]) yield () append builder.group(name, open_groups.pop, ) end |
#log(message, options = {}) ⇒ Object
Append a log message line to the flow
122 123 124 125 126 127 128 |
# File 'lib/atp/flow.rb', line 122 def log(, = {}) () t = apply_open_conditions() do || builder.log(, ) end append(t) end |
#marshal_dump ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/atp/flow.rb', line 19 def marshal_dump [@name, @program, Processors::Marshal.new.process(@raw)] end |
#marshal_load(array) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 |
# File 'lib/atp/flow.rb', line 24 def marshal_load(array) @name, @program, @raw = array end |
#render(str, options = {}) ⇒ Object
Insert explicitly rendered content in to the flow
149 150 151 152 |
# File 'lib/atp/flow.rb', line 149 def render(str, = {}) () append builder.render(str) end |
#run(options = {}) ⇒ Object
Execute the given flow in the console
163 164 165 166 |
# File 'lib/atp/flow.rb', line 163 def run( = {}) Formatters::Datalog.run_and_format(ast, ) nil end |
#test(instance, options = {}) ⇒ Object
Add a test line to the flow
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/atp/flow.rb', line 67 def test(instance, = {}) () r = .delete(:return) t = apply_open_conditions() do || # Allows any continue, bin, or soft bin argument passed in at the options top-level to be assumed # to be the action to take if the test fails if b = .delete(:bin) [:on_fail] ||= {} [:on_fail][:bin] = b end if b = .delete(:softbin) || b = .delete(:sbin) || b = .delete(:soft_bin) [:on_fail] ||= {} [:on_fail][:softbin] = b end if .delete(:continue) [:on_fail] ||= {} [:on_fail][:continue] = true end if f = .delete(:flag_pass) [:on_pass] ||= {} [:on_pass][:set_run_flag] = f end if f = .delete(:flag_fail) [:on_fail] ||= {} [:on_fail][:set_run_flag] = f end builder.test(instance, ) end append(t) unless r t end |
#with_condition(options) ⇒ Object Also known as: with_conditions
154 155 156 157 158 159 |
# File 'lib/atp/flow.rb', line 154 def with_condition() () open_conditions.push() yield open_conditions.pop end |