From 7ced99bcd761eb06f6000d4cde9556fb701c6805 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 26 Jan 2021 20:49:45 +0100 Subject: [PATCH] =?UTF-8?q?Line=20information=20for=20assertion=20failures?= =?UTF-8?q?=20=F0=9F=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/typeset.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/typeset.rs b/tests/typeset.rs index 620e11a6a..cd58bdabc 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -184,8 +184,9 @@ fn test_part(src: &str, i: usize, lines: u32, env: &mut Env) -> (bool, Vec (bool, Vec (bool, SpanVec) { (compare_ref, diags) } -fn register_helpers(scope: &mut Scope, panicked: Rc>) { +struct Panic { + pos: Pos, + lhs: Option, + rhs: Option, +} + +fn register_helpers(scope: &mut Scope, panics: Rc>>) { pub fn f(_: &mut EvalContext, args: &mut Args) -> Value { let (array, dict) = args.drain(); let iter = array @@ -294,10 +310,7 @@ fn register_helpers(scope: &mut Scope, panicked: Rc>) { let lhs = args.require::(ctx, "left-hand side"); let rhs = args.require::(ctx, "right-hand side"); if lhs != rhs { - *panicked.borrow_mut() = true; - println!(" Assertion failed ❌"); - println!(" left: {:?}", lhs); - println!(" right: {:?}", rhs); + panics.borrow_mut().push(Panic { pos: args.span.start, lhs, rhs }); Value::Str(format!("(panic)")) } else { Value::None