Skip to content

New Rule to check automatic variable availability. #1173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gohierf opened this issue Feb 13, 2025 · 1 comment
Open

New Rule to check automatic variable availability. #1173

gohierf opened this issue Feb 13, 2025 · 1 comment
Labels
rule Issue related to creating or changing a rule

Comments

@gohierf
Copy link

gohierf commented Feb 13, 2025

Some automatic variables are only available in certain context: "Test Case", "Test Teardown", "Suite Teardown" and "User Keyword Teardown".

Could Robocop check that the variables are not used outside this context?

For instance, there is no warning for using "User Keyword Teardown" ${KEYWORD STATUS} directly in a test case:

*** Test Cases***
My Test Case
    Log   ${KEYWORD STATUS}

This will fail with Variable '${KEYWORD STATUS}' not found.

However, this is a simple situation and others might be harder/not possible to work out?
For instance, using the ${TEST NAME} variable in a keyword might be legitimate when the keyword is used within a test case, but it fails when the same keyword is used in the suite setup or teardown.
In that case, I have used a TRY/EXCEPT block to deal with this situation, so I am not sure that Robocop could actually warn appropriately.

So maybe the rule should just warn that a variable as a limited scope and will not be available outside of Test Case for this particular example? Then the user can deal with it appropriately and ignore the error for this line.

@bhirsz
Copy link
Member

bhirsz commented Feb 13, 2025

The easiest option will be latest mentioned - so warn if limited scope variable is used outside the scope - and certainly we can add it.

@bhirsz bhirsz added the rule Issue related to creating or changing a rule label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Issue related to creating or changing a rule
Projects
None yet
Development

No branches or pull requests

2 participants