Skip to content

Require global settings to be defined before tests and keywords using them #5198

Description

@pekkaklarck

Currently we support data like this so that the created test gets the setup and the template defined after the test itself:

*** Test Cases ***
Example
    arg1    arg2

*** Settings ***
Test Setup       Setup Keyword
Test Template    Template Keyword

This syntax causes two problems:

  1. It is not possible to change the value of the global test and keyword related settings. There has, for example, been several requests to to allow using different test templates in a single file with a syntax like this:
    *** Settings ***
    Test Template    Something
    
    # The following tests use the template specified above
    *** Test Cases ***
    T1
        arg1.1    arg1.2
    T2
        arg2.1    arg2.2
    
    # Change the template it and use it with the forthcoming tests
    *** Settings ***
    Test Template    New
    
    *** Test Cases ***
    T3
        arg3.1    arg3.2   arg3.3
  2. It makes implementing parsers a lot harder. Parsers typically go through data line-by-line, but in our case the parser needs to process the whole file to find possible Test Template or it won't be able to handle test cases properly. Robot's own parser obviously handles that, but this syntax makes it a lot harder to implement custom parsers, for example, for syntax highlighting purposes or to implement a faster C/Rust/Go based parser for Robot itself.

The main benefit of allowing settings to be defined after tests and keywords using them is that it allows "hiding" the Setting section at the end of the file. That can be useful when tests are shown to non-technical people, but scrolling to the right place in the file or using code folding in an IDE ought to be good enough alternatives. Notice also that even after this change we'd allow suite related settings as well as imports to be defined after tests and keywords.

What do others think about this? Do you consider the benefits explained above higher than problems? The change is backwards incompatible, so it could only be done in a major release and would require a deprecation period. Please use 👍 / 👎 reactions to indicate how you feel about this and write a comment if you have something more to say.

Activity

  1. pekkaklarck commented on Sep 4, 2024

    @pekkaklarck
    MemberAuthor

    If we agree this is a good idea, we should deprecate the old syntax already in RF 7.2. We could then change the syntax in RF 8.0, but it would probably be better to wait for RF 9.0.

  2. oboehmer commented on Sep 4, 2024

    @oboehmer
    Contributor

    I find significance of order of the settings section (or any other section) in the file to be very counter-intuitive, so I am objecting this change.. To me the use case of having different templates in a single file is not really strong enough for such a significant change.

  3. pekkaklarck commented on Sep 5, 2024

    @pekkaklarck
    MemberAuthor

    The main motivation of this proposed change is making parsing simpler. Currently when a parser sees something like

    *** Test Cases ***
    Example
        Something    here

    in the beginning of a file, it doesn't know should Something and here be tokenized as a keyword an its argument or are both of them arguments to a template keyword specified later. Handling this properly requires the parser to go through the data twice which adds complexity. Robot's own Python based parser obviously handles this, but there are pretty good reasons to implement new parsers for Robot's syntax:

    1. Syntax highlighters, like the one here on GitHub, need parsers/tokenizers for languages they support. Various syntax highlighters have a parser for Robot Framework, but I don't think any of them handles all syntax properly. For example,Tree-sitter is a popular parser generator that actually has a parser for Robot, but I don't think it handles templates. Tree-sitter parsers are implemented in C making it somewhat challenging to implement complicated parsers.
    2. Also editors and IDEs need parsers to properly support different languages. This isn't so relevant anymore when LSP is getting so popular and we have a great LSP server that uses Robot's own parser, but I'm pretty sure there are IDEs that would benefit. My understanding is that some editors use the aforementioned Tree-sitter. A Javascript based parser would be cool in a browser.
    3. Robot's own parsing could be made significantly faster by implementing the parser (most importantly tokenizer) in C, Rust or Go. Not needing to support to support templates after tests would simplify creating them.

    If we'd only need one new parser, supporting all the current quirks would be ok, but I believe there are needs for various parsers in the long run. If there's syntax that adds a lot of parsing complexity and isn't widely used, I believe we should consider removing it. In this particular case the change would also allow a new feature, changing templates, which isn't that important but has nevertheless been requested multiple times.

  4. gohierf commented on Sep 5, 2024

    @gohierf
    Contributor

    @pekkaklarck, what do you mean by

    Notice also that even after this change we'd allow suite related settings as well as imports to be defined after tests and keywords.

  5. pekkaklarck commented on Sep 5, 2024

    @pekkaklarck
    MemberAuthor

    @gohierf, the proposed change wouldn't affect how

    *** Test Cases ***
    Example
        Some keyword
    
    *** Settings ***
    Documentation    Doc for the suite.
    Library          SomeLibrary

    works. Only test and keyword related settings would need to be set before tests and keywords using them.

  6. pekkaklarck commented on Sep 9, 2024

    @pekkaklarck
    MemberAuthor

    We discussed this and some other possible syntax changes at the end of the RF 7.2 planning session today. Participants in general agreed that this change makes sense, but because various people have expressed concerns we decided to not make any decision about this. Most importantly, there won't be any deprecation warning in RF 7.2 related to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions