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): disable artifacts for coverage #9692

Merged
merged 5 commits into from
Jan 21, 2025
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
10 changes: 9 additions & 1 deletion crates/forge/bin/cmd/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ impl CoverageArgs {
/// Builds the project.
fn build(&self, config: &Config) -> Result<(Project, ProjectCompileOutput)> {
// Set up the project
let mut project = config.create_project(false, false)?;
let mut project = config.create_project(false, true)?;

if self.ir_minimum {
// print warning message
sh_warn!("{}", concat!(
Expand Down Expand Up @@ -138,6 +139,13 @@ impl CoverageArgs {
project.settings.solc.optimizer.details = None;
project.settings.solc.via_ir = None;
}
let mut warning =
"optimizer settings have been disabled for accurate coverage reports".to_string();
if !self.ir_minimum {
warning += ", if you encounter \"stack too deep\" errors, consider using `--ir-minimum` which enables viaIR with minimum optimization resolving most of the errors";
}

sh_warn!("{warning}")?;

let output = ProjectCompiler::default()
.compile(&project)?
Expand Down
62 changes: 61 additions & 1 deletion crates/forge/tests/cli/coverage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use foundry_common::fs;
use foundry_common::fs::{self, files_with_ext};
use foundry_test_utils::{
snapbox::{Data, IntoData},
TestCommand, TestProject,
Expand Down Expand Up @@ -1691,3 +1691,63 @@ contract AContract {
fn assert_lcov(cmd: &mut TestCommand, data: impl IntoData) {
cmd.args(["--report=lcov", "--report-file"]).assert_file(data.into_data());
}

forgetest!(no_artifacts_written, |prj, cmd| {
prj.insert_ds_test();
prj.add_source(
"AContract.sol",
r#"
contract AContract {
int public i;

function init() public {
i = 0;
}

function foo() public {
i = 1;
}
}
"#,
)
.unwrap();

prj.add_source(
"AContractTest.sol",
r#"
import "./test.sol";
import {AContract} from "./AContract.sol";

contract AContractTest is DSTest {
AContract a;

function setUp() public {
a = new AContract();
a.init();
}

function testFoo() public {
a.foo();
}
}
"#,
)
.unwrap();

cmd.forge_fuse().arg("coverage").assert_success().stdout_eq(str![[r#"
...
╭-------------------+---------------+---------------+---------------+---------------╮
| File | % Lines | % Statements | % Branches | % Funcs |
+===================================================================================+
| src/AContract.sol | 100.00% (4/4) | 100.00% (2/2) | 100.00% (0/0) | 100.00% (2/2) |
|-------------------+---------------+---------------+---------------+---------------|
| Total | 100.00% (4/4) | 100.00% (2/2) | 100.00% (0/0) | 100.00% (2/2) |
╰-------------------+---------------+---------------+---------------+---------------╯
...
"#]]);

// no artifacts are to be written
let files = files_with_ext(prj.artifacts(), "json").collect::<Vec<_>>();

assert!(files.is_empty());
});
Loading