mirror of
https://github.com/Hopiu/lychee.git
synced 2026-04-23 14:34:46 +00:00
* Add more fine-grained error types; remove generic IO error * Update error message for missing file * Remove missing `Error` suffix * Rename ErrorKind::Github to ErrorKind::GithubRequest for consistency with NetworkRequest
65 lines
1.9 KiB
Rust
65 lines
1.9 KiB
Rust
#[cfg(test)]
|
|
mod cli {
|
|
use std::{error::Error, fs::File, io::Write};
|
|
|
|
use assert_cmd::Command;
|
|
use predicates::str::contains;
|
|
|
|
type Result<T> = std::result::Result<T, Box<dyn Error>>;
|
|
|
|
fn main_command() -> Command {
|
|
// this gets the "main" binary name (e.g. `lychee`)
|
|
Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Couldn't get cargo package name")
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_local_file() -> Result<()> {
|
|
let dir = tempfile::tempdir()?;
|
|
let index_path = dir.path().join("index.html");
|
|
let mut index = File::create(&index_path)?;
|
|
writeln!(index, r#"<a href="./foo.html">Foo</a>"#)?;
|
|
|
|
let foo_path = dir.path().join("foo.html");
|
|
File::create(&foo_path)?;
|
|
|
|
let mut cmd = main_command();
|
|
cmd.arg(index_path)
|
|
.arg("--no-progress")
|
|
.arg("--verbose")
|
|
.env_clear()
|
|
.assert()
|
|
.success()
|
|
.stdout(contains("1 Total"))
|
|
.stdout(contains("foo.html"));
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_local_dir() -> Result<()> {
|
|
let dir = tempfile::tempdir()?;
|
|
let index_path = dir.path().join("index.html");
|
|
let mut index = File::create(&index_path)?;
|
|
writeln!(index, r#"<a href="./foo.html">Foo</a>"#)?;
|
|
writeln!(index, r#"<a href="./bar.md">Bar</a>"#)?;
|
|
|
|
let foo_path = dir.path().join("foo.html");
|
|
File::create(&foo_path)?;
|
|
let bar_path = dir.path().join("bar.md");
|
|
File::create(&bar_path)?;
|
|
|
|
let mut cmd = main_command();
|
|
cmd.arg(dir.path())
|
|
.arg("--no-progress")
|
|
.arg("--verbose")
|
|
.env_clear()
|
|
.assert()
|
|
.success()
|
|
.stdout(contains("2 Total"))
|
|
.stdout(contains("2 OK"))
|
|
.stdout(contains("foo.html"))
|
|
.stdout(contains("bar.md"));
|
|
|
|
Ok(())
|
|
}
|
|
}
|