Skip to content

Commit

Permalink
Fix ReplaceReturns with RF 7 removing RETURN
Browse files Browse the repository at this point in the history
  • Loading branch information
bhirsz committed Jan 12, 2024
1 parent 7e2c293 commit b21d89c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/releasenotes/unreleased/fixes.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ReplaceReturns removing duplicated RETURN
------------------------------------------

In Robot Framework 7.0 ``ReplaceReturns`` removed all other instances of ``RETURN`` in the same keyword.
It is because internal model for ``RETURN`` class changed and ``ReplaceReturns`` transformer had to be updated.

8 changes: 6 additions & 2 deletions robotidy/transformers/ReplaceReturns.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ def visit_KeywordCall(self, node): # noqa
return node

@skip_if_disabled
def visit_Return(self, node): # noqa
def visit_ReturnSetting(self, node): # noqa
self.return_statement = node

visit_ReturnSetting = visit_Return
@skip_if_disabled
def visit_Return(self, node): # noqa
if misc.ROBOT_VERSION.major >= 7: # In RF 7, RETURN was class was renamed to Return
return node
self.return_statement = node

@skip_if_disabled
def visit_Error(self, node): # noqa
Expand Down
7 changes: 6 additions & 1 deletion tests/atest/transformers/ReplaceReturns/expected/test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ Keyword with Multiple [Return]

Keyword with RETURN
No Operation
RETURN 1
RETURN 1

Keyword With Two RETURN
IF ${GLOBAL} RETURN
No Operation
RETURN
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ Keyword with Multiple [Return]

Keyword with RETURN
No Operation
RETURN 1
RETURN 1

Keyword With Two RETURN
IF ${GLOBAL} RETURN
No Operation
RETURN
7 changes: 6 additions & 1 deletion tests/atest/transformers/ReplaceReturns/source/test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ Keyword with Multiple [Return]

Keyword with RETURN
No Operation
RETURN 1
RETURN 1

Keyword With Two RETURN
IF ${GLOBAL} RETURN
No Operation
RETURN
2 changes: 1 addition & 1 deletion tests/rf_versions_matrix/requirements_rf7.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
robotframework==7.0rc1
robotframework==7.0

0 comments on commit b21d89c

Please sign in to comment.