diff --git a/tests/simple_project.rs b/tests/simple_project.rs index 80cbfb0..0f81092 100644 --- a/tests/simple_project.rs +++ b/tests/simple_project.rs @@ -8,11 +8,8 @@ use std::process::Command; mod simple_project { use super::*; - #[test] - #[allow(unused_must_use)] - fn it_checks_okay_project_correctly() { - // cargo-deadlinks fails when docs have not been generated before - match std::fs::remove_dir_all("./tests/simple_project/target") { + fn remove_all(path: &str) { + match std::fs::remove_dir_all(path) { Ok(_) => {} Err(err) => match err.kind() { std::io::ErrorKind::NotFound => {} @@ -22,19 +19,9 @@ mod simple_project { ), }, }; - Command::cargo_bin("cargo-deadlinks") - .unwrap() - .arg("deadlinks") - .current_dir("./tests/simple_project") - .assert() - .failure() - .stdout(predicate::str::contains( - "Could not find directory \"target/doc/simple_project\".", - )) - .stdout(predicate::str::contains( - "Please run `cargo doc` before running `cargo deadlinks`.", - )); + } + fn assert_doc_succeeds() { // generate docs Command::new("cargo") .arg("doc") @@ -50,4 +37,39 @@ mod simple_project { .assert() .success(); } + + #[test] + fn it_checks_okay_project_correctly() { + use predicate::str::contains; + + std::env::remove_var("CARGO_TARGET_DIR"); + + // cargo-deadlinks fails when docs have not been generated before + remove_all("./tests/simple_project/target"); + + Command::cargo_bin("cargo-deadlinks") + .unwrap() + .arg("deadlinks") + .current_dir("./tests/simple_project") + .assert() + .failure() + .stdout( + contains("Could not find directory") + .and(contains("target/doc/simple_project\".")) + .and(contains( + "Please run `cargo doc` before running `cargo deadlinks`.", + )), + ); + + assert_doc_succeeds(); + + // NOTE: can't be parallel because of use of `set_var` + std::env::set_var("CARGO_TARGET_DIR", "target2"); + remove_all("./tests/simple_project/target2"); + assert_doc_succeeds(); + + std::env::remove_var("CARGO_TARGET_DIR"); + std::env::set_var("CARGO_BUILD_TARGET", "x86_64-unknown-linux-gnu"); + assert_doc_succeeds(); + } }