From 5536616da51ae3db2241b66d2f3ecb9a7fb4fdad Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:54:31 -0300 Subject: [PATCH] Use channel linking to test channel selection autocomplete --- tests/channel_selection.rs | 49 ++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/tests/channel_selection.rs b/tests/channel_selection.rs index 7bfaa8e6..c490696c 100644 --- a/tests/channel_selection.rs +++ b/tests/channel_selection.rs @@ -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 { + 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(); @@ -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() @@ -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()