From 5ea2c5e64de91b4e470dee2abee1770ae3f79122 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sun, 21 Jan 2024 15:55:42 +0100 Subject: [PATCH] fix: forge build spinner output (#6872) --- crates/common/src/compile.rs | 3 +++ crates/common/src/term.rs | 1 + crates/forge/tests/cli/build.rs | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/crates/common/src/compile.rs b/crates/common/src/compile.rs index f0dd60e020fc..1cc49e80e140 100644 --- a/crates/common/src/compile.rs +++ b/crates/common/src/compile.rs @@ -193,6 +193,9 @@ impl ProjectCompiler { r })?; + // need to drop the reporter here, so that the spinner terminates + drop(reporter); + if bail && output.has_compiler_errors() { eyre::bail!("{output}") } diff --git a/crates/common/src/term.rs b/crates/common/src/term.rs index 573bfb2f5e61..afeae0664049 100644 --- a/crates/common/src/term.rs +++ b/crates/common/src/term.rs @@ -86,6 +86,7 @@ impl Spinner { /// /// This reporter will prefix messages with a spinning cursor #[derive(Debug)] +#[must_use = "Terminates the spinner on drop"] pub struct SpinnerReporter { /// The sender to the spinner thread. sender: mpsc::Sender, diff --git a/crates/forge/tests/cli/build.rs b/crates/forge/tests/cli/build.rs index 2e97cb7491a7..240b5461442c 100644 --- a/crates/forge/tests/cli/build.rs +++ b/crates/forge/tests/cli/build.rs @@ -24,3 +24,24 @@ contract Dummy { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/compile_json.stdout"), ); }); + +// tests build output is as expected +forgetest_init!(exact_build_output, |prj, cmd| { + cmd.args(["build", "--force"]); + let (stdout, _) = cmd.unchecked_output_lossy(); + // Expected output from build + let expected = r#"Compiling 24 files with 0.8.23 +Solc 0.8.23 finished in 2.36s +Compiler run successful! +"#; + + // skip all dynamic parts of the output (numbers) + let expected_words = + expected.split(|c: char| c == ' ').filter(|w| !w.chars().next().unwrap().is_numeric()); + let output_words = + stdout.split(|c: char| c == ' ').filter(|w| !w.chars().next().unwrap().is_numeric()); + + for (expected, output) in expected_words.zip(output_words) { + assert_eq!(expected, output, "expected: {}, output: {}", expected, output); + } +});