]> git.proxmox.com Git - cargo.git/blob - crates/cargo-test-support/src/install.rs
Refactor echo cargo subcommand test helper into cargo-test-support
[cargo.git] / crates / cargo-test-support / src / install.rs
1 use crate::paths;
2 use std::env::consts::EXE_SUFFIX;
3 use std::path::{Path, PathBuf};
4
5 /// Used by `cargo install` tests to assert an executable binary
6 /// has been installed. Example usage:
7 ///
8 /// assert_has_installed_exe(cargo_home(), "foo");
9 #[track_caller]
10 pub fn assert_has_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
11 assert!(check_has_installed_exe(path, name));
12 }
13
14 #[track_caller]
15 pub fn assert_has_not_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
16 assert!(!check_has_installed_exe(path, name));
17 }
18
19 fn check_has_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) -> bool {
20 path.as_ref().join("bin").join(exe(name)).is_file()
21 }
22
23 pub fn cargo_home() -> PathBuf {
24 paths::home().join(".cargo")
25 }
26
27 pub fn exe(name: &str) -> String {
28 format!("{}{}", name, EXE_SUFFIX)
29 }