Skip to content

Commit

Permalink
test: improving test-tool on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 16, 2024
1 parent e3b5316 commit f716edb
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ jobs:
env:
MISE_USE_VERSIONS_HOST: 0
MISE_EXPERIMENTAL: 1
MISE_DISABLE_TOOLS: 1password-cli
MISE_DISABLE_TOOLS: |
1password-cli,
act,
age,
air,
continue-on-error: true
- run: cargo test
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion src/cli/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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::<Vec<_>>());
let config = Config::try_get()?;
self.plugin = self
.plugin
Expand Down
4 changes: 2 additions & 2 deletions src/cli/settings/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ pub fn set(mut key: &str, value: &str, add: bool) -> Result<()> {
}

fn parse_list_by_comma(value: &str) -> Result<toml_edit::Value> {
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<toml_edit::Value> {
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<toml_edit::Value> {
Expand Down
12 changes: 8 additions & 4 deletions src/cli/test_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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 {
Expand All @@ -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(),
Expand All @@ -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(())
}
Expand Down
7 changes: 7 additions & 0 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
self.disable_tools
.iter()
.map(|t| t.trim().to_string())
.collect()
}
}

impl Display for Settings {
Expand Down
2 changes: 1 addition & 1 deletion src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/toolset/tool_request_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashSet};
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::fmt::{Debug, Display};

use indexmap::IndexMap;
Expand Down Expand Up @@ -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<BackendArg>,
disable_tools: BTreeSet<BackendArg>,
}

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()
}
}
Expand Down Expand Up @@ -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<()> {
Expand Down

0 comments on commit f716edb

Please sign in to comment.