Skip to content

Commit

Permalink
Add a test for streaming with blank lines and a trailing newline
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
edmorley committed Feb 14, 2024
1 parent aa19940 commit 67e67aa
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions libherokubuildpack/src/buildpack_output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"};
Expand Down

0 comments on commit 67e67aa

Please sign in to comment.