-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(forge): added --json argument to forge build
command
#6465
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supportive, I can see how this is useful.
smol nits
or in the CoreBuildArgs structure
the new flag should stay in BuildArgs, because it's build command specific. other commands also have a json flag, like test which would then conflict if we have it in CoreBuildArgs
we also want a test for this:
add new tests/it/build.rs
file, add contract that has an error, run build command, check output.
ref example test you can use as base
foundry/crates/forge/tests/cli/test_cmd.rs
Lines 52 to 71 in e26f4d8
// tests that warning is displayed with pattern when no tests match | |
forgetest!(warn_no_tests_match, |prj, cmd| { | |
prj.add_source( | |
"dummy", | |
r" | |
contract Dummy {} | |
", | |
) | |
.unwrap(); | |
// set up command | |
cmd.args(["test", "--match-test", "testA.*", "--no-match-test", "testB.*"]); | |
cmd.args(["--match-contract", "TestC.*", "--no-match-contract", "TestD.*"]); | |
cmd.args(["--match-path", "*TestE*", "--no-match-path", "*TestF*"]); | |
// run command and assert | |
cmd.unchecked_output().stdout_matches_path( | |
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/warn_no_tests_match.stdout"), | |
); | |
}); |
you can generate fixtures via cmd.write_fixtures(path)
and then use it
…tead of an additional parameter
…json to avoid conflict with the test args
Thank you for your valuable feedback @mattsse. I implemented all your requests. Let me know if I can do something else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks great!
I'd like to see a simple test case for json output, see instructions above
Does the one in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, I must have overlooked this, hehe
This PR adds a
--json
argument toforge compile
command to output the compilation warnings/errors in jsonMotivation
Currently integrating foundry in VSCode, my team and I quickly realized there is no output format that can be easily parsed for the
forge compile
command. The goal is thus to add ajson
to output the compilaton result in the JSON format.Solution
To implement this feature, I added a
json
field in theBuildArgs
structure and added a condition in the run method of the command to check if the argument has been used.If so, a new function
suppress_compile_with_filter_json
is called. It behaves like thesuppress_compile_with_filter
function but without throwing error when compilation errors arise.All the other modified files are due to the new function parameters which I added to indicate to the function whether to throw or not.
Additional comments
I not sure if I should have add the
json
argument in theBuildArgs
structure or in theCoreBuildArgs
structure. Let me know if I should fix this.This PR does not contain test for the new feature as I only rely on serde_json and there was no tests for the compile command beforehand.