#
cargo_test_support/
install.rs

    1//! Helpers for testing `cargo install`
    2
    3use std::env::consts::EXE_SUFFIX;
    4use std::path::Path;
    5
    6/// Used by `cargo install` tests to assert an executable binary
    7/// has been installed. Example usage:
    8/// ```no_run
    9/// use cargo_test_support::install::assert_has_installed_exe;
    10/// use cargo_test_support::paths;
    11///
    12/// assert_has_installed_exe(paths::cargo_home(), "foo");
    13/// ```
    14#[track_caller]
    15pub fn assert_has_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
    16    assert!(check_has_installed_exe(path, name));
    17}
    18
    19#[track_caller]
    20pub fn assert_has_not_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
    21    assert!(!check_has_installed_exe(path, name));
    22}
    23
    24fn check_has_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) -> bool {
    25    path.as_ref().join("bin").join(exe(name)).is_file()
    26}
    27
    28/// `$name$EXE`
    29pub fn exe(name: &str) -> String {
    30    format!("{}{}", name, EXE_SUFFIX)
    31}