From e90abe099043862e0bc295a8ee2f551bd8e8b5aa Mon Sep 17 00:00:00 2001 From: grandizzy Date: Fri, 15 Nov 2024 14:34:14 +0200 Subject: [PATCH] feat(forge build): err if no source file in specified paths --- crates/forge/bin/cmd/build.rs | 3 +++ crates/forge/tests/cli/cmd.rs | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/forge/bin/cmd/build.rs b/crates/forge/bin/cmd/build.rs index f2a1891e2634..f803f45f6cf0 100644 --- a/crates/forge/bin/cmd/build.rs +++ b/crates/forge/bin/cmd/build.rs @@ -94,6 +94,9 @@ impl BuildArgs { let path = if joined.exists() { &joined } else { path }; files.extend(source_files_iter(path, MultiCompilerLanguage::FILE_EXTENSIONS)); } + if files.is_empty() { + eyre::bail!("No source files found in specified build paths.") + } } let format_json = shell::is_json(); diff --git a/crates/forge/tests/cli/cmd.rs b/crates/forge/tests/cli/cmd.rs index d4f3973a337a..e2e38cc3c1f1 100644 --- a/crates/forge/tests/cli/cmd.rs +++ b/crates/forge/tests/cli/cmd.rs @@ -2829,7 +2829,7 @@ Compiler run successful! "#]]); // Expect compilation to be skipped as no files have changed - cmd.arg("build").assert_success().stdout_eq(str![[r#" + cmd.forge_fuse().arg("build").assert_success().stdout_eq(str![[r#" No files changed, compilation skipped "#]]); @@ -2952,6 +2952,14 @@ Compiler run successful! [SOLC_VERSION] [ELAPSED] Compiler run successful! +"#]]); + + // Fail if no source file found. + prj.clear(); + cmd.forge_fuse(); + cmd.args(["build", "test/Dummy.sol", "--force"]).assert_failure().stderr_eq(str![[r#" +Error: No source files found in specified build paths. + "#]]); });