From da953f06939e91c3c0dae25012a44c3c82ea0182 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sun, 24 Dec 2023 08:48:03 +0100 Subject: [PATCH] Don't throw an error when there is no features in Cargo.toml Because this could happen if the Cargo.toml is "normalized". Instead, show a note in the documentation Fixes #20 --- lib.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib.rs b/lib.rs index 480f3bc..21f6520 100644 --- a/lib.rs +++ b/lib.rs @@ -359,7 +359,7 @@ fn process_toml(cargo_toml: &str, args: &Args) -> Result { return Err("Found comment not associated with a feature".into()); } if features.is_empty() { - return Err("Could not find documented features in Cargo.toml".into()); + return Ok("*No documented features in Cargo.toml*".into()); } let mut result = String::new(); for (f, top, comment) in features { @@ -585,26 +585,30 @@ default = ["feat1", "something_else"] } #[test] - fn parse_error1() { - test_error( + fn no_features() { + let r = process_toml( r#" [features] [dependencies] foo = 4; "#, - "Could not find documented features", - ); + &Args::default(), + ) + .unwrap(); + assert_eq!(r, "*No documented features in Cargo.toml*"); } #[test] - fn parse_error2() { - test_error( + fn no_features2() { + let r = process_toml( r#" [packages] [dependencies] "#, - "Could not find documented features", - ); + &Args::default(), + ) + .unwrap(); + assert_eq!(r, "*No documented features in Cargo.toml*"); } #[test]