Skip to content

Fix the test framework is failing in CRLF env. #2028

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

Merged
merged 1 commit into from
Oct 7, 2017

Conversation

wada314
Copy link
Contributor

@wada314 wada314 commented Oct 4, 2017

Fixes #1318 .
This just fixes the framework error: Many tests are still failing under Windows machine because of CRLF newline. Maybe I follow up with another pull requests.

Note: I cannot use str::lines() method to compare because that method does not respects the last empty line in the file.
https://doc.rust-lang.org/std/string/struct.String.html#method.lines

@wada314 wada314 changed the title Fix the test framework is failing in CRLF newline machine Fix the test framework is failing in CRLF env. Oct 4, 2017
Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I think the comment is out of date now though.

I am a bit worried about the performance of the second approach since it requires re-allocating the entire text for both the formatted and unformatted text. I expect that != just loops over s.chars() and compares them, so it would be fairly straightforward to write your own function which compares two strings, but treats \r\n and \n as equivalent.

@wada314
Copy link
Contributor Author

wada314 commented Oct 5, 2017

Thank you for reviewing!

Yes I agree for your concern. I wrote a function to compare bytes automatically converting \r\n to \n, without re-allocating I believe. Could you please take another look?

Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The strategy looks good, just a small issue with the details.

Could you use rebase to fix up your Git history too please? (let me know if you need help with that)

tests/system.rs Outdated

#[test]
fn string_eq_ignore_newline_repr_test() {
assert!(string_eq_ignore_newline_repr("a\nb\nc\rd", "a\nb\r\nc\rd"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a few more test cases please? For example, where the left or right are empty, where they match trivially, where they don't match, and where the left and right are different lengths.

tests/system.rs Outdated

// Compare strings without distinguishing between CRLF and LF
fn string_eq_ignore_newline_repr(left: &str, right: &str) -> bool {
let left = BytesIgnoreNewlineRepr(left.bytes().peekable());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to use chars rather than bytes here, and iterate over chars (I'm not sure if it is possible, but I feel like, there might be some subtle bug if b'\r' is a byte in a longer char

@wada314
Copy link
Contributor Author

wada314 commented Oct 6, 2017

Yeah I somehow messed my repository by rebasing 😆 I needed to squash my commits to fix it, hope it doesn't matter.

chars and bytes

Personally I lean into bytes but I don't care actually so changed to chars.
Just I didn't want to encode every bytes into char. The input bytes are utf8 so I believe it's guaranteed to be safe in < 0x7f area.

tests

added some.

@nrc nrc merged commit eec833f into rust-lang:master Oct 7, 2017
@nrc
Copy link
Member

nrc commented Oct 7, 2017

Great, thanks for the changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests fail on Windows with panic in tests/system.rs
2 participants