Skip to content

Commit 18b8e34

Browse files
ChrisDentonrami3l
authored andcommitted
Test CARGO environment replacement
1 parent f9ed6fc commit 18b8e34

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

Diff for: src/test/clitools.rs

+1
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ async fn setup_test_state(test_dist_dir: tempfile::TempDir) -> (tempfile::TempDi
684684
// **in this process** when the tests are still running.
685685
unsafe {
686686
// Unset env variables that will break our testing
687+
env::remove_var("CARGO");
687688
env::remove_var("RUSTUP_UPDATE_ROOT");
688689
env::remove_var("RUSTUP_TOOLCHAIN");
689690
env::remove_var("SHELL");

Diff for: src/test/mock_bin_src.rs

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ fn main() {
9494
let mut out = io::stderr();
9595
writeln!(out, "{}", std::env::var("PATH").unwrap()).unwrap();
9696
}
97+
Some("--echo-cargo-env") => {
98+
let mut out = io::stderr();
99+
if let Ok(cargo) = std::env::var("CARGO") {
100+
writeln!(out, "{cargo}").unwrap();
101+
} else {
102+
panic!("CARGO environment variable not set");
103+
}
104+
}
97105
arg => panic!("bad mock proxy commandline: {:?}", arg),
98106
}
99107
}

Diff for: tests/suite/cli_misc.rs

+44
Original file line numberDiff line numberDiff line change
@@ -1233,3 +1233,47 @@ async fn toolchain_install_multi_components_comma() {
12331233
.await;
12341234
}
12351235
}
1236+
1237+
#[tokio::test]
1238+
async fn rustup_updates_cargo_env_if_proxy() {
1239+
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
1240+
cx.config.expect_ok(&["rustup", "default", "stable"]).await;
1241+
1242+
use std::env::consts::EXE_SUFFIX;
1243+
let proxy_path = cx
1244+
.config
1245+
.workdir
1246+
.borrow()
1247+
.join("bin")
1248+
.join(format!("cargo{EXE_SUFFIX}"));
1249+
let real_path = cx.config.run("rustup", &["which", "cargo"], &[]).await;
1250+
assert!(real_path.ok);
1251+
let real_path = real_path.stdout;
1252+
1253+
fs::create_dir_all(proxy_path.parent().unwrap()).unwrap();
1254+
#[cfg(windows)]
1255+
if std::os::windows::fs::symlink_file("rustup", &proxy_path).is_err() {
1256+
// skip this test on Windows if symlinking isn't enabled.
1257+
return;
1258+
}
1259+
#[cfg(unix)]
1260+
std::os::unix::fs::symlink("rustup", &proxy_path).unwrap();
1261+
1262+
// If CARGO isn't set then we should not set it.
1263+
cx.config
1264+
.expect_err(
1265+
&["cargo", "--echo-cargo-env"],
1266+
"CARGO environment variable not set",
1267+
)
1268+
.await;
1269+
1270+
// If CARGO is set to a proxy then change it to the real CARGO path
1271+
cx.config
1272+
.expect_ok_ex_env(
1273+
&["cargo", "--echo-cargo-env"],
1274+
&[("CARGO", proxy_path.to_str().unwrap())],
1275+
"",
1276+
&real_path,
1277+
)
1278+
.await;
1279+
}

0 commit comments

Comments
 (0)