Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take CARGO_TARGET_DIR into account #66

Merged
merged 2 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn determine_dir() -> PathBuf {
.unwrap();
let package_name = package_name.replace("-", "_");

Path::new("target").join("doc").join(package_name)
manifest.target_directory.join("doc").join(package_name)
}
Err(_) => {
error!("Could not find a Cargo.toml.");
Expand Down
59 changes: 41 additions & 18 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() -> assert_cmd::assert::Assert {
// generate docs
Command::new("cargo")
.arg("doc")
Expand All @@ -48,6 +35,42 @@ mod simple_project {
.arg("deadlinks")
.current_dir("./tests/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().success();

// 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().success();

std::env::remove_var("CARGO_TARGET_DIR");
std::env::set_var("CARGO_BUILD_TARGET", "x86_64-unknown-linux-gnu");
remove_all("./tests/simple_project/target");
// This currently breaks due to a cargo bug: https://github.com/rust-lang/cargo/issues/8791
assert_doc().failure();
}
}