From 7be3c2f09bb58e232550d7a93d9fe6d8fce55c9e Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 21 Jan 2020 12:02:29 -0800 Subject: [PATCH] Fix cache replay including extra newlines. --- src/cargo/core/compiler/mod.rs | 3 +- tests/testsuite/cache_messages.rs | 49 ++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index febbbbbbcfa..67c5496e9ba 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1257,7 +1257,8 @@ fn replay_output_cache( if length == 0 { break; } - on_stderr_line(state, line.as_str(), package_id, &target, &mut options)?; + let trimmed = line.trim_end_matches(&['\n', '\r'][..]); + on_stderr_line(state, trimmed, package_id, &target, &mut options)?; line.clear(); } Ok(()) diff --git a/tests/testsuite/cache_messages.rs b/tests/testsuite/cache_messages.rs index e5afc00437d..9692cd23fca 100644 --- a/tests/testsuite/cache_messages.rs +++ b/tests/testsuite/cache_messages.rs @@ -1,7 +1,8 @@ //! Tests for caching compiler diagnostics. use cargo_test_support::{ - clippy_is_available, is_coarse_mtime, process, project, registry::Package, sleep_ms, + basic_manifest, clippy_is_available, is_coarse_mtime, process, project, registry::Package, + sleep_ms, }; use std::path::Path; @@ -390,3 +391,49 @@ fn doesnt_create_extra_files() { p.cargo("build").run(); assert_eq!(p.glob("target/debug/.fingerprint/foo-*/output").count(), 1); } + +#[cargo_test] +fn replay_non_json() { + // Handles non-json output. + let rustc = project() + .at("rustc") + .file("Cargo.toml", &basic_manifest("rustc_alt", "1.0.0")) + .file( + "src/main.rs", + r#" + fn main() { + eprintln!("line 1"); + eprintln!("line 2"); + let r = std::process::Command::new("rustc") + .args(std::env::args_os().skip(1)) + .status(); + std::process::exit(r.unwrap().code().unwrap_or(2)); + } + "#, + ) + .build(); + rustc.cargo("build").run(); + let p = project().file("src/lib.rs", "").build(); + p.cargo("check") + .env("RUSTC", rustc.bin("rustc_alt")) + .with_stderr( + "\ +[CHECKING] foo [..] +line 1 +line 2 +[FINISHED] dev [..] +", + ) + .run(); + + p.cargo("check") + .env("RUSTC", rustc.bin("rustc_alt")) + .with_stderr( + "\ +line 1 +line 2 +[FINISHED] dev [..] +", + ) + .run(); +}