From ee25adbed112ca809933b2963227ad33ce2afd33 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Sun, 15 Sep 2024 13:57:41 +0200 Subject: [PATCH] Update README.md test to trim whitespaced lines & update README.md --- README.md | 39 +++++++++++++++++++++------------------ lychee-bin/tests/usage.rs | 32 ++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 57ba948..ddfde36 100644 --- a/README.md +++ b/README.md @@ -315,7 +315,7 @@ Arguments: Options: -c, --config Configuration file to use - + [default: lychee.toml] -v, --verbose... @@ -333,7 +333,7 @@ Options: --max-cache-age Discard all cached requests older than this duration - + [default: 1d] --dump @@ -344,7 +344,7 @@ Options: --archive Specify the use of a specific web archive. Can be used in combination with `--suggest` - + [possible values: wayback] --suggest @@ -352,17 +352,17 @@ Options: -m, --max-redirects Maximum number of allowed redirects - + [default: 5] --max-retries Maximum number of retries per request - + [default: 3] --max-concurrency Maximum number of concurrent network requests - + [default: 128] -T, --threads @@ -370,7 +370,7 @@ Options: -u, --user-agent User agent - + [default: lychee/x.y.z] -i, --insecure @@ -420,7 +420,7 @@ Options: Test the specified file extensions for URIs when checking files locally. Multiple extensions can be separated by commas. Extensions will be checked in order of appearance. - + Example: --fallback-extensions html,htm,php,asp,aspx,jsp,cgi --header
@@ -428,20 +428,20 @@ Options: -a, --accept A List of accepted status codes for valid links - + The following accept range syntax is supported: [start]..[=]end|code. Some valid examples are: - + - 200..=204 - 200..204 - ..=204 - ..204 - 200 - + Use "lychee --accept '200..=204, 429, 500' ..." to provide a comma- separated list of accepted status codes. This example will accept 200, 201, 202, 203, 204, 429, and 500 as valid status codes. - + [default: 100..=103,200..=299] --include-fragments @@ -449,17 +449,17 @@ Options: -t, --timeout Website timeout in seconds from connect to response finished - + [default: 20] -r, --retry-wait-time Minimum wait time in seconds between retries of failed requests - + [default: 1] -X, --method Request method - + [default: get] -b, --base @@ -470,12 +470,15 @@ Options: --github-token GitHub API token to use when checking github.com links, to avoid rate limiting - + [env: GITHUB_TOKEN] --skip-missing Skip missing input files (default is to error if they don't exist) + --gitignore + Skip files that are ignored by git (default is to error if they don't exist) + --include-verbatim Find links in verbatim sections like `pre`- and `code` blocks @@ -487,13 +490,13 @@ Options: --mode Set the output display mode. Determines how results are presented in the terminal - + [default: color] [possible values: plain, color, emoji] -f, --format Output format of final status report - + [default: compact] [possible values: compact, detailed, json, markdown, raw] diff --git a/lychee-bin/tests/usage.rs b/lychee-bin/tests/usage.rs index b159489..7a1983d 100644 --- a/lychee-bin/tests/usage.rs +++ b/lychee-bin/tests/usage.rs @@ -20,6 +20,22 @@ mod readme { fs::read_to_string(readme_path).unwrap() } + /// Remove line `[default: lychee/x.y.z]` from the string + fn remove_lychee_version_line(string: &str) -> String { + string + .lines() + .filter(|line| !line.contains("[default: lychee/")) + .collect::>() + .join("\n") + } + + fn trim_empty_lines(str: &str) -> String { + str.lines() + .map(|line| if line.trim().is_empty() { "" } else { line }) + .collect::>() + .join("\n") + } + /// Test that the USAGE section in `README.md` is up to date with /// `lychee --help`. /// Only unix: might not work with windows CRLF line-endings returned from @@ -37,13 +53,7 @@ mod readme { .ok_or("Usage not found in help")?; let usage_in_help = &help_output[usage_in_help_start..]; - // Remove line `[default: lychee/0.1.0]` from the help output - let usage_in_help = usage_in_help - .lines() - .filter(|line| !line.contains("[default: lychee/")) - .collect::>() - .join("\n"); - + 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) @@ -52,13 +62,7 @@ mod readme { .find("\n```") .ok_or("End of usage not found in README")?; let usage_in_readme = &readme[usage_start..usage_start + usage_end]; - - // Remove line `[default: lychee/0.1.0]` from the README - let usage_in_readme = usage_in_readme - .lines() - .filter(|line| !line.contains("[default: lychee/")) - .collect::>() - .join("\n"); + let usage_in_readme = remove_lychee_version_line(usage_in_readme); assert_eq!(usage_in_readme, usage_in_help); Ok(())