mirror of
https://github.com/Hopiu/lychee.git
synced 2026-05-04 03:44:44 +00:00
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
|
|
//! The rest of the integration tests make heavy use of example domains, so
|
||
|
|
//! we use a separate module for testing that the exclusion of these domains
|
||
|
|
//! works as expected for normal users.
|
||
|
|
#[cfg(test)]
|
||
|
|
mod cli {
|
||
|
|
use std::{
|
||
|
|
error::Error,
|
||
|
|
path::{Path, PathBuf},
|
||
|
|
};
|
||
|
|
|
||
|
|
use assert_cmd::Command;
|
||
|
|
use predicates::str::contains;
|
||
|
|
|
||
|
|
type Result<T> = std::result::Result<T, Box<dyn Error>>;
|
||
|
|
|
||
|
|
fn fixtures_path() -> PathBuf {
|
||
|
|
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||
|
|
.parent()
|
||
|
|
.unwrap()
|
||
|
|
.join("fixtures")
|
||
|
|
}
|
||
|
|
|
||
|
|
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")
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn test_exclude_example_domains() -> Result<()> {
|
||
|
|
let mut cmd = main_command();
|
||
|
|
let input = fixtures_path().join("TEST_EXAMPLE_DOMAINS.md");
|
||
|
|
|
||
|
|
let cmd = cmd
|
||
|
|
.arg(input)
|
||
|
|
.arg("--dump")
|
||
|
|
.assert()
|
||
|
|
.success()
|
||
|
|
.stdout(contains("https://github.com/rust-lang/rust"))
|
||
|
|
.stdout(contains("https://www.rust-lang.org/"));
|
||
|
|
|
||
|
|
let output = cmd.get_output();
|
||
|
|
let output = std::str::from_utf8(&output.stdout).unwrap();
|
||
|
|
assert_eq!(output.lines().count(), 2);
|
||
|
|
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
}
|