From 7ef323d70ee343eeeb1ded5137a58b3c01f4bec5 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Sat, 16 Nov 2024 14:49:07 -0600 Subject: [PATCH] test: improving test-tool on windows --- .github/workflows/test.yml | 4 ++-- src/backend/mod.rs | 2 +- src/cli/ls.rs | 7 ++++++- src/cli/settings/set.rs | 4 ++-- src/cli/test_tool.rs | 30 +++++++++++++++++++----------- src/config/settings.rs | 7 +++++++ src/lockfile.rs | 2 +- src/toolset/mod.rs | 2 +- src/toolset/tool_request_set.rs | 10 +++++----- 9 files changed, 44 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ba43298b1f..9d0d6118ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -176,8 +176,8 @@ jobs: env: MISE_USE_VERSIONS_HOST: 0 MISE_EXPERIMENTAL: 1 - MISE_DISABLE_TOOLS: 1password-cli - continue-on-error: true + MISE_DISABLE_TOOLS: | + 1password-cli, - run: cargo test continue-on-error: true windows-e2e: diff --git a/src/backend/mod.rs b/src/backend/mod.rs index d73c163f2c..7677f380f3 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -94,7 +94,7 @@ pub fn load_tools() { .flat_map(|ist| arg_to_backend(BackendArg::new(ist.short, Some(ist.full)))), ); time!("load_tools install_state"); - tools.retain(|backend| !SETTINGS.disable_tools.contains(backend.id())); + tools.retain(|backend| !SETTINGS.disable_tools().contains(backend.id())); let tools: BackendMap = tools .into_iter() diff --git a/src/cli/ls.rs b/src/cli/ls.rs index c7c2611e8c..b40df2270c 100644 --- a/src/cli/ls.rs +++ b/src/cli/ls.rs @@ -15,7 +15,7 @@ use versions::Versioning; use crate::backend::Backend; use crate::cli::args::BackendArg; use crate::config; -use crate::config::Config; +use crate::config::{Config, SETTINGS}; use crate::toolset::{ToolSource, ToolVersion, Toolset}; use crate::ui::table; @@ -76,6 +76,11 @@ pub struct Ls { impl Ls { pub fn run(mut self) -> Result<()> { + dbg!(&*SETTINGS + .disable_tools() + .iter() + .map(|s| s.as_str()) + .collect::>()); let config = Config::try_get()?; self.plugin = self .plugin diff --git a/src/cli/settings/set.rs b/src/cli/settings/set.rs index 4dfd77f52a..efb64b2701 100644 --- a/src/cli/settings/set.rs +++ b/src/cli/settings/set.rs @@ -73,11 +73,11 @@ pub fn set(mut key: &str, value: &str, add: bool) -> Result<()> { } fn parse_list_by_comma(value: &str) -> Result { - Ok(value.split(',').map(|s| s.to_string()).collect()) + Ok(value.split(',').map(|s| s.trim().to_string()).collect()) } fn parse_list_by_colon(value: &str) -> Result { - Ok(value.split(':').map(|s| s.to_string()).collect()) + Ok(value.split(':').map(|s| s.trim().to_string()).collect()) } fn parse_bool(value: &str) -> Result { diff --git a/src/cli/test_tool.rs b/src/cli/test_tool.rs index dbf7ffe774..9d88c98028 100644 --- a/src/cli/test_tool.rs +++ b/src/cli/test_tool.rs @@ -7,7 +7,7 @@ use crate::toolset::{InstallOptions, ToolsetBuilder}; use crate::ui::time; use crate::{dirs, env, file}; use eyre::{eyre, Result}; -use itertools::Itertools; +use std::path::PathBuf; /// Test a tool installs and executes #[derive(Debug, clap::Args)] @@ -32,7 +32,7 @@ pub struct TestTool { impl TestTool { pub fn run(self) -> Result<()> { - let mut errored = false; + let mut errored = vec![]; self.github_summary(vec![ "Tool".to_string(), "Duration".to_string(), @@ -51,6 +51,10 @@ impl TestTool { } tool = t.clone(); } + if self.all && rt.short != *short { + // means this is an alias + continue; + } let (cmd, expected) = if let Some(test) = &rt.test { (test.0.to_string(), test.1) } else if self.include_non_defined { @@ -70,7 +74,7 @@ impl TestTool { } Err(err) => { error!("{}: {:?}", tool.short, err); - errored = true; + errored.push(tool.short.clone()); self.github_summary(vec![ tool.short.clone(), time::format_duration(start.elapsed()).to_string(), @@ -79,8 +83,8 @@ impl TestTool { } }; } - if errored { - return Err(eyre!("some tests failed")); + if !errored.is_empty() { + return Err(eyre!("tools failed: {}", errored.join(", "))); } Ok(()) } @@ -117,12 +121,16 @@ impl TestTool { }; let backend = tv.backend()?; let env = ts.env_with_path(&CONFIG)?; - let which_cmd = backend.which(&tv, cmd.split_whitespace().next().unwrap())?; - info!( - "$ {which_cmd} {rest}", - which_cmd = display_path(which_cmd.unwrap_or_default()), - rest = cmd.split_whitespace().skip(1).join(" ") - ); + let mut which_parts = cmd.split_whitespace().collect::>(); + let cmd = which_parts.remove(0); + let mut which_cmd = backend + .which(&tv, &cmd)? + .unwrap_or(PathBuf::from(cmd)); + if cfg!(windows) && which_cmd == PathBuf::from("which") { + which_cmd = PathBuf::from("where"); + } + let cmd = format!("{} {}", which_cmd.display(), which_parts.join(" ")); + info!("$ {cmd}"); let mut cmd = if cfg!(windows) { cmd!("cmd", "/C", cmd) } else { diff --git a/src/config/settings.rs b/src/config/settings.rs index 393d98b28d..3302e4dcbd 100644 --- a/src/config/settings.rs +++ b/src/config/settings.rs @@ -393,6 +393,13 @@ impl Settings { pub fn log_level(&self) -> log::LevelFilter { self.log_level.parse().unwrap_or(log::LevelFilter::Info) } + + pub fn disable_tools(&self) -> BTreeSet { + self.disable_tools + .iter() + .map(|t| t.trim().to_string()) + .collect() + } } impl Display for Settings { diff --git a/src/lockfile.rs b/src/lockfile.rs index 37f4b23812..7f22391e1e 100644 --- a/src/lockfile.rs +++ b/src/lockfile.rs @@ -94,7 +94,7 @@ pub fn update_lockfiles(new_versions: &[ToolVersion]) -> Result<()> { // * tools inside a parent config but are overridden by a child config (we just keep what was in the lockfile before, if anything) existing_lockfile .tools - .retain(|k, _| all_tool_names.contains(k) || SETTINGS.disable_tools.contains(k)); + .retain(|k, _| all_tool_names.contains(k) || SETTINGS.disable_tools().contains(k)); for (short, tvl) in tools { if tvl.versions.len() > 1 { diff --git a/src/toolset/mod.rs b/src/toolset/mod.rs index f958b71db3..b786560ac4 100644 --- a/src/toolset/mod.rs +++ b/src/toolset/mod.rs @@ -628,7 +628,7 @@ impl Toolset { } fn is_disabled(&self, ba: &BackendArg) -> bool { - !ba.is_os_supported() || SETTINGS.disable_tools.contains(&ba.short) + !ba.is_os_supported() || SETTINGS.disable_tools().contains(&ba.short) } } diff --git a/src/toolset/tool_request_set.rs b/src/toolset/tool_request_set.rs index 485b1f8bf2..a3d3cd4077 100644 --- a/src/toolset/tool_request_set.rs +++ b/src/toolset/tool_request_set.rs @@ -1,4 +1,4 @@ -use std::collections::{BTreeMap, HashSet}; +use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::fmt::{Debug, Display}; use indexmap::IndexMap; @@ -111,14 +111,14 @@ pub struct ToolRequestSetBuilder { /// default to latest version if no version is specified (for `mise x`) default_to_latest: bool, /// tools which will be disabled - disable_tools: Vec, + disable_tools: BTreeSet, } impl ToolRequestSetBuilder { pub fn new() -> Self { let settings = Settings::get(); Self { - disable_tools: settings.disable_tools.iter().map(|s| s.into()).collect(), + disable_tools: settings.disable_tools().iter().map(|s| s.into()).collect(), ..Default::default() } } @@ -152,8 +152,8 @@ impl ToolRequestSetBuilder { Ok(trs) } - fn is_disabled(&self, fa: &BackendArg) -> bool { - self.disable_tools.contains(fa) + fn is_disabled(&self, ba: &BackendArg) -> bool { + !ba.is_os_supported() || self.disable_tools.contains(ba) } fn load_config_files(&self, trs: &mut ToolRequestSet) -> eyre::Result<()> {