From 786db97a032420b9adeb631ba6f82d45aaab51f3 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 a trailing newline Currently the implementation results in a double newline, which may not be what we'd prefer, however, it seems best to have a test so we can confirm if/when it's fixed. I've also added a TODO. --- .../src/buildpack_output/mod.rs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/libherokubuildpack/src/buildpack_output/mod.rs b/libherokubuildpack/src/buildpack_output/mod.rs index 83e1bccf..904f3d2b 100644 --- a/libherokubuildpack/src/buildpack_output/mod.rs +++ b/libherokubuildpack/src/buildpack_output/mod.rs @@ -642,28 +642,40 @@ 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 trailing newline"); + + writeln!(&mut second_stream, "stuff\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 trailing newline + + stuff + + - Done (< 0.1s) - Done (finished in < 0.1s) "};