Skip to content

Deprecate ignoring space after literal newline #3333

Closed

Description

@pekkaklarck

Robot Framework has a strange quirk that a space character after a literal newline like \n is ignored. In other words, this test currently passes:

*** Test Cases ***
Example
    Should Be Equal    two lines\nhere    two lines\n here

The reason for this behavior is that it enabled wrapping long lines after \n when using the HTML format:

Test Case Keyword Argument Argument
Example Log xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n INFO

Such wrapping doesn't work with the plain text format, and in general there has never been real benefits from this syntax with the plain text syntax. Now that RF 3.2 won't be supporting HTML anymore (#3081), this strange feature can go as well. We cannot remove it right away, but we can deprecate it in RF 3.2 and remove later.

Activity

  1. added this to the v3.2 milestone on Oct 9, 2019
  2. pekkaklarck commented on Oct 9, 2019

    @pekkaklarck
    MemberAuthor

    A problem with deprecation is that handling \n happens in such code where the location where the syntax has been used isn't known. We can easily emit a warning that this syntax is deprecated, but the message won't tell where the problem occurs. The message has a timestamp and comparing it to timestamps in the execution log is possible, but finding exact locations using this approach is likely to be slow.

    An easier solution is simply finding \n usages from the test data. This can be done with an editor/IDE or an external tool like ack or pss. I used the latter with Robot's own tests using this command:

    pss -a '\\n [^ ]' atest/robot/
    
  3. pekkaklarck commented on Oct 9, 2019

    @pekkaklarck
    MemberAuthor

    This deprecation will be included in RF 3.2 alpha 1. If it turns out \n syntax is used widely and finding usages is hard, we can still enhance the deprecation messages before RF 3.2 final. If there are valid use cases for this syntax, we can also consider removing the deprecation.

  4. pekkaklarck commented on Oct 9, 2019

    @pekkaklarck
    MemberAuthor

    This quirk also has a quirk that space isn't ignored after \n when using the extended variable syntax. Inconsistency is not good, and an easy way to have consistent behavior it is removing the whole "feature".

  5. added a commit that references this issue on Oct 9, 2019
  6. changed the title [-]Deprecate ignoring space after literal newline (`\n `)[/-] [+]Deprecate ignoring space after literal newline[/+] on Nov 8, 2019
  7. pekkaklarck commented on Mar 3, 2020

    @pekkaklarck
    MemberAuthor

    I was able to enhance this a bit. Now the deprecation warning has a link to the keyword causing it if this syntax is used in keyword arguments. If it's used in e.g. in documentation, only the message is shown. Also added a reference to this issue to that message. Both changes will be committed shortly.

  8. paperclip commented on Jul 16, 2020

    @paperclip

    Sorry for commenting on a closed ticket.

    What should be placed instead of the space, if the intent is for there to be a space required?

  9. paperclip commented on Jul 16, 2020

    @paperclip

    I guess maybe ${SPACE}?

  10. pekkaklarck commented on Jul 16, 2020

    @pekkaklarck
    MemberAuthor

    Yeah, ${SPACE} ought to work.

  11. tomekPawlak commented on Feb 1, 2021

    @tomekPawlak

    Hello @pekkaklarck,
    After this change I can see that now breaking variables which consist of \n is problematic, as this:

    ${a}=  Set Variable  two lines\nhere
    ${b}=  Set Variable  two lines\n
    ...  here
    Should Be Equal  ${a}  ${b}
    

    should PASS but it FAIL because 2 spaces as a separator between ... and next part of variable will be processed as 1 space as a part of variable so instead

    two lines
    here
    

    we would have

    two lines
     here
    
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions