Update README.md test to trim whitespaced lines & update README.md

This commit is contained in:
Thomas Zahner 2024-09-15 13:57:41 +02:00
parent bd187ba0d9
commit ee25adbed1
2 changed files with 39 additions and 32 deletions

View file

@ -315,7 +315,7 @@ Arguments:
Options:
-c, --config <CONFIG_FILE>
Configuration file to use
[default: lychee.toml]
-v, --verbose...
@ -333,7 +333,7 @@ Options:
--max-cache-age <MAX_CACHE_AGE>
Discard all cached requests older than this duration
[default: 1d]
--dump
@ -344,7 +344,7 @@ Options:
--archive <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 <MAX_REDIRECTS>
Maximum number of allowed redirects
[default: 5]
--max-retries <MAX_RETRIES>
Maximum number of retries per request
[default: 3]
--max-concurrency <MAX_CONCURRENCY>
Maximum number of concurrent network requests
[default: 128]
-T, --threads <THREADS>
@ -370,7 +370,7 @@ Options:
-u, --user-agent <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 <HEADER>
@ -428,20 +428,20 @@ Options:
-a, --accept <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' <inputs>..." 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 <TIMEOUT>
Website timeout in seconds from connect to response finished
[default: 20]
-r, --retry-wait-time <RETRY_WAIT_TIME>
Minimum wait time in seconds between retries of failed requests
[default: 1]
-X, --method <METHOD>
Request method
[default: get]
-b, --base <BASE>
@ -470,12 +470,15 @@ Options:
--github-token <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 <MODE>
Set the output display mode. Determines how results are presented in the terminal
[default: color]
[possible values: plain, color, emoji]
-f, --format <FORMAT>
Output format of final status report
[default: compact]
[possible values: compact, detailed, json, markdown, raw]

View file

@ -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::<Vec<_>>()
.join("\n")
}
fn trim_empty_lines(str: &str) -> String {
str.lines()
.map(|line| if line.trim().is_empty() { "" } else { line })
.collect::<Vec<_>>()
.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::<Vec<_>>()
.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::<Vec<_>>()
.join("\n");
let usage_in_readme = remove_lychee_version_line(usage_in_readme);
assert_eq!(usage_in_readme, usage_in_help);
Ok(())