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

How to find binary from integration test? #5758

Closed
ehuss opened this issue Jul 21, 2018 · 1 comment · Fixed by #7697
Closed

How to find binary from integration test? #5758

ehuss opened this issue Jul 21, 2018 · 1 comment · Fixed by #7697

Comments

@ehuss
Copy link
Contributor

ehuss commented Jul 21, 2018

Is there a cleaner way to find a binary executable from an integration test other than looking at current_exe() and finding it from there? Cargo itself uses this logic:

pub fn cargo_dir() -> PathBuf {
env::var_os("CARGO_BIN_PATH")
.map(PathBuf::from)
.or_else(|| {
env::current_exe().ok().map(|mut path| {
path.pop();
if path.ends_with("deps") {
path.pop();
}
path
})
})
.unwrap_or_else(|| panic!("CARGO_BIN_PATH wasn't set. Cannot continue running test"))
}
pub fn cargo_exe() -> PathBuf {
cargo_dir().join(format!("cargo{}", env::consts::EXE_SUFFIX))
}

I've seen others use Command::new("./target/debug/NAME") which can fail in some cases.

It seems like this should be easier. Am I missing a better way? If not, would it make sense to provide some method to more easily find binaries?

@alexcrichton
Copy link
Member

The if path.ends_with("deps") is a compatibility hack for older Cargos, but otherwise that's AFAIK the "state of the art" in terms of being robust to future tweaks in Cargo as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants