Skip to content
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

Appears to have issues with CRLF line endings #48

Open
Alpvax opened this issue Apr 18, 2024 · 1 comment
Open

Appears to have issues with CRLF line endings #48

Alpvax opened this issue Apr 18, 2024 · 1 comment

Comments

@Alpvax
Copy link

Alpvax commented Apr 18, 2024

I wish to test against a file with the line endings as CRLF, using expect_file
When I use UPDATE_EXPECT, the test passes, but if I then re-run the test, it fails, with no highlighted error characters.

@bjorn3
Copy link

bjorn3 commented Apr 18, 2024

Do you mean that the value which you are testing is a string containing a CRLF? In other words something like

use expect_test::expect;

#[test]
fn foo() {
    let actual = "foo\r\n";
    let expected = expect![[r#"
    foo
"#]];
    expected.assert_eq(&actual);
}

? Rust normalizes all strings from CRLF to LF, so expect_test will think that the test expectation is meant to use LF even if the source file contains CRLF. This then results in a mismatch between the actual (CRLF line endings) and expected (LF line endings) value. You can use .assert_debug_eq() instead of .assert_eq() to make the line endings get rendered as \r\n in the test expectation to avoid this normalization:

use expect_test::expect;

#[test]
fn foo() {
    let actual = "foo\r\n";
    let expected = expect![[r#"
        "foo\r\n"
    "#]];
    expected.assert_debug_eq(&actual);
}

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

No branches or pull requests

2 participants