Skip to content

Commit

Permalink
Add test for CARGO_TARGET_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Oct 16, 2020
1 parent 1fcfa5a commit efbe289
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions tests/simple_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
Expand All @@ -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")
Expand All @@ -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();
}
}

0 comments on commit efbe289

Please sign in to comment.