From f419837b3186c37cf06cba0885a492f29b0a957c Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Fri, 15 Nov 2024 10:58:18 +0100 Subject: [PATCH] Improve the format of error messages for failing examples. - Compiler error messages are usually formatted as follows: PROGRAM:FILE_NAME:LINENO: MESSAGE - When an example fails, format it accordingly. - This has the advantage that IDEs like emacs can jump to the specified location. --- src/cli/examples.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cli/examples.rs b/src/cli/examples.rs index 0a53043d..9d446bf5 100644 --- a/src/cli/examples.rs +++ b/src/cli/examples.rs @@ -195,7 +195,7 @@ macro_rules! test_examples { eprintln!("Testing example from {}:{}", file!(), line!()); - for action in $actions.actions { + for (i, action) in $actions.actions.into_iter().enumerate() { let command = if let Some(command) = action.command() { command } else { @@ -222,7 +222,11 @@ macro_rules! test_examples { let res = cmd.assert(); intermediate = Some(res.get_output().stdout.clone()); - res.success(); + if let Err(err) = res.try_success() { + eprintln!("example:{}:{}: executing example #{}: {}", + file!(), line!(), i + 1, err); + panic!("executing example failed"); + } } } }