use crate::util; use assert_cmd::Command; use regex::Regex; use std::{fs::read_to_string, path::Path}; #[test] fn clippy() { Command::new("cargo") .args([ "+nightly", "clippy", "--all-features", "--all-targets", "--", "--deny=warnings", ]) .assert() .success(); } #[test] fn dylint() { Command::new("cargo") .args(["dylint", "--all", "--", "--all-features", "--all-targets"]) .env("DYLINT_RUSTFLAGS", "--deny warnings") .assert() .success(); } #[test] fn markdown_link_check() { let tempdir = util::tempdir().unwrap(); // smoelius: Pin `markdown-link-check` to version 3.11 until the following issue is resolved: // https://github.com/tcort/markdown-link-check/issues/304 Command::new("npm") .args(["install", "markdown-link-check@3.11"]) .current_dir(&tempdir) .assert() .success(); let readme_md = Path::new(env!("CARGO_MANIFEST_DIR")).join("README.md"); Command::new("npx") .args(["markdown-link-check", &readme_md.to_string_lossy()]) .current_dir(&tempdir) .assert() .success(); } #[test] fn readme_reference_links_are_sorted() { let re = Regex::new(r"^\[[^\]]*\]:").unwrap(); let readme = read_to_string("README.md").unwrap(); let links = readme .lines() .filter(|line| re.is_match(line)) .collect::>(); let mut links_sorted = links.clone(); links_sorted.sort_unstable(); assert_eq!(links_sorted, links); } #[test] fn readme_reference_links_are_used() { let re = Regex::new(r"(?m)^(\[[^\]]*\]):").unwrap(); let readme = read_to_string("README.md").unwrap(); for captures in re.captures_iter(&readme) { assert_eq!(2, captures.len()); let m = captures.get(1).unwrap(); assert!( readme[..m.start()].contains(m.as_str()), "{} is unused", m.as_str() ); } }