From 95c5a02d507a418c68cadf1c4a4a9db73111c1f8 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 27 Jul 2023 13:28:15 +0200 Subject: [PATCH] test: rewrite doc test Line numbering has changed in Rust 1.71 in the doc tests, due to an extra inserted `#[allow(unused_extern_crates)]` line. Don't test for the exact line number anymore. Signed-off-by: Harald Hoyer --- src/lib.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9ba0f28..2c58ec4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,17 +60,16 @@ //! fn main() { //! if let Err(e) = process_config_file() { //! eprintln!("Error:\n{:?}", e); -//! # assert_eq!( -//! # format!("{:?}\n", e), -//! # "\ -//! # src/lib.rs:16:51: read the config file\n\ -//! # Caused by:\n\ -//! # src/lib.rs:9:47: Reading file: \"foo.txt\"\n\ -//! # Caused by:\n\ -//! # Os { code: 2, kind: NotFound, message: \"No such file or directory\" }\n\ -//! # ", -//! # ); +//! # let s = format!("{:?}", e); +//! # let lines = s.lines().collect::>(); +//! # assert_eq!(lines.len(), 5); +//! # assert!(lines[0].starts_with("src/lib.rs:")); +//! # assert_eq!(lines[1], "Caused by:"); +//! # assert!(lines[2].starts_with("src/lib.rs:")); +//! # assert_eq!(lines[3], "Caused by:"); +//! # assert_eq!(lines[4], "Os { code: 2, kind: NotFound, message: \"No such file or directory\" }"); //! } +//! # else { panic!(); } //! } //! ``` //!