2021-04-22 22:27:12 +00:00
|
|
|
//! `lychee` is a fast, asynchronous, resource-friendly link checker.
|
|
|
|
|
//! It is able to find broken hyperlinks and mail addresses inside Markdown,
|
|
|
|
|
//! HTML, `reStructuredText`, and any other format.
|
|
|
|
|
//!
|
|
|
|
|
//! The lychee binary is a wrapper around lychee-lib, which provides
|
|
|
|
|
//! convenience functions for calling lychee from the command-line.
|
|
|
|
|
//!
|
|
|
|
|
//! Run it inside a repository with a `README.md`:
|
|
|
|
|
//! ```
|
|
|
|
|
//! lychee
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! You can also specify various types of inputs:
|
|
|
|
|
//!
|
|
|
|
|
//! Check links on a website:
|
|
|
|
|
//!
|
|
|
|
|
//! ```sh
|
|
|
|
|
//! lychee https://endler.dev/
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Check links in a remote file:
|
|
|
|
|
//! ```sh
|
|
|
|
|
//! lychee https://raw.githubusercontent.com/lycheeverse/lychee/master/README.md
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Check links in local file(s):
|
|
|
|
|
//! ```sh
|
|
|
|
|
//! lychee README.md
|
|
|
|
|
//! lychee test.html info.txt
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Check links in local files (by shell glob):
|
|
|
|
|
//! ```sh
|
|
|
|
|
//! lychee ~/projects/*/README.md
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Check links in local files (lychee supports advanced globbing and `~` expansion):
|
|
|
|
|
//! ```sh
|
|
|
|
|
//! lychee "~/projects/big_project/**/README.*"
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Ignore case when globbing and check result for each link:
|
|
|
|
|
//! ```sh
|
|
|
|
|
//! lychee --glob-ignore-case --verbose "~/projects/**/[r]eadme.*"
|
|
|
|
|
//! ```
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
#![warn(clippy::all, clippy::pedantic)]
|
|
|
|
|
#![warn(
|
|
|
|
|
absolute_paths_not_starting_with_crate,
|
|
|
|
|
invalid_html_tags,
|
|
|
|
|
missing_copy_implementations,
|
|
|
|
|
missing_debug_implementations,
|
|
|
|
|
semicolon_in_expressions_from_macros,
|
|
|
|
|
unreachable_pub,
|
|
|
|
|
unused_extern_crates,
|
|
|
|
|
variant_size_differences,
|
|
|
|
|
clippy::missing_const_for_fn
|
|
|
|
|
)]
|
|
|
|
|
#![deny(anonymous_parameters, macro_use_extern_crate, pointer_structural_match)]
|
2021-04-22 22:27:12 +00:00
|
|
|
#![deny(missing_docs)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
|
|
|
|
|
// required for apple silicon
|
|
|
|
|
use ring as _;
|
|
|
|
|
|
2021-09-03 00:12:03 +00:00
|
|
|
use std::fs::File;
|
|
|
|
|
use std::io::{self, BufRead};
|
2021-04-26 16:24:54 +00:00
|
|
|
use std::iter::FromIterator;
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
use std::{collections::HashSet, fs, str::FromStr, time::Duration};
|
|
|
|
|
|
2020-12-14 00:15:14 +00:00
|
|
|
use anyhow::{anyhow, Context, Result};
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
use headers::{authorization::Basic, Authorization, HeaderMap, HeaderMapExt, HeaderName};
|
|
|
|
|
use http::StatusCode;
|
2020-10-10 04:31:28 +00:00
|
|
|
use indicatif::{ProgressBar, ProgressStyle};
|
2021-06-16 11:03:36 +00:00
|
|
|
use lychee_lib::{ClientBuilder, ClientPool, Collector, Input, Response};
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
use openssl_sys as _; // required for vendored-openssl feature
|
2020-10-25 12:41:06 +00:00
|
|
|
use regex::RegexSet;
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
use ring as _; // required for apple silicon
|
2020-10-21 00:10:25 +00:00
|
|
|
use structopt::StructOpt;
|
2020-11-24 20:30:06 +00:00
|
|
|
use tokio::sync::mpsc;
|
2020-08-09 20:48:02 +00:00
|
|
|
|
2020-08-14 09:43:45 +00:00
|
|
|
mod options;
|
2020-11-24 20:30:06 +00:00
|
|
|
mod stats;
|
2020-08-04 22:32:37 +00:00
|
|
|
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
use crate::{
|
|
|
|
|
options::{Config, Format, LycheeOptions},
|
|
|
|
|
stats::{color_response, ResponseStats},
|
|
|
|
|
};
|
2020-08-04 22:32:37 +00:00
|
|
|
|
2020-10-26 22:31:31 +00:00
|
|
|
/// A C-like enum that can be cast to `i32` and used as process exit code.
|
|
|
|
|
enum ExitCode {
|
|
|
|
|
Success = 0,
|
|
|
|
|
// NOTE: exit code 1 is used for any `Result::Err` bubbled up to `main()` using the `?` operator.
|
|
|
|
|
// For now, 1 acts as a catch-all for everything non-link related (including config errors),
|
|
|
|
|
// until we find a way to structure the error code handling better.
|
|
|
|
|
#[allow(unused)]
|
|
|
|
|
UnexpectedFailure = 1,
|
|
|
|
|
LinkCheckFailure = 2,
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 09:48:55 +00:00
|
|
|
fn main() -> Result<()> {
|
2021-02-08 10:04:01 +00:00
|
|
|
// std::process::exit doesn't guarantee that all destructors will be ran,
|
|
|
|
|
// therefore we wrap "main" code in another function to guarantee that.
|
|
|
|
|
// See: https://doc.rust-lang.org/stable/std/process/fn.exit.html
|
|
|
|
|
// Also see: https://www.youtube.com/watch?v=zQC8T71Y8e4
|
|
|
|
|
let exit_code = run_main()?;
|
|
|
|
|
std::process::exit(exit_code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run_main() -> Result<i32> {
|
2020-12-02 22:28:37 +00:00
|
|
|
let mut opts = LycheeOptions::from_args();
|
2020-08-14 09:48:55 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
// Load a potentially existing config file and merge it into the config from the CLI
|
2020-12-02 22:28:37 +00:00
|
|
|
if let Some(c) = Config::load_from_file(&opts.config_file)? {
|
2021-09-03 00:18:58 +00:00
|
|
|
opts.config.merge(c);
|
2020-12-02 22:28:37 +00:00
|
|
|
}
|
2021-09-01 15:37:31 +00:00
|
|
|
|
|
|
|
|
// Load excludes from file
|
|
|
|
|
for path in &opts.config.exclude_file {
|
2021-09-03 00:24:02 +00:00
|
|
|
let file = File::open(path)?;
|
|
|
|
|
opts.config
|
|
|
|
|
.exclude
|
|
|
|
|
.append(&mut io::BufReader::new(file).lines().collect::<Result<_, _>>()?);
|
2021-09-01 15:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 22:28:37 +00:00
|
|
|
let cfg = &opts.config;
|
2020-10-21 00:10:25 +00:00
|
|
|
|
2021-01-06 23:10:58 +00:00
|
|
|
let runtime = match cfg.threads {
|
2020-08-14 09:48:55 +00:00
|
|
|
Some(threads) => {
|
2021-02-18 22:33:14 +00:00
|
|
|
// We define our own runtime instead of the `tokio::main` attribute
|
|
|
|
|
// since we want to make the number of threads configurable
|
2021-01-06 23:10:58 +00:00
|
|
|
tokio::runtime::Builder::new_multi_thread()
|
|
|
|
|
.worker_threads(threads)
|
2020-08-14 09:48:55 +00:00
|
|
|
.enable_all()
|
|
|
|
|
.build()?
|
|
|
|
|
}
|
|
|
|
|
None => tokio::runtime::Runtime::new()?,
|
|
|
|
|
};
|
2021-02-08 10:04:01 +00:00
|
|
|
|
|
|
|
|
runtime.block_on(run(cfg, opts.inputs()))
|
2020-08-14 09:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-24 20:30:06 +00:00
|
|
|
fn show_progress(progress_bar: &Option<ProgressBar>, response: &Response, verbose: bool) {
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
let out = color_response(&response.1);
|
2020-11-24 20:30:06 +00:00
|
|
|
if let Some(pb) = progress_bar {
|
|
|
|
|
pb.inc(1);
|
2021-02-25 20:00:06 +00:00
|
|
|
pb.set_message(&out);
|
2021-02-18 23:23:35 +00:00
|
|
|
if verbose {
|
2021-02-25 20:00:06 +00:00
|
|
|
pb.println(out);
|
2021-02-18 23:23:35 +00:00
|
|
|
}
|
2021-02-17 11:20:51 +00:00
|
|
|
} else {
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
if (response.status().is_success() || response.status().is_excluded()) && !verbose {
|
2021-02-18 23:23:35 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2021-02-25 20:00:06 +00:00
|
|
|
println!("{}", out);
|
2021-02-17 11:20:51 +00:00
|
|
|
}
|
2020-11-24 20:30:06 +00:00
|
|
|
}
|
2020-10-26 08:23:45 +00:00
|
|
|
|
2020-12-14 00:15:14 +00:00
|
|
|
fn fmt(stats: &ResponseStats, format: &Format) -> Result<String> {
|
|
|
|
|
Ok(match format {
|
|
|
|
|
Format::String => stats.to_string(),
|
2021-02-18 00:32:48 +00:00
|
|
|
Format::Json => serde_json::to_string_pretty(&stats)?,
|
2020-12-14 00:15:14 +00:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 22:28:37 +00:00
|
|
|
async fn run(cfg: &Config, inputs: Vec<Input>) -> Result<i32> {
|
2020-11-24 20:30:06 +00:00
|
|
|
let mut headers = parse_headers(&cfg.headers)?;
|
|
|
|
|
if let Some(auth) = &cfg.basic_auth {
|
2021-09-03 00:18:58 +00:00
|
|
|
let auth_header = parse_basic_auth(auth)?;
|
2020-10-26 08:23:45 +00:00
|
|
|
headers.typed_insert(auth_header);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 20:30:06 +00:00
|
|
|
let accepted = cfg.accept.clone().and_then(|a| parse_statuscodes(&a).ok());
|
2020-12-02 22:28:37 +00:00
|
|
|
let timeout = parse_timeout(cfg.timeout);
|
|
|
|
|
let max_concurrency = cfg.max_concurrency;
|
2020-11-24 20:30:06 +00:00
|
|
|
let method: reqwest::Method = reqwest::Method::from_str(&cfg.method.to_uppercase())?;
|
2020-12-04 09:44:31 +00:00
|
|
|
let include = RegexSet::new(&cfg.include)?;
|
|
|
|
|
let exclude = RegexSet::new(&cfg.exclude)?;
|
2020-11-24 20:30:06 +00:00
|
|
|
|
2021-09-02 21:10:46 +00:00
|
|
|
// Offline mode overrides the scheme
|
|
|
|
|
let schemes = if cfg.offline {
|
|
|
|
|
vec!["file".to_string()]
|
|
|
|
|
} else {
|
|
|
|
|
cfg.scheme.clone()
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-16 18:25:22 +00:00
|
|
|
let client = ClientBuilder::builder()
|
2020-12-04 09:44:31 +00:00
|
|
|
.includes(include)
|
|
|
|
|
.excludes(exclude)
|
|
|
|
|
.exclude_all_private(cfg.exclude_all_private)
|
|
|
|
|
.exclude_private_ips(cfg.exclude_private)
|
|
|
|
|
.exclude_link_local_ips(cfg.exclude_link_local)
|
|
|
|
|
.exclude_loopback_ips(cfg.exclude_loopback)
|
2021-03-29 21:28:17 +00:00
|
|
|
.exclude_mail(cfg.exclude_mail)
|
2020-11-24 20:30:06 +00:00
|
|
|
.max_redirects(cfg.max_redirects)
|
2020-12-02 22:28:37 +00:00
|
|
|
.user_agent(cfg.user_agent.clone())
|
2020-11-24 20:30:06 +00:00
|
|
|
.allow_insecure(cfg.insecure)
|
|
|
|
|
.custom_headers(headers)
|
|
|
|
|
.method(method)
|
|
|
|
|
.timeout(timeout)
|
2020-12-02 22:28:37 +00:00
|
|
|
.github_token(cfg.github_token.clone())
|
2021-09-02 21:10:46 +00:00
|
|
|
.schemes(HashSet::from_iter(schemes))
|
2020-11-24 20:30:06 +00:00
|
|
|
.accepted(accepted)
|
2021-09-04 01:21:54 +00:00
|
|
|
.require_https(cfg.require_https)
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
.build()
|
2021-04-16 18:25:22 +00:00
|
|
|
.client()
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
.map_err(|e| anyhow!(e))?;
|
2020-11-24 20:30:06 +00:00
|
|
|
|
2021-06-22 22:18:12 +00:00
|
|
|
let links = Collector::new(cfg.base.clone(), cfg.skip_missing, max_concurrency)
|
|
|
|
|
.collect_links(&inputs)
|
|
|
|
|
.await
|
|
|
|
|
.map_err(|e| anyhow!(e))?;
|
2021-02-17 11:20:51 +00:00
|
|
|
|
2021-09-06 14:10:48 +00:00
|
|
|
if cfg.dump {
|
|
|
|
|
for link in links {
|
|
|
|
|
if !client.filtered(&link.uri) {
|
|
|
|
|
println!("{}", link);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Ok(ExitCode::Success as i32);
|
|
|
|
|
}
|
|
|
|
|
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
let pb = if cfg.no_progress {
|
|
|
|
|
None
|
|
|
|
|
} else {
|
|
|
|
|
let bar =
|
|
|
|
|
ProgressBar::new(links.len() as u64).with_style(ProgressStyle::default_bar().template(
|
2021-02-18 23:23:35 +00:00
|
|
|
"{spinner:.red.bright} {pos}/{len:.dim} [{elapsed_precise}] {bar:25} {wide_msg}",
|
|
|
|
|
));
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
bar.enable_steady_tick(100);
|
|
|
|
|
Some(bar)
|
2020-10-10 04:31:28 +00:00
|
|
|
};
|
2020-11-24 20:30:06 +00:00
|
|
|
|
2021-01-06 23:10:58 +00:00
|
|
|
let (send_req, recv_req) = mpsc::channel(max_concurrency);
|
2020-11-24 20:30:06 +00:00
|
|
|
let (send_resp, mut recv_resp) = mpsc::channel(max_concurrency);
|
|
|
|
|
|
|
|
|
|
let mut stats = ResponseStats::new();
|
|
|
|
|
|
|
|
|
|
let bar = pb.clone();
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
for link in links {
|
|
|
|
|
if let Some(pb) = &bar {
|
|
|
|
|
pb.set_message(&link.to_string());
|
|
|
|
|
};
|
|
|
|
|
send_req.send(link).await.unwrap();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
// Start receiving requests
|
2020-11-24 20:30:06 +00:00
|
|
|
tokio::spawn(async move {
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
let clients = vec![client; max_concurrency];
|
2020-11-24 20:30:06 +00:00
|
|
|
let mut clients = ClientPool::new(send_resp, recv_req, clients);
|
|
|
|
|
clients.listen().await;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
while let Some(response) = recv_resp.recv().await {
|
|
|
|
|
show_progress(&pb, &response, cfg.verbose);
|
|
|
|
|
stats.add(response);
|
2020-10-10 04:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-24 20:30:06 +00:00
|
|
|
// Note that print statements may interfere with the progress bar, so this
|
|
|
|
|
// must go before printing the stats
|
|
|
|
|
if let Some(pb) = &pb {
|
2021-02-25 20:00:06 +00:00
|
|
|
pb.finish_and_clear();
|
2020-08-13 17:58:25 +00:00
|
|
|
}
|
2020-10-10 04:31:28 +00:00
|
|
|
|
2021-02-17 11:22:31 +00:00
|
|
|
let stats_formatted = fmt(&stats, &cfg.format)?;
|
2020-12-14 00:15:14 +00:00
|
|
|
if let Some(output) = &cfg.output {
|
2021-02-17 11:22:31 +00:00
|
|
|
fs::write(output, stats_formatted).context("Cannot write status output to file")?;
|
|
|
|
|
} else {
|
2021-03-14 18:59:52 +00:00
|
|
|
if cfg.verbose && !stats.is_empty() {
|
|
|
|
|
// separate summary from the verbose list of links above
|
|
|
|
|
println!();
|
|
|
|
|
}
|
|
|
|
|
// we assume that the formatted stats don't have a final newline
|
|
|
|
|
println!("{}", stats_formatted);
|
2020-12-14 00:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
if stats.is_success() {
|
|
|
|
|
Ok(ExitCode::Success as i32)
|
|
|
|
|
} else {
|
|
|
|
|
Ok(ExitCode::LinkCheckFailure as i32)
|
2020-10-26 22:31:31 +00:00
|
|
|
}
|
2020-08-04 22:32:37 +00:00
|
|
|
}
|
2020-08-14 13:24:41 +00:00
|
|
|
|
2020-11-24 20:30:06 +00:00
|
|
|
fn read_header(input: &str) -> Result<(String, String)> {
|
2020-08-14 13:24:41 +00:00
|
|
|
let elements: Vec<_> = input.split('=').collect();
|
|
|
|
|
if elements.len() != 2 {
|
|
|
|
|
return Err(anyhow!(
|
|
|
|
|
"Header value should be of the form key=value, got {}",
|
|
|
|
|
input
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
Ok((elements[0].into(), elements[1].into()))
|
|
|
|
|
}
|
|
|
|
|
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
const fn parse_timeout(timeout: usize) -> Duration {
|
2020-12-02 22:28:37 +00:00
|
|
|
Duration::from_secs(timeout as u64)
|
2020-08-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-24 20:30:06 +00:00
|
|
|
fn parse_headers<T: AsRef<str>>(headers: &[T]) -> Result<HeaderMap> {
|
2020-08-14 13:24:41 +00:00
|
|
|
let mut out = HeaderMap::new();
|
|
|
|
|
for header in headers {
|
2020-11-24 20:30:06 +00:00
|
|
|
let (key, val) = read_header(header.as_ref())?;
|
2020-08-14 13:24:41 +00:00
|
|
|
out.insert(
|
|
|
|
|
HeaderName::from_bytes(key.as_bytes())?,
|
|
|
|
|
val.parse().unwrap(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
Ok(out)
|
|
|
|
|
}
|
|
|
|
|
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
fn parse_statuscodes<T: AsRef<str>>(accept: T) -> Result<HashSet<StatusCode>> {
|
2020-08-17 23:17:26 +00:00
|
|
|
let mut statuscodes = HashSet::new();
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
for code in accept.as_ref().split(',') {
|
|
|
|
|
let code: StatusCode = StatusCode::from_bytes(code.as_bytes())?;
|
2020-08-17 23:17:26 +00:00
|
|
|
statuscodes.insert(code);
|
|
|
|
|
}
|
2020-11-24 20:30:06 +00:00
|
|
|
Ok(statuscodes)
|
2020-08-17 23:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-26 08:23:45 +00:00
|
|
|
fn parse_basic_auth(auth: &str) -> Result<Authorization<Basic>> {
|
|
|
|
|
let params: Vec<_> = auth.split(':').collect();
|
|
|
|
|
if params.len() != 2 {
|
|
|
|
|
return Err(anyhow!(
|
|
|
|
|
"Basic auth value should be of the form username:password, got {}",
|
|
|
|
|
auth
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
Ok(Authorization::basic(params[0], params[1]))
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 13:24:41 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod test {
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
use std::{array, collections::HashSet};
|
2021-04-12 12:40:39 +00:00
|
|
|
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
use headers::{HeaderMap, HeaderMapExt};
|
2020-08-17 23:17:26 +00:00
|
|
|
use http::StatusCode;
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
use pretty_assertions::assert_eq;
|
2020-08-14 13:24:41 +00:00
|
|
|
use reqwest::header;
|
|
|
|
|
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
use super::{parse_basic_auth, parse_headers, parse_statuscodes};
|
|
|
|
|
|
2020-08-14 13:24:41 +00:00
|
|
|
#[test]
|
|
|
|
|
fn test_parse_custom_headers() {
|
|
|
|
|
let mut custom = HeaderMap::new();
|
|
|
|
|
custom.insert(header::ACCEPT, "text/html".parse().unwrap());
|
2020-11-24 20:30:06 +00:00
|
|
|
assert_eq!(parse_headers(&["accept=text/html"]).unwrap(), custom);
|
2020-08-14 13:24:41 +00:00
|
|
|
}
|
2020-08-17 23:17:26 +00:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_parse_statuscodes() {
|
2020-11-24 20:30:06 +00:00
|
|
|
let actual = parse_statuscodes("200,204,301").unwrap();
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
let expected = array::IntoIter::new([
|
2020-11-24 20:30:06 +00:00
|
|
|
StatusCode::OK,
|
|
|
|
|
StatusCode::NO_CONTENT,
|
|
|
|
|
StatusCode::MOVED_PERMANENTLY,
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
])
|
|
|
|
|
.collect::<HashSet<_>>();
|
|
|
|
|
|
2020-08-17 23:17:26 +00:00
|
|
|
assert_eq!(actual, expected);
|
|
|
|
|
}
|
2020-10-26 08:23:45 +00:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_parse_basic_auth() {
|
|
|
|
|
let mut expected = HeaderMap::new();
|
|
|
|
|
expected.insert(
|
|
|
|
|
header::AUTHORIZATION,
|
|
|
|
|
"Basic YWxhZGluOmFicmV0ZXNlc2Ftbw==".parse().unwrap(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let mut actual = HeaderMap::new();
|
|
|
|
|
let auth_header = parse_basic_auth("aladin:abretesesamo").unwrap();
|
|
|
|
|
actual.typed_insert(auth_header);
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
|
2020-10-26 08:23:45 +00:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
}
|
2020-08-14 13:24:41 +00:00
|
|
|
}
|