Skip to content

Commit

Permalink
test: separate success and failure of ensure_eq
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Oct 10, 2023
1 parent c152ee3 commit 86b9799
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions triton-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,24 +688,33 @@ mod tests {
assert!(initial_ram_val_error.to_string().contains("RAM values"));
}

#[test]
fn succeeding_ensure_eq_macro() {
method_with_succeeding_ensure_eq_macro().unwrap()
}

fn method_with_succeeding_ensure_eq_macro() -> Result<()> {
ensure_eq!(1, 1);
Ok(())
}

#[test]
#[should_panic(expected = "Expected `left_hand_side` to equal `right_hand_side`.")]
fn failing_ensure_eq_macro() {
method_with_failing_ensure_eq_macro().unwrap()
}

/// Invocations of the `ensure_eq!` macro for testing purposes must be wrapped in their own
/// function due to the return type requirements, which _must_ be
/// - `Result<_>` for any method invoking the `ensure_eq!` macro, and
/// - `()` for any method annotated with `#[test]`.
fn method_with_failing_ensure_eq_macro() -> Result<()> {
ensure_eq!("a", "a");
let left_hand_side = 2;
let right_hand_side = 1;
ensure_eq!(left_hand_side, right_hand_side);
Ok(())
}

#[test]
#[should_panic(expected = "Expected `left_hand_side` to equal `right_hand_side`.")]
fn ensure_eq_macro() {
method_with_failing_ensure_eq_macro().unwrap()
}

#[test]
fn nested_triton_asm_interpolation() {
let triple_write = triton_asm![write_io; 3];
Expand Down

0 comments on commit 86b9799

Please sign in to comment.