Skip to content

Commit

Permalink
fix: forge build spinner output (#6872)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jan 21, 2024
1 parent d91748a commit 5ea2c5e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/common/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
Expand Down
1 change: 1 addition & 0 deletions crates/common/src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpinnerMsg>,
Expand Down
21 changes: 21 additions & 0 deletions crates/forge/tests/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

0 comments on commit 5ea2c5e

Please sign in to comment.