diff --git a/README.md b/README.md index 6686d3ccf8..0af194522e 100644 --- a/README.md +++ b/README.md @@ -325,8 +325,8 @@ Please follow the [GitHub App Setup][github-app-setup] example. There is an extensive list of command line parameters to customize the behavior. See below for a full list. -```text -lychee is a tool to detect broken URLs and mail addresses in local files and websites. It supports Markdown and HTML explicitly and works well with many plain text file formats. +```help-message +lychee is a fast, asynchronous link checker which detects broken URLs and mail addresses in local files and websites. It supports Markdown and HTML and works well with many plain text file formats. lychee is powered by lychee-lib, the Rust library for link checking. @@ -497,7 +497,7 @@ Options: Empty lines are also ignored. --generate - Generate special output (e.g. man page) instead of performing link checking + Generate special output (e.g. the man page) instead of performing link checking [possible values: man] diff --git a/lychee-bin/src/commands/generate.rs b/lychee-bin/src/commands/generate.rs index c6917963d1..1ee384eeac 100644 --- a/lychee-bin/src/commands/generate.rs +++ b/lychee-bin/src/commands/generate.rs @@ -128,7 +128,7 @@ mod tests { // Must contain description assert!(roff.contains("lychee \\- A fast, async link checker")); assert!(roff.contains( - "lychee is a fast, async link checker which detects broken URLs and mail addresses in local files and websites." + "lychee is a fast, asynchronous link checker which detects broken URLs and mail addresses in local files and websites. It supports Markdown and HTML and works well with many plain text file formats." )); assert!( roff.contains("lychee is powered by lychee\\-lib, the Rust library for link checking.") diff --git a/lychee-bin/src/options.rs b/lychee-bin/src/options.rs index 8a4b274d2e..847a6edffc 100644 --- a/lychee-bin/src/options.rs +++ b/lychee-bin/src/options.rs @@ -312,9 +312,9 @@ impl HeaderMapExt for HeaderMap { } } -/// lychee is a fast, async link checker which detects broken URLs and mail addresses in -/// local files and websites. It supports Markdown and HTML explicitly -/// and works well with many plain text file formats. +/// lychee is a fast, asynchronous link checker which detects broken URLs and mail addresses +/// in local files and websites. It supports Markdown and HTML and works well +/// with many plain text file formats. /// /// lychee is powered by lychee-lib, the Rust library for link checking. #[derive(Parser, Debug)] diff --git a/lychee-bin/tests/usage.rs b/lychee-bin/tests/usage.rs index 2b7d915581..469ca60efe 100644 --- a/lychee-bin/tests/usage.rs +++ b/lychee-bin/tests/usage.rs @@ -2,8 +2,8 @@ mod readme { use assert_cmd::Command; use pretty_assertions::assert_eq; - - const USAGE_STRING: &str = "Usage: lychee [OPTIONS] [inputs]...\n"; + use regex::Regex; + use test_utils::load_readme_text; fn main_command() -> Command { // this gets the "main" binary name (e.g. `lychee`) @@ -34,22 +34,15 @@ mod readme { #[test] #[cfg(unix)] fn test_readme_usage_up_to_date() -> Result<(), Box> { - use test_utils::load_readme_text; - + const BEGIN: &str = "```help-message\n"; let mut cmd = main_command(); let help_cmd = cmd.env_clear().arg("--help").assert().success(); - let help_output = std::str::from_utf8(&help_cmd.get_output().stdout)?; - let usage_in_help_start = help_output - .find(USAGE_STRING) - .ok_or("Usage not found in help")?; - let usage_in_help = &help_output[usage_in_help_start..]; + let usage_in_help = std::str::from_utf8(&help_cmd.get_output().stdout)?; let usage_in_help = trim_empty_lines(&remove_lychee_version_line(usage_in_help)); let readme = load_readme_text!(); - let usage_start = readme - .find(USAGE_STRING) - .ok_or("Usage not found in README")?; + let usage_start = readme.find(BEGIN).ok_or("Usage not found in README")? + BEGIN.len(); let usage_end = readme[usage_start..] .find("\n```") .ok_or("End of usage not found in README")?; @@ -66,36 +59,43 @@ mod readme { #[test] #[cfg(unix)] fn test_arguments_ordered_alphabetically() -> Result<(), Box> { - use regex::Regex; - let mut cmd = main_command(); - let help_cmd = cmd.env_clear().arg("--help").assert().success(); let help_text = std::str::from_utf8(&help_cmd.get_output().stdout)?; - let regex = Regex::new(r"^\s{2,6}(-(?[a-zA-Z]),)? --(?[a-zA-Z-]*)").unwrap(); + let regex = Regex::new(r"^\s{2,6}(?:-(?[a-zA-Z]),)?\s--(?[a-zA-Z-]+)")?; let arguments: Vec<&str> = help_text .lines() .filter_map(|line| { let captures = regex.captures(line)?; - Some( - // Short flags (-a) take precedence over the long flags (--a) - captures - .name("short") - .unwrap_or_else(|| captures.name("long").unwrap()) - .as_str(), - ) + captures + .name("short") + .or_else(|| captures.name("long")) + .map(|m| m.as_str()) }) .collect(); let mut sorted = arguments.clone(); sorted.sort_by_key(|arg| arg.to_lowercase()); - assert_eq!( - arguments, sorted, - "Arguments are not sorted alphabetically: {arguments:?}", - ); + if arguments != sorted { + // Find all positions where order differs + let mismatches: Vec<_> = arguments + .iter() + .zip(&sorted) + .enumerate() + .filter(|(_, (a, b))| a != b) + .map(|(i, (actual, expected))| format!(" [{i}] '{actual}' should be '{expected}'")) + .collect(); + + panic!( + "\nArguments are not sorted alphabetically!\n\nMismatches:\n{}\n\nFull actual order:\n{:?}\n\nFull expected order:\n{:?}", + mismatches.join("\n"), + arguments, + sorted + ); + } Ok(()) }