-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add community rule: not-allowed-keyword (#1082)
* Add community rule: not-allowed-keyword * Update tests for RF3 and RF4
- Loading branch information
Showing
8 changed files
with
229 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Community rule: not-allowed-keyword (#1067) | ||
------------------------------------------- | ||
|
||
New community (optional) rule W10002 ``not-allowed-keyword``. You can use this rule to find keywords that should not | ||
be used in your project. | ||
|
||
For example with following configuration:: | ||
|
||
> > robocop -i not-allowed-keyword -c not-allowed-keyword:keywords:click_using_javascript,click_with_sleep | ||
|
||
It will find and raise issues in the following code:: | ||
|
||
*** Test Cases *** | ||
Test with obsolete keyword | ||
[Setup] Click With Sleep 1 min # Robocop will report not allowed keyword | ||
Test Step | ||
|
||
|
||
*** Keywords *** | ||
Keyword With Obsolete Implementation | ||
[Arguments] ${locator} | ||
Click Using Javascript ${locator} # Robocop will report not allowed keyword | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
14 changes: 14 additions & 0 deletions
14
tests/atest/rules/community_rules/keywords/not_allowed_keyword/expected_output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
test.robot:2:16:2:27 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:4:15:4:26 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:5:18:5:39 [W] 10002 Keyword 'Not Allowed With Args' is not allowed | ||
test.robot:15:5:15:16 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:16:25:16:35 [W] 10002 Keyword 'Notallowed' is not allowed | ||
test.robot:18:9:18:30 [W] 10002 Keyword 'Not_allowed With Args' is not allowed | ||
test.robot:23:9:23:20 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:28:12:28:23 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:30:12:30:23 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:31:19:31:40 [W] 10002 Keyword 'Not Allowed With Args' is not allowed | ||
test.robot:34:19:34:30 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:38:5:38:33 [W] 10002 Keyword 'Library.Not Allowed With Lib' is not allowed | ||
test.robot:39:5:39:32 [W] 10002 Keyword 'Library2.Nested.Not Allowed' is not allowed | ||
test.robot:44:5:44:16 [W] 10002 Keyword 'Not Allowed' is not allowed |
13 changes: 13 additions & 0 deletions
13
tests/atest/rules/community_rules/keywords/not_allowed_keyword/expected_output_rf3.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
test.robot:2:16:2:27 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:4:15:4:26 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:5:18:5:39 [W] 10002 Keyword 'Not Allowed With Args' is not allowed | ||
test.robot:15:5:15:16 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:18:9:18:30 [W] 10002 Keyword 'Not_allowed With Args' is not allowed | ||
test.robot:23:9:23:20 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:28:12:28:23 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:30:12:30:23 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:31:19:31:40 [W] 10002 Keyword 'Not Allowed With Args' is not allowed | ||
test.robot:34:19:34:30 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:38:5:38:33 [W] 10002 Keyword 'Library.Not Allowed With Lib' is not allowed | ||
test.robot:39:5:39:32 [W] 10002 Keyword 'Library2.Nested.Not Allowed' is not allowed | ||
test.robot:44:5:44:16 [W] 10002 Keyword 'Not Allowed' is not allowed |
13 changes: 13 additions & 0 deletions
13
tests/atest/rules/community_rules/keywords/not_allowed_keyword/expected_output_rf4.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
test.robot:2:16:2:27 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:4:15:4:26 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:5:18:5:39 [W] 10002 Keyword 'Not Allowed With Args' is not allowed | ||
test.robot:15:5:15:16 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:18:9:18:30 [W] 10002 Keyword 'Not_allowed With Args' is not allowed | ||
test.robot:23:9:23:20 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:28:12:28:23 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:30:12:30:23 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:31:19:31:40 [W] 10002 Keyword 'Not Allowed With Args' is not allowed | ||
test.robot:34:19:34:30 [W] 10002 Keyword 'Not Allowed' is not allowed | ||
test.robot:38:5:38:33 [W] 10002 Keyword 'Library.Not Allowed With Lib' is not allowed | ||
test.robot:39:5:39:32 [W] 10002 Keyword 'Library2.Nested.Not Allowed' is not allowed | ||
test.robot:44:5:44:16 [W] 10002 Keyword 'Not Allowed' is not allowed |
46 changes: 46 additions & 0 deletions
46
tests/atest/rules/community_rules/keywords/not_allowed_keyword/test.robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
*** Settings *** | ||
Suite Setup Not Allowed | ||
Suite Teardown | ||
Test Setup Not Allowed | ||
Test Teardown Not Allowed With Args | ||
... ${arg} | ||
|
||
|
||
*** Test Cases *** | ||
Test with allowed keywords | ||
Allowed | ||
Allowed With Args ${arg} | ||
|
||
Test with not allowed keywords | ||
Not Allowed | ||
IF $condition Notallowed | ||
FOR ${var} IN RANGE 10 | ||
Not_allowed With Args ${arg} | ||
... ${arg} | ||
END | ||
IF True | ||
Log statement | ||
Not Allowed | ||
END | ||
|
||
Test with settings | ||
[Setup] Run Keywords | ||
... Not Allowed | ||
... AND | ||
... Not Allowed | ||
[Teardown] Not Allowed With Args ${arg} | ||
|
||
Test with template | ||
[Template] Not Allowed | ||
|
||
Test with library | ||
Not Allowed With Lib # should be ignored | ||
Library.Not Allowed With Lib # should be reported | ||
Library2.Nested.Not Allowed # should be reported | ||
|
||
|
||
*** Keywords *** | ||
Keyword with not allowed | ||
Not Allowed | ||
|
||
# while and stuff? |
30 changes: 30 additions & 0 deletions
30
tests/atest/rules/community_rules/keywords/not_allowed_keyword/test_rule.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from tests.atest.utils import RuleAcceptance | ||
|
||
|
||
class TestRuleAcceptance(RuleAcceptance): | ||
def test_rule(self): | ||
self.check_rule( | ||
src_files=["test.robot"], | ||
expected_file="expected_output.txt", | ||
config="-c not-allowed-keyword:keywords:NotAllowed,Not_AllowedWithArgs,library.not_allowed_with_lib", | ||
issue_format="end_col", | ||
target_version=">=5", | ||
) | ||
|
||
def test_rule_rf3(self): | ||
self.check_rule( | ||
src_files=["test.robot"], | ||
expected_file="expected_output_rf3.txt", | ||
config="-c not-allowed-keyword:keywords:NotAllowed,Not_AllowedWithArgs,library.not_allowed_with_lib", | ||
issue_format="end_col", | ||
target_version="==3.*", | ||
) | ||
|
||
def test_rule_rf4(self): | ||
self.check_rule( | ||
src_files=["test.robot"], | ||
expected_file="expected_output_rf4.txt", | ||
config="-c not-allowed-keyword:keywords:NotAllowed,Not_AllowedWithArgs,library.not_allowed_with_lib", | ||
issue_format="end_col", | ||
target_version="==4.*", | ||
) |