Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: forge build spinner output #6872

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
});