Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions crates/cargo-gamma-lib/tests/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
Loading