From 5aec6e4381dc6350163905774f0ee6ce055f8eee Mon Sep 17 00:00:00 2001 From: Martin Havelka Date: Mon, 21 Sep 2026 12:03:49 +0200 Subject: [PATCH] fix(cargo-gamma): support standalone toolchains in environment tests Require rustup-specific environment variables only when an active rustup toolchain is available. Keep Cargo and nextest environment assertions unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f2464692-d45c-4470-a24e-ec24b46fe2b5 --- crates/cargo-gamma-lib/tests/session.rs | 29 ++++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/crates/cargo-gamma-lib/tests/session.rs b/crates/cargo-gamma-lib/tests/session.rs index 3514e6c7b..a2926bc88 100644 --- a/crates/cargo-gamma-lib/tests/session.rs +++ b/crates/cargo-gamma-lib/tests/session.rs @@ -115,16 +115,25 @@ fn cargo_runtime_environment_is_present() { "CARGO_PKG_RUST_VERSION", "CARGO_BIN_EXE_subject-cli", "OUT_DIR", - "RUSTUP_HOME", - "RUSTUP_TOOLCHAIN", - "RUSTUP_TOOLCHAIN_SOURCE", - "RUST_RECURSION_COUNT", "SUBJECT_BUILD_VALUE", ]; for name in required { assert!(std::env::var_os(name).is_some(), "{name} was not set"); } + // Standalone toolchains provide Cargo's environment without rustup's variables. + if RUSTUP_AVAILABLE { + for name in [ + "RUSTUP_HOME", + "RUSTUP_TOOLCHAIN", + "RUSTUP_TOOLCHAIN_SOURCE", + "RUST_RECURSION_COUNT", + ] { + assert!(std::env::var_os(name).is_some(), "{name} was not set"); + } + assert!(std::path::Path::new(&std::env::var_os("RUSTUP_HOME").unwrap()).is_dir()); + } + assert_eq!(std::env::var("CARGO_PKG_NAME").unwrap(), "subject"); assert_eq!(std::env::var("CARGO_PKG_VERSION").unwrap(), "1.2.3-alpha.1"); assert_eq!(std::env::var("CARGO_PKG_VERSION_PRE").unwrap(), "alpha.1"); @@ -146,7 +155,6 @@ fn cargo_runtime_environment_is_present() { assert!(std::path::Path::new(&std::env::var_os("OUT_DIR").unwrap()).is_dir()); assert!(std::path::Path::new(&std::env::var_os("CARGO").unwrap()).is_file()); assert!(std::path::Path::new(&std::env::var_os("CARGO_HOME").unwrap()).is_dir()); - assert!(std::path::Path::new(&std::env::var_os("RUSTUP_HOME").unwrap()).is_dir()); let profile = cargo_binary .parent() @@ -332,8 +340,17 @@ fn environment_workspace() -> TempDir { fs::write(root.join("src/lib.rs"), SUBJECT).expect("could not write the library"); fs::write(root.join("src/bin/subject-cli.rs"), "fn main() {}\n").expect("could not write the binary"); + let rustup_available = Command::new("rustup") + .args(["show", "active-toolchain"]) + .current_dir(root) + .output() + .is_ok_and(|output| output.status.success()); fs::create_dir_all(root.join("tests")).expect("could not create tests"); - fs::write(root.join("tests/environment.rs"), ENVIRONMENT_TEST).expect("could not write the integration test"); + fs::write( + root.join("tests/environment.rs"), + format!("const RUSTUP_AVAILABLE: bool = {rustup_available};\n{ENVIRONMENT_TEST}"), + ) + .expect("could not write the integration test"); dir }