Skip to content

Commit 6fa6a79

Browse files
committed
(wip) add tests
1 parent 88b4d81 commit 6fa6a79

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

src/test/clitools.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ pub enum Scenario {
473473
/// Three dates, v2 manifests, host and MULTI_ARCH1 in first, host only in second,
474474
/// host and MULTI_ARCH1 but no RLS in last
475475
MissingComponentMulti,
476+
/// One date, v2 manifests, with rust-analyzer
477+
RustAnalyzer,
476478
}
477479

478480
impl Scenario {
@@ -561,6 +563,9 @@ impl Scenario {
561563
.multi_arch()
562564
.with_rls(RlsStatus::Unavailable),
563565
],
566+
Self::RustAnalyzer => {
567+
vec![Release::stable("1.79.0", "2024-06-15").with_rls(RlsStatus::RustAnalyzer)]
568+
}
564569
};
565570

566571
let vs = match self {
@@ -581,7 +586,8 @@ impl Scenario {
581586
| Self::HostGoesMissingBefore
582587
| Self::HostGoesMissingAfter
583588
| Self::MissingComponent
584-
| Self::MissingComponentMulti => vec![MockManifestVersion::V2],
589+
| Self::MissingComponentMulti
590+
| Self::RustAnalyzer => vec![MockManifestVersion::V2],
585591
};
586592

587593
MockDistServer {
@@ -634,6 +640,7 @@ impl ConstState {
634640
Scenario::MultiHost => RwLock::new(None),
635641
Scenario::None => RwLock::new(None),
636642
Scenario::RemovedRls => RwLock::new(None),
643+
Scenario::RustAnalyzer => RwLock::new(None),
637644
Scenario::SimpleV1 => RwLock::new(None),
638645
Scenario::SimpleV2 => RwLock::new(None),
639646
Scenario::Unavailable => RwLock::new(None),
@@ -748,6 +755,7 @@ async fn setup_test_state(test_dist_dir: tempfile::TempDir) -> (tempfile::TempDi
748755
let rustc_path = config.exedir.join(format!("rustc{EXE_SUFFIX}"));
749756
let cargo_path = config.exedir.join(format!("cargo{EXE_SUFFIX}"));
750757
let rls_path = config.exedir.join(format!("rls{EXE_SUFFIX}"));
758+
let rust_analyzer_path = config.exedir.join(format!("rust-analyzer{EXE_SUFFIX}"));
751759
let rust_lldb_path = config.exedir.join(format!("rust-lldb{EXE_SUFFIX}"));
752760

753761
const ESTIMATED_LINKS_PER_TEST: usize = 6 * 2;
@@ -784,6 +792,7 @@ async fn setup_test_state(test_dist_dir: tempfile::TempDir) -> (tempfile::TempDi
784792
hard_link(&rustup_path, rustc_path).unwrap();
785793
hard_link(&rustup_path, cargo_path).unwrap();
786794
hard_link(&rustup_path, rls_path).unwrap();
795+
hard_link(&rustup_path, rust_analyzer_path).unwrap();
787796
hard_link(&rustup_path, rust_lldb_path).unwrap();
788797

789798
// Make sure the host triple matches the build triple. Otherwise testing a 32-bit build of

src/test/dist.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ impl MockChannel {
365365
target: target.to_string(),
366366
is_extension: true,
367367
});
368+
} else if rls == RlsStatus::RustAnalyzer {
369+
target_pkg.components.push(MockComponent {
370+
name: "rust-analyzer".to_string(),
371+
target: target.to_string(),
372+
is_extension: true,
373+
});
368374
} else {
369375
target_pkg.components.push(MockComponent {
370376
name: "rls".to_string(),
@@ -482,13 +488,15 @@ impl MockChannelContent {
482488
pub(super) enum RlsStatus {
483489
Available,
484490
Renamed,
491+
RustAnalyzer,
485492
Unavailable,
486493
}
487494

488495
impl RlsStatus {
489496
fn pkg_name(self) -> &'static str {
490497
match self {
491498
Self::Renamed => "rls-preview",
499+
Self::RustAnalyzer => "rust-analyzer",
492500
_ => "rls",
493501
}
494502
}

src/test/mock.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ impl MockInstallerBuilder {
6767
}
6868

6969
pub(super) fn rls(version: &str, version_hash: &str, pkg_name: &str) -> Self {
70+
let bin = match pkg_name {
71+
"rust-analyzer" => pkg_name,
72+
_ => "rls",
73+
};
7074
Self {
7175
components: vec![MockComponentBuilder {
7276
name: pkg_name.to_string(),
73-
files: mock_bin("rls", version, version_hash),
77+
files: mock_bin(bin, version, version_hash),
7478
}],
7579
}
7680
}

src/test/mock_bin_src.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ fn main() {
102102
panic!("CARGO environment variable not set");
103103
}
104104
}
105+
Some("--echo-current-exe") => {
106+
let mut out = io::stderr();
107+
writeln!(out, "{}", std::env::current_exe().unwrap().display()).unwrap();
108+
}
105109
arg => panic!("bad mock proxy commandline: {:?}", arg),
106110
}
107111
}

tests/suite/cli_misc.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,3 +1277,40 @@ async fn rustup_updates_cargo_env_if_proxy() {
12771277
)
12781278
.await;
12791279
}
1280+
1281+
#[tokio::test]
1282+
async fn rust_analyzer_proxy_falls_back_external() {
1283+
let mut cx = CliTestContext::new(Scenario::RustAnalyzer).await;
1284+
cx.config.expect_ok(&["rustup", "default", "stable"]).await;
1285+
cx.config
1286+
.expect_ok(&["rustup", "component", "add", "rust-analyzer"])
1287+
.await;
1288+
1289+
let real_path = cx
1290+
.config
1291+
.run("rustup", &["which", "rust-analyzer"], &[])
1292+
.await;
1293+
assert!(real_path.ok);
1294+
let real_path_str = &real_path.stdout;
1295+
let real_path = Path::new(&real_path_str);
1296+
1297+
cx.config
1298+
.expect_ok_ex(&["rust-analyzer", "--echo-current-exe"], "", &real_path_str)
1299+
.await;
1300+
1301+
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
1302+
let extern_path = tempdir.path().join("rust-analyzer");
1303+
fs::copy(real_path, &extern_path).unwrap();
1304+
1305+
cx.config
1306+
.expect_ok(&["rustup", "component", "remove", "rust-analyzer"])
1307+
.await;
1308+
cx.config
1309+
.expect_ok_ex_env(
1310+
&["rust-analyzer", "--echo-current-exe"],
1311+
&[("PATH", &tempdir.path().to_string_lossy())],
1312+
"",
1313+
&extern_path.to_string_lossy(),
1314+
)
1315+
.await;
1316+
}

0 commit comments

Comments
 (0)