Skip to content

Commit

Permalink
feat(forge): --watch coverage (#9702)
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-atreya authored Jan 17, 2025
1 parent 00c944b commit 1f48a34
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
10 changes: 9 additions & 1 deletion crates/forge/bin/cmd/coverage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{install, test::TestArgs};
use super::{install, test::TestArgs, watch::WatchArgs};
use alloy_primitives::{map::HashMap, Address, Bytes, U256};
use clap::{Parser, ValueEnum, ValueHint};
use eyre::{Context, Result};
Expand Down Expand Up @@ -319,6 +319,14 @@ impl CoverageArgs {
}
Ok(())
}

pub(crate) fn is_watch(&self) -> bool {
self.test.is_watch()
}

pub(crate) fn watch(&self) -> &WatchArgs {
&self.test.watch
}
}

/// Coverage reports to generate.
Expand Down
16 changes: 14 additions & 2 deletions crates/forge/bin/cmd/watch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use super::{build::BuildArgs, doc::DocArgs, snapshot::GasSnapshotArgs, test::TestArgs};
use super::{
build::BuildArgs, coverage::CoverageArgs, doc::DocArgs, snapshot::GasSnapshotArgs,
test::TestArgs,
};
use alloy_primitives::map::HashSet;
use clap::Parser;
use eyre::Result;
use foundry_cli::utils::{self, FoundryPathExt};
use foundry_cli::utils::{self, FoundryPathExt, LoadConfig};
use foundry_config::Config;
use parking_lot::Mutex;
use std::{
Expand Down Expand Up @@ -316,6 +319,15 @@ pub async fn watch_test(args: TestArgs) -> Result<()> {
Ok(())
}

pub async fn watch_coverage(args: CoverageArgs) -> Result<()> {
let config = args.load_config();
let config = args.watch().watchexec_config(|| [config.test, config.src])?;

run(config).await?;

Ok(())
}

/// Executes a [`Watchexec`] that listens for changes in the project's sources directory
pub async fn watch_doc(args: DocArgs) -> Result<()> {
let src_path = args.config()?.src;
Expand Down
8 changes: 7 additions & 1 deletion crates/forge/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ fn run() -> Result<()> {
}
}
ForgeSubcommand::Script(cmd) => utils::block_on(cmd.run_script()),
ForgeSubcommand::Coverage(cmd) => utils::block_on(cmd.run()),
ForgeSubcommand::Coverage(cmd) => {
if cmd.is_watch() {
utils::block_on(watch::watch_coverage(cmd))
} else {
utils::block_on(cmd.run())
}
}
ForgeSubcommand::Bind(cmd) => cmd.run(),
ForgeSubcommand::Build(cmd) => {
if cmd.is_watch() {
Expand Down

0 comments on commit 1f48a34

Please sign in to comment.