From cd5f676903606f8623fbc921489ddab7419bbadf Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Thu, 16 Sep 2021 22:33:04 -0400 Subject: [PATCH] hashsum: add tests for Windows text mode --- tests/by-util/test_hashsum.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index f2cf91d45..545b4ee78 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -38,6 +38,30 @@ macro_rules! test_digest { .no_stderr() .stdout_is("input.txt: OK\n"); } + + #[cfg(windows)] + #[test] + fn test_text_mode() { + // TODO Replace this with hard-coded files that store the + // expected output of text mode on an input file that has + // "\r\n" line endings. + let result = new_ucmd!() + .args(&[DIGEST_ARG, BITS_ARG, "-b"]) + .pipe_in("a\nb\nc\n") + .succeeds(); + let expected = result.no_stderr().stdout(); + // Replace the "*-\n" at the end of the output with " -\n". + // The asterisk indicates that the digest was computed in + // binary mode. + let n = expected.len(); + let expected = [&expected[..n - 3], &[b' ', b'-', b'\n']].concat(); + new_ucmd!() + .args(&[DIGEST_ARG, BITS_ARG, "-t"]) + .pipe_in("a\r\nb\r\nc\r\n") + .succeeds() + .no_stderr() + .stdout_is(std::str::from_utf8(&expected).unwrap()); + } } )*) }