robotframework-robocop icon indicating copy to clipboard operation
robotframework-robocop copied to clipboard

Defining *** Test Case / Task *** section in resource file is reported as parsing-error

Open bhirsz opened this issue 3 years ago • 4 comments

Related #524

If Robocop auto detect file as resource type, but it will contain *** Test Case / Task *** section it will be reported as parsing error. It should be parsed and reported as other type of issue: test.robot:

*** Settings ***
Resource    resource.robot

resource.robot:

*** Test Cases ***
Test
    No Operation

Command:

robocop test.robot resource.robot

Output:

resource.robot:1:1 [E] 0401 Robot Framework syntax error: Resource file with 'Test Cases' section is invalid. (parsing-error)

bhirsz avatar Oct 24 '21 10:10 bhirsz

I think it should be used so that test.robot defines Resource called test.resource, not resource.robot.

Yeah I agree, I actually copy pasted wrong line from the output. We have can-be-resource-file rule to check if robot files are used as resource but don't have .resource extension. But in case if the file is used as resource (imported somewhere, doesn't matter with which extension) it shouldn't contain any tests - that's why above parsing-error is reported. But we should catch parsing-error and report it as other issue, ie *** Test Cases *** should not be used in resource file. That's what this issue is about

bhirsz avatar Oct 24 '21 13:10 bhirsz

I also got it a bit wrong, that's why deleted my comment. I made a tryout getting:

resource.robot:1:1 [E] 0401 Robot Framework syntax error: Resource file with 'Test Cases' section is invalid. (parsing-error)

Exactly same as @bhirsz
Where as documentation says:

[E0401] parsing-error: Robot Framework syntax error: %s

So, I think we are getting the resource file parse done right here. Maybe improve the output line to follow documentation will help to prevent misunderstandings. Or is that a real parse error?

rikerfi avatar Oct 24 '21 13:10 rikerfi

I also got it a bit wrong, that's why deleted my comment. I made a tryout getting:

resource.robot:1:1 [E] 0401 Robot Framework syntax error: Resource file with 'Test Cases' section is invalid. (parsing-error)

Exactly same as @bhirsz Where as documentation says:

[E0401] parsing-error: Robot Framework syntax error: %s

So, I think we are getting the resource file parse done right here. Maybe improve the output line to follow documentation will help to prevent misunderstandings. Or is that a real parse error?

Ok. Finally I got it. Totally different or new error should be reported. Sorry to spam the issue.

rikerfi avatar Oct 24 '21 13:10 rikerfi

No worries, it's good to have 'second pair of eyes' on stuff ;) It's indeed parsing error - we're using Robot Framework parsing engine under hood and it does report it as error in parsing. Until recently we reported all such issues as parsing-error. Then we introduced some rules like invalid-continuation-mark and other that are created by filtering out parsing-error. There are other issues left so I will create more rules based on parsing-error.

bhirsz avatar Oct 24 '21 13:10 bhirsz