Skip to content

Conversation

wellnana
Copy link
Contributor

Add a log if evm_version is not compatible with the solc version, to avoid the confusion of the user.

@wellnana wellnana requested a review from zerosnacks August 25, 2025 15:40
@wellnana wellnana requested a review from zerosnacks August 25, 2025 15:48
@zerosnacks
Copy link
Member

Thanks! Would you mind adding a unit test for this?

For reference:

#[test]
fn test_normalize_defaults() {
figment::Jail::expect_with(|jail| {
jail.create_file(
"foundry.toml",
r"
[default]
solc = '0.8.13'
",
)?;
let loaded = Config::load().unwrap().sanitized();
assert_eq!(loaded.evm_version, EvmVersion::London);
Ok(())
});
}

This shows how to use Snapbox's .stderr_eq to assert the warning:

// Sets up a debuggable test case.
// Run with `cargo test-debugger`.
forgetest!(
#[ignore = "ran manually"]
manual_debug_setup,
|prj, cmd| {
cmd.args(["init", "--force"])
.arg(prj.root())
.assert_success()
.stdout_eq(str![[r#"
Initializing [..]...
Installing forge-std in [..] (url: Some("https://github.com/foundry-rs/forge-std"), tag: None)
Installed forge-std[..]
Initialized forge project
"#]])
.stderr_eq(str![[r#"
Warning: Target directory is not empty, but `--force` was specified
...
"#]]);

Thanks!

@wellnana
Copy link
Contributor Author

Thanks! Would you mind adding a unit test for this?

For reference:

#[test]
fn test_normalize_defaults() {
figment::Jail::expect_with(|jail| {
jail.create_file(
"foundry.toml",
r"
[default]
solc = '0.8.13'
",
)?;
let loaded = Config::load().unwrap().sanitized();
assert_eq!(loaded.evm_version, EvmVersion::London);
Ok(())
});
}

This shows how to use Snapbox's .stderr_eq to assert the warning:

// Sets up a debuggable test case.
// Run with `cargo test-debugger`.
forgetest!(
#[ignore = "ran manually"]
manual_debug_setup,
|prj, cmd| {
cmd.args(["init", "--force"])
.arg(prj.root())
.assert_success()
.stdout_eq(str![[r#"
Initializing [..]...
Installing forge-std in [..] (url: Some("https://github.com/foundry-rs/forge-std"), tag: None)
Installed forge-std[..]
Initialized forge project
"#]])
.stderr_eq(str![[r#"
Warning: Target directory is not empty, but `--force` was specified
...
"#]]);

Thanks!

Thanks for the suggestion! I've implemented the unit test and it passes locally.

However, I'm running into an issue where the test doesn't work properly within the forgetest integration test framework. There seems to be an integration problem that I need to investigate.

I'll need some time to figure this out.

@wellnana
Copy link
Contributor Author

@zerosnacks

  1. Add a cli test for the mismatch of evm_version and solc version
  2. use eprintln instead of warn!, warn! was not printing the message to stderr even with RUST_LOG=warn set, but println! works.

Copy link
Collaborator

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@onbjerg onbjerg merged commit d223552 into foundry-rs:master Sep 16, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Sep 16, 2025
onbjerg added a commit that referenced this pull request Sep 16, 2025
MerkleBoy pushed a commit to MerkleBoy/foundry that referenced this pull request Sep 17, 2025
* chore: check compatibility of evm_version and solc

* use 'eprintln' instead

* remove unnecessary expect

* add unit test

* fix test

* final fix

---------

Co-authored-by: 0xrusowsky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants