Back to questions
JuniorTheoryCommon
What happens when this program is built and run?
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn main() {
assert_eq!(add(2, 2), 5);
println!("done");
}It compiles and panics
- Expecting
done, as if a failed assertion were a warning or skipped outside tests:assert_eq!always runs and panics when the two sides differ. - Expecting a build error because
assert_eq!lives only in#[test]functions: it is a normal macro and works inmaintoo.
- What two value lines does the panic message show, and which side is
left? - Inside a
#[test]function, what wouldcargo testreport for this assertion?