Skip to content

Commit 0c9cff3

Browse files
committed
Fix --flattenkeywords with VAR, GROUP and RETURN
Fixes #5466.
1 parent e4c6314 commit 0c9cff3

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

atest/robot/output/flatten_keyword.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ Flattened in log after execution
6868

6969
Flatten controls in keyword
7070
${tc} = Check Test Case ${TEST NAME}
71-
Check Counts ${tc[0]} 23
7271
@{expected} = Create List
7372
... Outside IF Inside IF 1 Nested IF
7473
... 3 2 1 BANG!
7574
... FOR: 0 1 FOR: 1 1 FOR: 2 1
7675
... WHILE: 2 1 \${i} = 1 WHILE: 1 1 \${i} = 0
7776
... AssertionError 1 finally
78-
FOR ${msg} ${exp} IN ZIP ${tc[0].body} ${expected}
77+
... Inside GROUP \${x} = Using VAR
78+
FOR ${msg} ${exp} IN ZIP ${tc[0].body} ${expected} mode=STRICT
7979
Check Log Message ${msg} ${exp} level=IGNORE
8080
END
8181

atest/testdata/output/flatten_keywords.robot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ Flatten controls in keyword
8888
FOR ${i} IN RANGE 3
8989
Log FOR: ${i}
9090
Keyword 1
91+
CONTINUE
92+
Fail Not run
9193
END
9294
WHILE $i > 0
9395
Log WHILE: ${i}
@@ -103,6 +105,11 @@ Flatten controls in keyword
103105
FINALLY
104106
Log finally
105107
END
108+
GROUP
109+
Log Inside GROUP
110+
END
111+
VAR ${x} Using VAR
112+
RETURN return value
106113

107114
Countdown
108115
[Arguments] ${count}=${3}

src/robot/result/resultbuilder.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,31 @@ def _flatten_keywords(self, context, flattened):
172172
name_match, by_name = self._get_matcher(FlattenByNameMatcher, flattened)
173173
type_match, by_type = self._get_matcher(FlattenByTypeMatcher, flattened)
174174
started = -1 # If 0 or more, we are flattening.
175-
containers = {"kw", "for", "while", "iter", "if", "try"}
175+
include_on_top = {"doc", "tag", "timeout", "status"}
176176
for event, elem in context:
177177
tag = elem.tag
178178
if event == "start":
179-
if tag in containers:
180-
if started >= 0:
181-
started += 1
182-
elif by_name and tag == "kw" and name_match(
179+
if started >= 0:
180+
started += 1
181+
elif (
182+
by_name
183+
and tag == "kw"
184+
and name_match(
183185
elem.get("name", ""),
184186
elem.get("owner") or elem.get("library"),
185-
):
186-
started = 0
187-
elif by_type and type_match(tag):
188-
started = 0
189-
elif started == 0 and tag == "status":
187+
# 'library' is for RF < 7 compatibility
188+
)
189+
):
190+
started = 0
191+
elif by_type and type_match(tag):
192+
started = 0
193+
elif started == 1 and tag == "status":
190194
elem.text = create_flatten_message(elem.text)
191-
if started <= 0 or tag == "msg":
195+
if started <= 0 or (started == 1 and tag in include_on_top) or tag == "msg":
192196
yield event, elem
193197
else:
194198
elem.clear()
195-
if started >= 0 and event == "end" and tag in containers:
199+
if started >= 0 and event == "end":
196200
started -= 1
197201

198202
def _get_matcher(self, matcher_class, flattened):

0 commit comments

Comments
 (0)