Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7994015

Browse files
committedOct 5, 2024·
Use channel linking to test channel selection autocomplete
1 parent 41e6b59 commit 7994015

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed
 

‎src/global_paths.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ fn get_default_juliaup_home_path() -> Result<PathBuf> {
5555

5656
pub fn get_paths() -> Result<GlobalPaths> {
5757
let juliauphome = get_juliaup_home_path()?;
58-
58+
return get_paths_from_home_path(juliauphome);
59+
}
60+
pub fn get_paths_from_home_path(juliauphome: PathBuf) -> Result<GlobalPaths> {
5961
#[cfg(feature = "selfupdate")]
6062
let my_own_path = std::env::current_exe()
6163
.with_context(|| "Could not determine the path of the running exe.")?;

‎tests/channel_selection.rs

+49-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
use assert_cmd::Command;
22

3+
use anyhow::Result;
4+
use juliaup::config_file::{load_config_db, JuliaupConfigChannel};
5+
use juliaup::global_paths::get_paths_from_home_path;
6+
use normpath::PathExt;
7+
use std::path::PathBuf;
8+
9+
// Simpler reimplementation of get_julia_path_from_channel from julialauncher.rs to help link channels
10+
fn get_julia_path_from_channel(
11+
requested_channel: &str,
12+
juliaup_depot_path: PathBuf,
13+
) -> Result<PathBuf> {
14+
let paths = get_paths_from_home_path(juliaup_depot_path)?;
15+
let config_file = load_config_db(&paths)?;
16+
let config_data = config_file.data;
17+
18+
let juliaupconfig_path = paths.juliaupconfig.as_path();
19+
20+
let channel_info = config_data
21+
.installed_channels
22+
.get(requested_channel)
23+
.unwrap();
24+
25+
let path: &String = if let JuliaupConfigChannel::SystemChannel { version } = channel_info {
26+
&config_data.installed_versions.get(version).unwrap().path
27+
} else {
28+
panic!("whoops")
29+
};
30+
31+
let absolute_path = juliaupconfig_path
32+
.parent()
33+
.unwrap() // unwrap OK because there should always be a parent
34+
.join(path)
35+
.join("bin")
36+
.join(format!("julia{}", std::env::consts::EXE_SUFFIX))
37+
.normalize()?;
38+
39+
return Ok(absolute_path.into_path_buf());
40+
}
41+
342
#[test]
443
fn channel_selection() {
544
let depot_dir = assert_fs::TempDir::new().unwrap();
@@ -141,10 +180,15 @@ fn channel_selection() {
141180
.failure();
142181

143182
// Test that completion works only when it should for words
183+
let linked_julia_path =
184+
get_julia_path_from_channel("1.6.7", depot_dir.path().to_path_buf().join("juliaup"))
185+
.unwrap();
186+
let linked_julia_version = linked_julia_path.to_str().unwrap();
144187
Command::cargo_bin("juliaup")
145188
.unwrap()
146-
.arg("add")
147-
.arg("release")
189+
.arg("link")
190+
.arg("ra")
191+
.arg(linked_julia_version)
148192
.env("JULIA_DEPOT_PATH", depot_dir.path())
149193
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
150194
.assert()
@@ -161,8 +205,9 @@ fn channel_selection() {
161205

162206
Command::cargo_bin("juliaup")
163207
.unwrap()
164-
.arg("add")
165-
.arg("rc")
208+
.arg("link")
209+
.arg("rb")
210+
.arg(linked_julia_version)
166211
.env("JULIA_DEPOT_PATH", depot_dir.path())
167212
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
168213
.assert()

0 commit comments

Comments
 (0)
Please sign in to comment.