From 95bd18bb2b83e1b94fea283114ad7d61c8b22c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Hirsz?= Date: Mon, 6 May 2024 14:02:16 +0200 Subject: [PATCH] Fix task section detection (#1075) --- docs/releasenotes/unreleased/fixes.1.rst | 7 +++++++ robocop/checkers/naming.py | 5 +++-- .../naming/mixed_task_test_settings/mixed_tasks.robot | 9 +++++++++ .../naming/mixed_task_test_settings/mixed_tests.robot | 4 ++++ .../rules/naming/mixed_task_test_settings/test_rule.py | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 docs/releasenotes/unreleased/fixes.1.rst diff --git a/docs/releasenotes/unreleased/fixes.1.rst b/docs/releasenotes/unreleased/fixes.1.rst new file mode 100644 index 000000000..33f4caa04 --- /dev/null +++ b/docs/releasenotes/unreleased/fixes.1.rst @@ -0,0 +1,7 @@ +Task section not recognized for mixed-task-test-settings rule (#1074) +---------------------------------------------------------------------- + +If last section of the file wasn't Tasks section, Robocop assumed that file contains only Test Cases section. This +caused W0326 ``mixed-task-test-settings`` to be issued with incorrect message. + +Thanks @MrBIN89 for finding the issue. diff --git a/robocop/checkers/naming.py b/robocop/checkers/naming.py index b3ff3cb7f..4aee152b7 100644 --- a/robocop/checkers/naming.py +++ b/robocop/checkers/naming.py @@ -877,8 +877,9 @@ def visit_File(self, node): # noqa ROBOT_VERSION.major >= 6 and section.header.type == Token.TASK_HEADER ): self.task_section = True - else: - self.task_section = False + break + else: + self.task_section = False super().visit_File(node) def visit_Setup(self, node): # noqa diff --git a/tests/atest/rules/naming/mixed_task_test_settings/mixed_tasks.robot b/tests/atest/rules/naming/mixed_task_test_settings/mixed_tasks.robot index b1b1500d3..9b35b562e 100644 --- a/tests/atest/rules/naming/mixed_task_test_settings/mixed_tasks.robot +++ b/tests/atest/rules/naming/mixed_task_test_settings/mixed_tasks.robot @@ -7,6 +7,15 @@ Task Tags tag Documentation some docs +*** Variables *** +${variable} value + + + *** Tasks *** Some Task No Operation + +*** Keywords *** +Some Keyword + No Operation diff --git a/tests/atest/rules/naming/mixed_task_test_settings/mixed_tests.robot b/tests/atest/rules/naming/mixed_task_test_settings/mixed_tests.robot index da19a2b3c..3eeec71c0 100644 --- a/tests/atest/rules/naming/mixed_task_test_settings/mixed_tests.robot +++ b/tests/atest/rules/naming/mixed_task_test_settings/mixed_tests.robot @@ -7,6 +7,10 @@ Task Tags tag Documentation some docs +*** Variables *** +${variable} value + + *** Test Cases *** Some Task No Operation diff --git a/tests/atest/rules/naming/mixed_task_test_settings/test_rule.py b/tests/atest/rules/naming/mixed_task_test_settings/test_rule.py index 47f94e263..bb6e416fe 100644 --- a/tests/atest/rules/naming/mixed_task_test_settings/test_rule.py +++ b/tests/atest/rules/naming/mixed_task_test_settings/test_rule.py @@ -13,7 +13,7 @@ def test_rule_rf6(self): "golden_test.robot", ], expected_file="expected_output_rf6.txt", - target_version="==6.*", + target_version=">=6", ) def test_rule(self):