From adf78169da8a632d99398840d93246128f8256d5 Mon Sep 17 00:00:00 2001 From: HongboZhang Date: Tue, 12 Mar 2024 17:01:11 +0800 Subject: [PATCH 1/2] use autoloc --- assertion/assertion.mbt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/assertion/assertion.mbt b/assertion/assertion.mbt index 4c3492d11..61b893952 100644 --- a/assertion/assertion.mbt +++ b/assertion/assertion.mbt @@ -18,13 +18,17 @@ fn debug_string[T : Debug](t : T) -> String { buf.to_string() } -pub fn assert_eq[T : Debug + Eq](a : T, b : T) -> Result[Unit, String] { +pub fn assert_eq[T : Debug + Eq]( + a : T, + b : T, + ~loc : SourceLoc = _ +) -> Result[Unit, String] { if a == b { Ok(()) } else { let a = debug_string(a) let b = debug_string(b) - Err("assertion failed for `\(a) == \(b)`") + Err("FAILD:\(loc) `\(a) == \(b)`") } } @@ -42,13 +46,17 @@ test "assert_eq.ne" { } } -pub fn assert_ne[T : Debug + Eq](a : T, b : T) -> Result[Unit, String] { +pub fn assert_ne[T : Debug + Eq]( + a : T, + b : T, + ~loc : SourceLoc = _ +) -> Result[Unit, String] { if a != b { Ok(()) } else { let a = debug_string(a) let b = debug_string(b) - Err("assertion failed for `\(a) != \(b)`") + Err("FAILED:\(loc) `\(a) != \(b)`") } } From a0224282adcab31b86a16b5b098840664dc1613d Mon Sep 17 00:00:00 2001 From: HongboZhang Date: Tue, 12 Mar 2024 17:04:01 +0800 Subject: [PATCH 2/2] fix typo --- assertion/assertion.mbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assertion/assertion.mbt b/assertion/assertion.mbt index 61b893952..07344496b 100644 --- a/assertion/assertion.mbt +++ b/assertion/assertion.mbt @@ -28,7 +28,7 @@ pub fn assert_eq[T : Debug + Eq]( } else { let a = debug_string(a) let b = debug_string(b) - Err("FAILD:\(loc) `\(a) == \(b)`") + Err("FAILED:\(loc) `\(a) == \(b)`") } }