-
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
) Native assertion cheatcodes
#6803
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.
great draft!
one nit re error messages, I think we want real error types via thiserror, so we can test formatting etc
maybe an enum or several standalone error structs
enum AssertErr {
....
}
wdyt @DaniPopes
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.
good draft! looking good so far imo.
Wonder if we can ship improvements incrementally? so we can get the equivalent native cheats in, and then improve errors and diagnostics in followups
crates/cheatcodes/src/test/assert.rs
Outdated
use crate::{Cheatcode, Cheatcodes, Result, Vm::*}; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
#[error("Assertion failed")] |
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.
#[error("Assertion failed")] | |
#[error("assertion failed")] |
crates/cheatcodes/src/test/assert.rs
Outdated
|
||
impl Cheatcode for assertTrue_0Call { | ||
fn apply(&self, _state: &mut Cheatcodes) -> Result { | ||
Ok(assert_true(self.condition).map_err(|_| "Assertion failed")?) |
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.
I believe
Ok(assert_true(self.condition).map_err(|_| "Assertion failed")?) | |
assert_true(self.condition).map_err(|e| e.to_string().into()) |
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 kind of conflicts with your other suggestion to rename error message, by default error on assert is "Assertion failed", and in that case it would be "assertion failed"
which one should I do?
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.
I don't see how they conflict, and error messages should be lowercase
921f1ab
to
be2523d
Compare
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!
This should speed up compilation and finally makes tests fail as soon as an assert fails.
one thing we need to decide is, do we want to include them in the Vm interface or mark them internal and switch out all the assert Code in forge-std so function assertEq just calls vm.assertEq?
wdyt @mds1 @DaniPopes @Evalir
forge
) Native assertion cheatcodesforge
) Native assertion cheatcodes
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 awesome to me.
I think we should just take the bandaid off and include them in the vm interface.
One thing to consider re compile times is that after this PR we will have enough native cheatcodes to drop |
Per @klkvr's comment, since users won't yet be able to find+replace all Once we also have everything 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.
sgtm!
pending @DaniPopes
crates/cheatcodes/src/test/assert.rs
Outdated
|
||
impl Cheatcode for assertTrue_0Call { | ||
fn apply(&self, _state: &mut Cheatcodes) -> Result { | ||
Ok(assert_true(self.condition).map_err(|_| "Assertion failed")?) |
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.
I don't see how they conflict, and error messages should be lowercase
Motivation
Adds native
assert*
cheatcodes toVm
Solution