From 67e67aac889902924ad80d6a63b8b40fcd245940 Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:08:24 +0000 Subject: [PATCH] Add a test for streaming with blank lines and a trailing newline Previously two cases were not tested: 1. The "don't add the prefix if the line is blank" case, which is why the `if input.iter().all(u8::is_ascii_whitespace)` logic exists. 2. The output when the streamed command output includes a trailing newline. Whilst the output for (2) currently includes a redundant newline, IMO it makes sense to have a test demonstrating the issue in the meantime. (I've also added a TODO.) --- .../src/buildpack_output/mod.rs | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/libherokubuildpack/src/buildpack_output/mod.rs b/libherokubuildpack/src/buildpack_output/mod.rs index 83e1bccf..6c45ee59 100644 --- a/libherokubuildpack/src/buildpack_output/mod.rs +++ b/libherokubuildpack/src/buildpack_output/mod.rs @@ -642,28 +642,43 @@ mod test { #[test] fn test_captures() { let writer = Vec::new(); - let mut stream = BuildpackOutput::new(writer) + let mut first_stream = BuildpackOutput::new(writer) .start("Heroku Ruby Buildpack") .section("Ruby version `3.1.3` from `Gemfile.lock`") .finish() .section("Hello world") - .start_stream("Streaming stuff"); + .start_stream("Streaming with no newlines"); - let value = "stuff".to_string(); - writeln!(&mut stream, "{value}").unwrap(); + writeln!(&mut first_stream, "stuff").unwrap(); - let io = stream.finish().finish().finish(); + let mut second_stream = first_stream + .finish() + .start_stream("Streaming with blank lines and a trailing newline"); + + writeln!(&mut second_stream, "foo\nbar\n\nbaz\n").unwrap(); + + let io = second_stream.finish().finish().finish(); + // TODO: See if there is a way to remove the additional newlines in the trailing newline case. let expected = formatdoc! {" # Heroku Ruby Buildpack - Ruby version `3.1.3` from `Gemfile.lock` - Hello world - - Streaming stuff + - Streaming with no newlines stuff + - Done (< 0.1s) + - Streaming with blank lines and a trailing newline + + foo + bar + + baz + + - Done (< 0.1s) - Done (finished in < 0.1s) "};