Skip to content

Commit

Permalink
Fix search order w/ two matches when one is from std lib.
Browse files Browse the repository at this point in the history
Search order needs to be used first on standard library keywords
filtered only afterwards. Fixes #4516.
  • Loading branch information
pekkaklarck committed Oct 27, 2022
1 parent 886ffcf commit acc61b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
29 changes: 21 additions & 8 deletions atest/robot/keywords/keyword_namespaces.robot
Expand Up @@ -46,12 +46,24 @@ Local keyword in resource file has precedence even if search order is set

Keyword From Custom Library Overrides Keywords From Standard Library
${tc} = Check Test Case ${TEST NAME}
Verify Override Message ${ERRORS}[2] ${tc.kws[0].msgs[0]} Comment BuiltIn
Verify Override Message ${ERRORS}[3] ${tc.kws[1].msgs[0]} Copy Directory OperatingSystem
Verify Override Message ${ERRORS}[2] ${tc.kws[0]} Comment BuiltIn
Verify Override Message ${ERRORS}[3] ${tc.kws[1]} Copy Directory OperatingSystem

Search order can give presedence to standard library keyword over custom keyword
${tc} = Check Test Case ${TEST NAME}
Check Keyword Data ${tc.kws[1]} BuiltIn.Comment args=Used from BuiltIn
Verify Override Message ${ERRORS}[4] ${tc.kws[2]} Copy Directory OperatingSystem

Search order can give presedence to custom keyword over standard library keyword
${tc} = Check Test Case ${TEST NAME}
Check Keyword Data ${tc.kws[1]} MyLibrary1.Comment
Check Log Message ${tc.kws[1].msgs[0]} Overrides keyword from BuiltIn library
Check Keyword Data ${tc.kws[2]} MyLibrary1.Copy Directory
Check Log Message ${tc.kws[2].msgs[0]} Overrides keyword from OperatingSystem library

Keyword From Custom Library Overrides Keywords From Standard Library Even When Std Lib Imported With Different Name
${tc} = Check Test Case ${TEST NAME}
Verify Override Message ${ERRORS}[4] ${tc.kws[0].msgs[0]} Replace String
Verify Override Message ${ERRORS}[5] ${tc.kws[0]} Replace String
... String MyLibrary2 Std With Name My With Name

No Warning When Custom Library Keyword Is Registered As RunKeyword Variant And It Has Same Name As Std Keyword
Expand All @@ -71,16 +83,17 @@ Keywords are first searched from test case file even if they contain dot

*** Keywords ***
Verify override message
[Arguments] ${error msg} ${kw msg} ${kw} ${standard} ${custom}=MyLibrary1
[Arguments] ${error msg} ${kw} ${name} ${standard} ${custom}=MyLibrary1
... ${std with name}= ${ctm with name}=
${std imported as} = Set Variable If "${std with name}" ${SPACE}imported as '${std with name}' ${EMPTY}
${ctm imported as} = Set Variable If "${ctm with name}" ${SPACE}imported as '${ctm with name}' ${EMPTY}
${std long} = Set Variable If "${std with name}" ${std with name} ${standard}
${ctm long} = Set Variable If "${ctm with name}" ${ctm with name} ${custom}
${expected} = Catenate
... Keyword '${kw}' found both from a custom library '${custom}'${ctm imported as}
... Keyword '${name}' found both from a custom library '${custom}'${ctm imported as}
... and a standard library '${standard}'${std imported as}. The custom keyword is used.
... To select explicitly, and to get rid of this warning, use either '${ctm long}.${kw}'
... or '${std long}.${kw}'.
... To select explicitly, and to get rid of this warning, use either '${ctm long}.${name}'
... or '${std long}.${name}'.
Check Log Message ${error msg} ${expected} WARN
Check Log Message ${kw msg} ${expected} WARN
Check Log Message ${kw.msgs[0]} ${expected} WARN
Check Log Message ${kw.msgs[1]} Overrides keyword from ${standard} library
12 changes: 12 additions & 0 deletions atest/testdata/keywords/keyword_namespaces.robot
Expand Up @@ -73,6 +73,18 @@ Keyword From Custom Library Overrides Keywords From Standard Library
Comment
Copy Directory

Search order can give presedence to standard library keyword over custom keyword
Set Library Search Order BuiltIn
Comment Used from BuiltIn
Copy Directory
[Teardown] Set Library Search Order

Search order can give presedence to custom keyword over standard library keyword
Set Library Search Order MyLibrary1
Comment
Copy Directory
[Teardown] Set Library Search Order

Keyword From Custom Library Overrides Keywords From Standard Library Even When Std Lib Imported With Different Name
${ret} = Replace String
Should Be Equal ${ret} I replace nothing!
Expand Down
4 changes: 2 additions & 2 deletions src/robot/running/namespace.py
Expand Up @@ -390,9 +390,9 @@ def _get_runner_from_libraries(self, name):
if len(handlers) > 1:
handlers = self._select_best_matches(handlers)
if len(handlers) > 1:
handlers, pre_run_message = self._filter_stdlib_handler(handlers)
handlers = self._filter_based_on_search_order(handlers)
if len(handlers) > 1:
handlers = self._filter_based_on_search_order(handlers)
handlers, pre_run_message = self._filter_stdlib_handler(handlers)
if len(handlers) != 1:
self._raise_multiple_keywords_found(handlers, name)
runner = handlers[0].create_runner(name, self.languages)
Expand Down

0 comments on commit acc61b8

Please sign in to comment.