atrium icon indicating copy to clipboard operation
atrium copied to clipboard

warn if a CharSequence.contains and the like did not match because of different line endings

Open robstoll opened this issue 3 years ago • 5 comments

Platform (all, jvm, js): all Extension (none, kotlin 1.3): none

Code related feature

Consider:

expect("Hello World\r\nMy name is Robert").contains("Hello World\n")

Currently results in the following error report:

expected that subject: "Hello World
My name is Robert"        <558676967>
◆ contains: 
  ⚬ value: "Hello World

It would be very helpful if Atrium pointed out that it would have matched if the user were using the correct line endings. So I imagine something like the following in the report:

expected that subject: "Hello World
My name is Robert"        <558676967>
◆ contains: 
  ⚬ value: "Hello World
"
  🔎 Atrium detected that your expectation would have been met if you had used `\r\n` instead of `\n` in the expected string. 
    Consider using `System.lineSeparator` if your test runs on different operating systems.

robstoll avatar Mar 16 '21 20:03 robstoll

I like the idea! With the following wording the message would be easier to understand for me:

Atrium detected that your expectation would have been met if you expected \r\n instead of \n. Consider using System.lineSeparator if your test runs on different OS.

I also don’t know why we should suggest System.getProperty("line.separator") when there is System.lineSeparator

jGleitz avatar Mar 17 '21 11:03 jGleitz

Thanks for the hint about System.lineSeparator and the missing been. However, I prefer used over expected. I have update the description and added the missing had. I hope the sentence is now correct :)

robstoll avatar Mar 17 '21 20:03 robstoll

My issue with ‘used’ is that it is ambiguous where \r\n should have been used. Although not both interpretations are equally likely, the sentence could be read as

if you had used \r\n instead of \n in the expectation

or as

if you had used \r\n instead of \n in your production code

jGleitz avatar Mar 17 '21 21:03 jGleitz

I see your point. The problem I see with expected is that it might not be that obvious could be confusing in the sense of:

Why does Atrium tell me I have expected \n I have expected Hello World\n

how about: if you had used \r\n instead of \n in the expected string

robstoll avatar Mar 17 '21 21:03 robstoll

if you had used \r\n instead of \n in the expected string

:+1:

jGleitz avatar Mar 18 '21 16:03 jGleitz