Skip to content

Commit

Permalink
Use channel linking to test channel selection autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Aug 21, 2024
1 parent 677b564 commit 5536616
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions tests/channel_selection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
use assert_cmd::Command;

use anyhow::Result;
use juliaup::config_file::{load_config_db, JuliaupConfigChannel};
use juliaup::global_paths::get_paths;
use normpath::PathExt;
use std::path::PathBuf;

// Simpler reimplementation of get_julia_path_from_channel from julialauncher.rs to help link channels
fn get_julia_path_from_channel(requested_channel: &str) -> Result<PathBuf> {
let paths = get_paths()?;
let config_file = load_config_db(&paths)?;
let config_data = config_file.data;
// .with_context(|| "The Julia launcher failed to load a configuration file.")?;

let juliaupconfig_path = paths.juliaupconfig.as_path();

let channel_info = config_data
.installed_channels
.get(requested_channel)
.unwrap();

let path: &String = if let JuliaupConfigChannel::SystemChannel { version } = channel_info {
&config_data.installed_versions.get(version).unwrap().path
} else {
panic!("whoops")
};

let absolute_path = juliaupconfig_path
.parent()
.unwrap() // unwrap OK because there should always be a parent
.join(path)
.join("bin")
.join(format!("julia{}", std::env::consts::EXE_SUFFIX))
.normalize()?;

return Ok(absolute_path.into_path_buf());
}

#[test]
fn channel_selection() {
let depot_dir = assert_fs::TempDir::new().unwrap();
Expand Down Expand Up @@ -141,10 +178,13 @@ fn channel_selection() {
.failure();

// Test that completion works only when it should for words
let linked_julia_path = get_julia_path_from_channel("1.6.7").unwrap();
let linked_julia_version = linked_julia_path.to_str().unwrap();
Command::cargo_bin("juliaup")
.unwrap()
.arg("add")
.arg("release")
.arg("link")
.arg("ra")
.arg(linked_julia_version)
.env("JULIA_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.assert()
Expand All @@ -161,8 +201,9 @@ fn channel_selection() {

Command::cargo_bin("juliaup")
.unwrap()
.arg("add")
.arg("rc")
.arg("link")
.arg("rb")
.arg(linked_julia_version)
.env("JULIA_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.assert()
Expand Down

0 comments on commit 5536616

Please sign in to comment.