rust-llm-tidy-cli 0.8.2

CLI for linting and tidying Rust, C#, and documentation source.
//! Helpers shared by the `rust-llm-tidy` CLI integration tests.
//!
//! Each test binary under `tests/` is its own crate, so helpers used by
//! several of them live in this submodule (`tests/common/mod.rs`). Flat
//! roots pull it in with `mod common;`; folder roots use
//! `#[path = "../common/mod.rs"]`.

use std::env;
use std::path::PathBuf;

/// Returns the path to the `rust-llm-tidy` binary for spawning in tests.
///
/// Resolution order:
/// 1. `CARGO_BIN_EXE_rust-llm-tidy`; modern Cargo keeps the hyphen.
/// 2. `CARGO_BIN_EXE_rust_llm_tidy`; older Cargo normalized it.
/// 3. Walk up from the test executable to the `target/<profile>` dir that
///    holds the peer binary.
///
/// Panics when none resolve.
pub fn binary() -> PathBuf {
    for var in ["CARGO_BIN_EXE_rust-llm-tidy", "CARGO_BIN_EXE_rust_llm_tidy"] {
        if let Some(path) = env::var_os(var) {
            return PathBuf::from(path);
        }
    }

    // Fallback for direct runs: walk up to the `<profile>` dir that holds
    // the peer binary.

    // The test binary lives in `<profile>/deps/` (stable) or the build-out
    // dir (newer Cargo); both sit under that `<profile>` dir.
    let mut dir = env::current_exe()
        .expect("current_exe must resolve")
        .parent()
        .expect("current_exe must have a parent")
        .to_path_buf();
    loop {
        for bin in ["rust-llm-tidy", "rust-llm-tidy.exe"] {
            let candidate = dir.join(bin);
            if candidate.is_file() {
                return candidate;
            }
        }
        if !dir.pop() {
            break;
        }
    }
    panic!("could not locate the rust-llm-tidy binary next to the test executable");
}