Skip to content

Commit

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

0 comments on commit 786db97

Please sign in to comment.