Skip to content

Commit 1f48a34

Browse files
authored
feat(forge): --watch coverage (#9702)
1 parent 00c944b commit 1f48a34

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

crates/forge/bin/cmd/coverage.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{install, test::TestArgs};
1+
use super::{install, test::TestArgs, watch::WatchArgs};
22
use alloy_primitives::{map::HashMap, Address, Bytes, U256};
33
use clap::{Parser, ValueEnum, ValueHint};
44
use eyre::{Context, Result};
@@ -319,6 +319,14 @@ impl CoverageArgs {
319319
}
320320
Ok(())
321321
}
322+
323+
pub(crate) fn is_watch(&self) -> bool {
324+
self.test.is_watch()
325+
}
326+
327+
pub(crate) fn watch(&self) -> &WatchArgs {
328+
&self.test.watch
329+
}
322330
}
323331

324332
/// Coverage reports to generate.

crates/forge/bin/cmd/watch.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
use super::{build::BuildArgs, doc::DocArgs, snapshot::GasSnapshotArgs, test::TestArgs};
1+
use super::{
2+
build::BuildArgs, coverage::CoverageArgs, doc::DocArgs, snapshot::GasSnapshotArgs,
3+
test::TestArgs,
4+
};
25
use alloy_primitives::map::HashSet;
36
use clap::Parser;
47
use eyre::Result;
5-
use foundry_cli::utils::{self, FoundryPathExt};
8+
use foundry_cli::utils::{self, FoundryPathExt, LoadConfig};
69
use foundry_config::Config;
710
use parking_lot::Mutex;
811
use std::{
@@ -316,6 +319,15 @@ pub async fn watch_test(args: TestArgs) -> Result<()> {
316319
Ok(())
317320
}
318321

322+
pub async fn watch_coverage(args: CoverageArgs) -> Result<()> {
323+
let config = args.load_config();
324+
let config = args.watch().watchexec_config(|| [config.test, config.src])?;
325+
326+
run(config).await?;
327+
328+
Ok(())
329+
}
330+
319331
/// Executes a [`Watchexec`] that listens for changes in the project's sources directory
320332
pub async fn watch_doc(args: DocArgs) -> Result<()> {
321333
let src_path = args.config()?.src;

crates/forge/bin/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ fn run() -> Result<()> {
4949
}
5050
}
5151
ForgeSubcommand::Script(cmd) => utils::block_on(cmd.run_script()),
52-
ForgeSubcommand::Coverage(cmd) => utils::block_on(cmd.run()),
52+
ForgeSubcommand::Coverage(cmd) => {
53+
if cmd.is_watch() {
54+
utils::block_on(watch::watch_coverage(cmd))
55+
} else {
56+
utils::block_on(cmd.run())
57+
}
58+
}
5359
ForgeSubcommand::Bind(cmd) => cmd.run(),
5460
ForgeSubcommand::Build(cmd) => {
5561
if cmd.is_watch() {

0 commit comments

Comments
 (0)