Class: ATP::Processors::Relationship
Overview
This processor will apply the relationships between tests, e.g. if testB should only execute if testA passes, then this processor will update the AST to make testA set a flag on pass, and then update testB to only run if that flag is set.
Defined Under Namespace
Classes: ExtractTestResults
Instance Attribute Summary collapse
Instance Method Summary
collapse
#clean_flag, #extract_volatiles, #handler_missing, #process, #process_all, #volatile?, #volatile_flags
Instance Attribute Details
#test_results ⇒ Object
Returns a hash containing the IDs of all tests that have dependents
8
9
10
|
# File 'lib/atp/processors/relationship.rb', line 8
def test_results
@test_results
end
|
Instance Method Details
#add_fail_flag(id, node) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/atp/processors/relationship.rb', line 76
def add_fail_flag(id, node)
node = node.ensure_node_present(:on_fail)
node.updated(nil, node.children.map do |n|
if n.type == :on_fail
n = n.add node.updated(:set_flag, ["#{id}_FAILED", :auto_generated])
n.ensure_node_present(:continue)
else
n
end
end)
end
|
#add_pass_flag(id, node) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/atp/processors/relationship.rb', line 62
def add_pass_flag(id, node)
node = node.ensure_node_present(:on_pass)
node = node.ensure_node_present(:on_fail)
node.updated(nil, node.children.map do |n|
if n.type == :on_pass
n = n.add node.updated(:set_flag, ["#{id}_PASSED", :auto_generated])
elsif n.type == :on_fail
n.ensure_node_present(:continue)
else
n
end
end)
end
|
#add_ran_flags(id, node) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/atp/processors/relationship.rb', line 88
def add_ran_flags(id, node)
set_flag = node.updated(:set_flag, ["#{id}_RAN", :auto_generated])
if node.type == :group
name, id, *nodes = *node
if id.type == :id
nodes.unshift(set_flag)
nodes.unshift(id)
else
nodes.unshift(id)
nodes.unshift(set_flag)
end
node.updated(nil, [name] + nodes)
elsif node.type == :test
node.updated(:inline, [node, set_flag])
else
fail "Don't know how to add ran flag to #{node.type}"
end
end
|
#id(node) ⇒ Object
Returns the ID of the give test node (if any), caller is responsible for only passing test nodes
177
178
179
180
181
|
# File 'lib/atp/processors/relationship.rb', line 177
def id(node)
if n = node.children.find { |c| c.type == :id }
n.children.first
end
end
|
#id_to_flag(id, type) ⇒ Object
183
184
185
186
187
188
189
|
# File 'lib/atp/processors/relationship.rb', line 183
def id_to_flag(id, type)
if id.is_a?(Array)
id.map { |i| "#{i}_#{type}" }
else
"#{id}_#{type}"
end
end
|
#on_if_all_failed(node) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/atp/processors/relationship.rb', line 135
def on_if_all_failed(node)
ids, *children = *node
ids.reverse_each.with_index do |id, i|
if i == 0
node = node.updated(:if_flag, [id_to_flag(id, 'FAILED')] + process_all(children))
else
node = node.updated(:if_flag, [id_to_flag(id, 'FAILED'), node])
end
end
node
end
|
#on_if_all_passed(node) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/atp/processors/relationship.rb', line 153
def on_if_all_passed(node)
ids, *children = *node
ids.reverse_each.with_index do |id, i|
if i == 0
node = node.updated(:if_flag, [id_to_flag(id, 'PASSED')] + process_all(children))
else
node = node.updated(:if_flag, [id_to_flag(id, 'PASSED'), node])
end
end
node
end
|
#on_if_failed(node) ⇒ Object
Also known as:
on_if_any_failed
129
130
131
132
|
# File 'lib/atp/processors/relationship.rb', line 129
def on_if_failed(node)
id, *children = *node
node.updated(:if_flag, [id_to_flag(id, 'FAILED')] + process_all(children))
end
|
#on_if_passed(node) ⇒ Object
Also known as:
on_if_any_passed
147
148
149
150
|
# File 'lib/atp/processors/relationship.rb', line 147
def on_if_passed(node)
id, *children = *node
node.updated(:if_flag, [id_to_flag(id, 'PASSED')] + process_all(children))
end
|
#on_if_ran(node) ⇒ Object
165
166
167
168
|
# File 'lib/atp/processors/relationship.rb', line 165
def on_if_ran(node)
id, *children = *node
node.updated(:if_flag, [id_to_flag(id, 'RAN')] + process_all(children))
end
|
#on_test(node) ⇒ Object
Also known as:
on_group
Set flags depending on the result on tests which have dependents later in the flow
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/atp/processors/relationship.rb', line 113
def on_test(node)
nid = id(node)
if test_results[nid]
node = add_pass_flag(nid, node) if test_results[nid][:passed]
node = add_fail_flag(nid, node) if test_results[nid][:failed]
node = add_ran_flags(nid, node) if test_results[nid][:ran]
end
if node.type == :group
node.updated(nil, process_all(node))
else
node
end
end
|
#on_unless_ran(node) ⇒ Object
170
171
172
173
|
# File 'lib/atp/processors/relationship.rb', line 170
def on_unless_ran(node)
id, *children = *node
node.updated(:unless_flag, [id_to_flag(id, 'RAN')] + process_all(children))
end
|
#run(node) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/atp/processors/relationship.rb', line 55
def run(node)
t = ExtractTestResults.new
t.process(node)
@test_results = t.results || {}
process(node)
end
|