diff --git a/src/cli/alias/set.rs b/src/cli/alias/set.rs index a5408b521..31445cee6 100644 --- a/src/cli/alias/set.rs +++ b/src/cli/alias/set.rs @@ -21,7 +21,7 @@ pub struct AliasSet { impl AliasSet { pub fn run(self) -> Result<()> { let mut global_config = Config::get().global_config()?; - global_config.set_alias(&self.plugin, &self.alias, &self.value); + global_config.set_alias(&self.plugin, &self.alias, &self.value)?; global_config.save() } } diff --git a/src/cli/alias/unset.rs b/src/cli/alias/unset.rs index 709a8552d..1e5adfda6 100644 --- a/src/cli/alias/unset.rs +++ b/src/cli/alias/unset.rs @@ -19,7 +19,7 @@ pub struct AliasUnset { impl AliasUnset { pub fn run(self) -> Result<()> { let mut global_config = Config::get().global_config()?; - global_config.remove_alias(&self.plugin, &self.alias); + global_config.remove_alias(&self.plugin, &self.alias)?; global_config.save() } } diff --git a/src/cli/local.rs b/src/cli/local.rs index 0629bcca4..830c696cb 100644 --- a/src/cli/local.rs +++ b/src/cli/local.rs @@ -105,7 +105,7 @@ pub fn local( if let Some(plugins) = &remove { for plugin in plugins { - cf.remove_plugin(plugin); + cf.remove_plugin(plugin)?; } let tools = plugins .iter() @@ -128,7 +128,7 @@ pub fn local( if !runtime.is_empty() || remove.is_some() { cf.save()?; } else { - miseprint!("{}", cf.dump()); + miseprint!("{}", cf.dump()?); } Ok(()) diff --git a/src/cli/set.rs b/src/cli/set.rs index 65667a2ec..df905be7f 100644 --- a/src/cli/set.rs +++ b/src/cli/set.rs @@ -68,7 +68,7 @@ impl Set { if let Some(env_names) = &self.remove { for name in env_names { - mise_toml.remove_env(name); + mise_toml.remove_env(name)?; } } @@ -83,7 +83,7 @@ impl Set { } for ev in env_vars { match ev.value { - Some(value) => mise_toml.update_env(&ev.key, value), + Some(value) => mise_toml.update_env(&ev.key, value)?, None => bail!("{} has no value", ev.key), } } @@ -131,7 +131,7 @@ mod tests { fn remove_config_file(filename: &str) -> PathBuf { let cf_path = env::current_dir().unwrap().join(filename); - let _ = file::remove_file(&cf_path); + let _ = file::write(&cf_path, ""); cf_path } @@ -156,6 +156,7 @@ mod tests { assert_cli_snapshot!("env-vars", "--file", filename, "FOO=bar", @""); assert_snapshot!(file::read_to_string(cf_path).unwrap()); remove_config_file(filename); + file::remove_file(filename).unwrap(); } #[test] @@ -175,5 +176,6 @@ mod tests { assert_cli_snapshot!("env-vars", "--file", filename, "--remove", "BAZ", @""); assert_snapshot!(file::read_to_string(cf_path).unwrap()); remove_config_file(filename); + file::remove_file(filename).unwrap(); } } diff --git a/src/cli/unset.rs b/src/cli/unset.rs index e6cbb0425..0f4c458a6 100644 --- a/src/cli/unset.rs +++ b/src/cli/unset.rs @@ -36,7 +36,7 @@ impl Unset { let mut mise_toml = get_mise_toml(&filename)?; for name in self.keys.iter() { - mise_toml.remove_env(name); + mise_toml.remove_env(name)?; } mise_toml.save() @@ -62,7 +62,7 @@ mod tests { fn remove_config_file(filename: &str) -> PathBuf { let cf_path = env::current_dir().unwrap().join(filename); - let _ = file::remove_file(&cf_path); + let _ = file::write(&cf_path, ""); cf_path } @@ -76,5 +76,6 @@ mod tests { assert_cli_snapshot!("unset", "BAZ", @""); assert_snapshot!(file::read_to_string(cf_path).unwrap()); remove_config_file(filename); + file::remove_file(filename).unwrap(); } } diff --git a/src/cli/use.rs b/src/cli/use.rs index 4a5ded6cb..89a7db6c3 100644 --- a/src/cli/use.rs +++ b/src/cli/use.rs @@ -122,14 +122,14 @@ impl Use { } }) .collect(); - cf.replace_versions(fa, &versions); + cf.replace_versions(fa, &versions)?; } if self.global { self.warn_if_hidden(&config, cf.get_path()); } for plugin_name in &self.remove { - cf.remove_plugin(plugin_name); + cf.remove_plugin(plugin_name)?; } cf.save()?; self.render_success_message(cf.as_ref(), &versions); @@ -264,13 +264,31 @@ mod tests { fn test_use_global() { let cf_path = dirs::CONFIG.join("config.toml"); let orig = file::read_to_string(&cf_path).unwrap(); - let _ = file::remove_file(&cf_path); assert_cli_snapshot!("use", "-g", "tiny@2", @r###" mise ~/config/config.toml tools: tiny@2.1.0 mise tiny is defined in ~/cwd/.test-tool-versions which overrides the global config (~/config/config.toml) "###); assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###" + [env] + TEST_ENV_VAR = 'test-123' + + [alias.tiny] + "my/alias" = '3.0' + + [tasks.configtask] + run = 'echo "configtask:"' + [tasks.lint] + run = 'echo "linting!"' + [tasks.test] + run = 'echo "testing!"' + [settings] + always_keep_download= true + always_keep_install= true + legacy_version_file= true + plugin_autoupdate_last_check_duration = "20m" + jobs = 2 + [tools] tiny = "2" "###); diff --git a/src/config/config_file/legacy_version.rs b/src/config/config_file/legacy_version.rs index 40d27d370..489dfe36e 100644 --- a/src/config/config_file/legacy_version.rs +++ b/src/config/config_file/legacy_version.rs @@ -41,11 +41,11 @@ impl ConfigFile for LegacyVersionFile { self.path.as_path() } - fn remove_plugin(&mut self, _fa: &ForgeArg) { + fn remove_plugin(&mut self, _fa: &ForgeArg) -> Result<()> { unimplemented!() } - fn replace_versions(&mut self, _plugin_name: &ForgeArg, _versions: &[String]) { + fn replace_versions(&mut self, _plugin_name: &ForgeArg, _versions: &[String]) -> Result<()> { unimplemented!() } @@ -53,7 +53,7 @@ impl ConfigFile for LegacyVersionFile { unimplemented!() } - fn dump(&self) -> String { + fn dump(&self) -> Result { unimplemented!() } diff --git a/src/config/config_file/mise_toml.rs b/src/config/config_file/mise_toml.rs index 0dc9f0c26..7fb8d2ec7 100644 --- a/src/config/config_file/mise_toml.rs +++ b/src/config/config_file/mise_toml.rs @@ -4,6 +4,7 @@ use std::path::{Path, PathBuf}; use eyre::WrapErr; use itertools::Itertools; +use once_cell::sync::OnceCell; use serde::de::Visitor; use serde::{de, Deserializer}; use serde_derive::Deserialize; @@ -45,7 +46,7 @@ pub struct MiseToml { #[serde(default, deserialize_with = "deserialize_alias")] alias: AliasMap, #[serde(skip)] - doc: Document, + doc: OnceCell, #[serde(default)] plugins: HashMap, #[serde(default)] @@ -80,7 +81,7 @@ impl MiseToml { let mut rf = Self::init(path); let body = file::read_to_string(path)?; // .suggestion("ensure file exists and can be read")?; rf.parse(&body)?; - trace!("{}", rf.dump()); + trace!("{}", rf.dump()?); Ok(rf) } @@ -111,10 +112,21 @@ impl MiseToml { _ => bail!("unknown key: {}", style::ered(k)), } } - self.doc = doc; Ok(()) } + fn doc(&self) -> eyre::Result<&Document> { + self.doc.get_or_try_init(|| { + let body = file::read_to_string(&self.path).unwrap_or_default(); + Ok(body.parse()?) + }) + } + + fn doc_mut(&mut self) -> eyre::Result<&mut Document> { + self.doc()?; + Ok(self.doc.get_mut().unwrap()) + } + fn parse_toolset(&self, key: &str, v: &Item) -> eyre::Result { let mut toolset = Toolset::new(self.toolset.source.clone().unwrap()); @@ -258,12 +270,12 @@ impl MiseToml { } } - pub fn set_alias(&mut self, fa: &ForgeArg, from: &str, to: &str) { + pub fn set_alias(&mut self, fa: &ForgeArg, from: &str, to: &str) -> eyre::Result<()> { self.alias .entry(fa.clone()) .or_default() .insert(from.into(), to.into()); - self.doc + self.doc_mut()? .entry("alias") .or_insert_with(table) .as_table_like_mut() @@ -273,45 +285,57 @@ impl MiseToml { .as_table_like_mut() .unwrap() .insert(from, value(to)); + Ok(()) } - pub fn remove_alias(&mut self, fa: &ForgeArg, from: &str) { - if let Some(aliases) = self.doc.get_mut("alias").and_then(|v| v.as_table_mut()) { + pub fn remove_alias(&mut self, fa: &ForgeArg, from: &str) -> eyre::Result<()> { + if let Some(aliases) = self + .doc_mut()? + .get_mut("alias") + .and_then(|v| v.as_table_mut()) + { if let Some(plugin_aliases) = aliases .get_mut(&fa.to_string()) .and_then(|v| v.as_table_mut()) { - self.alias.get_mut(fa).unwrap().remove(from); plugin_aliases.remove(from); if plugin_aliases.is_empty() { aliases.remove(&fa.to_string()); - self.alias.remove(fa); } } if aliases.is_empty() { - self.doc.as_table_mut().remove("alias"); + self.doc_mut()?.as_table_mut().remove("alias"); + } + } + if let Some(aliases) = self.alias.get_mut(fa) { + aliases.remove(from); + if aliases.is_empty() { + self.alias.remove(fa); } } + Ok(()) } - pub fn update_env>(&mut self, key: &str, value: V) { + pub fn update_env>(&mut self, key: &str, value: V) -> eyre::Result<()> { let env_tbl = self - .doc + .doc_mut()? .entry("env") .or_insert_with(table) .as_table_like_mut() .unwrap(); env_tbl.insert(key, toml_edit::value(value)); + Ok(()) } - pub fn remove_env(&mut self, key: &str) { + pub fn remove_env(&mut self, key: &str) -> eyre::Result<()> { let env_tbl = self - .doc + .doc_mut()? .entry("env") .or_insert_with(table) .as_table_like_mut() .unwrap(); env_tbl.remove(key); + Ok(()) } fn parse_template(&self, k: &str, input: &str) -> eyre::Result { @@ -383,19 +407,21 @@ impl ConfigFile for MiseToml { self.tasks.0.values().collect() } - fn remove_plugin(&mut self, fa: &ForgeArg) { + fn remove_plugin(&mut self, fa: &ForgeArg) -> eyre::Result<()> { self.toolset.versions.shift_remove(fa); - if let Some(tools) = self.doc.get_mut("tools") { + let doc = self.doc_mut()?; + if let Some(tools) = doc.get_mut("tools") { if let Some(tools) = tools.as_table_like_mut() { tools.remove(&fa.to_string()); if tools.is_empty() { - self.doc.as_table_mut().remove("tools"); + doc.as_table_mut().remove("tools"); } } } + Ok(()) } - fn replace_versions(&mut self, fa: &ForgeArg, versions: &[String]) { + fn replace_versions(&mut self, fa: &ForgeArg, versions: &[String]) -> eyre::Result<()> { if let Some(plugin) = self.toolset.versions.get_mut(fa) { plugin.requests = versions .iter() @@ -403,7 +429,7 @@ impl ConfigFile for MiseToml { .collect(); } let tools = self - .doc + .doc_mut()? .entry("tools") .or_insert_with(table) .as_table_mut() @@ -418,18 +444,20 @@ impl ConfigFile for MiseToml { } tools.insert(&fa.to_string(), Item::Value(Value::Array(arr))); } + + Ok(()) } fn save(&self) -> eyre::Result<()> { - let contents = self.dump(); + let contents = self.dump()?; if let Some(parent) = self.path.parent() { create_dir_all(parent)?; } file::write(&self.path, contents) } - fn dump(&self) -> String { - self.doc.to_string() + fn dump(&self) -> eyre::Result { + Ok(self.doc()?.to_string()) } fn to_toolset(&self) -> &Toolset { @@ -755,6 +783,7 @@ where mod tests { use crate::dirs; use crate::test::replace_path; + use dirs::CWD; use super::*; @@ -772,17 +801,23 @@ mod tests { #[test] fn test_env() { - let cf = MiseToml::init(PathBuf::from("/tmp/.mise.toml").as_path()); - let env = parse_env(formatdoc! {r#" + let p = CWD.as_ref().unwrap().join(".test.mise.toml"); + file::write( + &p, + formatdoc! {r#" min_version = "2024.1.1" [env] foo="bar" - "#}); + "#}, + ) + .unwrap(); + let cf = MiseToml::from_file(&p).unwrap(); + let env = parse_env(file::read_to_string(&p).unwrap()); assert_debug_snapshot!(env, @r###""foo=bar""###); let cf: Box = Box::new(cf); with_settings!({ - assert_snapshot!(cf.dump()); + assert_snapshot!(cf.dump().unwrap()); assert_display_snapshot!(cf); assert_debug_snapshot!(cf); }); @@ -895,80 +930,98 @@ mod tests { #[test] fn test_set_alias() { - let mut cf = MiseToml::init(PathBuf::from("/tmp/.mise.toml").as_path()); - cf.parse(&formatdoc! {r#" - [alias.node] - 16 = "16.0.0" - 18 = "18.0.0" - "#}) - .unwrap(); - + let p = CWD.as_ref().unwrap().join(".test.mise.toml"); + file::write( + &p, + formatdoc! {r#" + [alias.node] + 16 = "16.0.0" + 18 = "18.0.0" + "#}, + ) + .unwrap(); + let mut cf = MiseToml::from_file(&p).unwrap(); let node = "node".parse().unwrap(); let python = "python".parse().unwrap(); - cf.set_alias(&node, "18", "18.0.1"); - cf.set_alias(&node, "20", "20.0.0"); - cf.set_alias(&python, "3.10", "3.10.0"); + cf.set_alias(&node, "18", "18.0.1").unwrap(); + cf.set_alias(&node, "20", "20.0.0").unwrap(); + cf.set_alias(&python, "3.10", "3.10.0").unwrap(); assert_debug_snapshot!(cf.alias); let cf: Box = Box::new(cf); assert_display_snapshot!(cf); + file::remove_file(&p).unwrap(); } #[test] fn test_remove_alias() { - let mut cf = MiseToml::init(PathBuf::from("/tmp/.mise.toml").as_path()); - cf.parse(&formatdoc! {r#" - [alias.node] - 16 = "16.0.0" - 18 = "18.0.0" - - [alias.python] - "3.10" = "3.10.0" - "#}) - .unwrap(); + let p = CWD.as_ref().unwrap().join(".test.mise.toml"); + file::write( + &p, + formatdoc! {r#" + [alias.node] + 16 = "16.0.0" + 18 = "18.0.0" + + [alias.python] + "3.10" = "3.10.0" + "#}, + ) + .unwrap(); + let mut cf = MiseToml::from_file(&p).unwrap(); let node = "node".parse().unwrap(); let python = "python".parse().unwrap(); - cf.remove_alias(&node, "16"); - cf.remove_alias(&python, "3.10"); + cf.remove_alias(&node, "16").unwrap(); + cf.remove_alias(&python, "3.10").unwrap(); assert_debug_snapshot!(cf.alias); let cf: Box = Box::new(cf); - assert_snapshot!(cf.dump()); + assert_snapshot!(cf.dump().unwrap()); assert_display_snapshot!(cf); assert_debug_snapshot!(cf); + file::remove_file(&p).unwrap(); } #[test] fn test_replace_versions() { - let mut cf = MiseToml::init(PathBuf::from("/tmp/.mise.toml").as_path()); - cf.parse(&formatdoc! {r#" - [tools] - node = ["16.0.0", "18.0.0"] - "#}) - .unwrap(); + let p = PathBuf::from("/tmp/.mise.toml"); + file::write( + &p, + formatdoc! {r#" + [tools] + node = ["16.0.0", "18.0.0"] + "#}, + ) + .unwrap(); + let mut cf = MiseToml::from_file(&p).unwrap(); let node = "node".parse().unwrap(); - cf.replace_versions(&node, &["16.0.1".into(), "18.0.1".into()]); + cf.replace_versions(&node, &["16.0.1".into(), "18.0.1".into()]) + .unwrap(); assert_debug_snapshot!(cf.toolset); let cf: Box = Box::new(cf); - assert_snapshot!(cf.dump()); + assert_snapshot!(cf.dump().unwrap()); assert_display_snapshot!(cf); assert_debug_snapshot!(cf); } #[test] fn test_remove_plugin() { - let mut cf = MiseToml::init(PathBuf::from("/tmp/.mise.toml").as_path()); - cf.parse(&formatdoc! {r#" - [tools] - node = ["16.0.0", "18.0.0"] - "#}) - .unwrap(); - cf.remove_plugin(&"node".parse().unwrap()); + let p = PathBuf::from("/tmp/.mise.toml"); + file::write( + &p, + formatdoc! {r#" + [tools] + node = ["16.0.0", "18.0.0"] + "#}, + ) + .unwrap(); + let mut cf = MiseToml::from_file(&p).unwrap(); + cf.remove_plugin(&"node".parse().unwrap()).unwrap(); assert_debug_snapshot!(cf.toolset); let cf: Box = Box::new(cf); - assert_snapshot!(cf.dump()); + assert_snapshot!(cf.dump().unwrap()); assert_display_snapshot!(cf); assert_debug_snapshot!(cf); } @@ -1044,9 +1097,9 @@ mod tests { } fn parse(s: String) -> MiseToml { - let mut cf = MiseToml::init(PathBuf::from("/tmp/.mise.toml").as_path()); - cf.parse(&s).unwrap(); - cf + let p = CWD.as_ref().unwrap().join(".test.mise.toml"); + file::write(&p, s).unwrap(); + MiseToml::from_file(&p).unwrap() } fn parse_env(toml: String) -> String { diff --git a/src/config/config_file/mod.rs b/src/config/config_file/mod.rs index 693a3346e..fe238565b 100644 --- a/src/config/config_file/mod.rs +++ b/src/config/config_file/mod.rs @@ -70,10 +70,10 @@ pub trait ConfigFile: Debug + Send + Sync { fn tasks(&self) -> Vec<&Task> { Default::default() } - fn remove_plugin(&mut self, _fa: &ForgeArg); - fn replace_versions(&mut self, fa: &ForgeArg, versions: &[String]); + fn remove_plugin(&mut self, _fa: &ForgeArg) -> Result<()>; + fn replace_versions(&mut self, fa: &ForgeArg, versions: &[String]) -> Result<()>; fn save(&self) -> Result<()>; - fn dump(&self) -> String; + fn dump(&self) -> Result; fn to_toolset(&self) -> &Toolset; fn aliases(&self) -> AliasMap { Default::default() @@ -119,7 +119,7 @@ impl dyn ConfigFile { } }) .collect::>>()?; - self.replace_versions(&fa, &versions); + self.replace_versions(&fa, &versions)?; } Ok(()) diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-2.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-2.snap index a2587ae1e..ccb8ea352 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-2.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-2.snap @@ -1,5 +1,8 @@ --- source: src/config/config_file/mise_toml.rs -expression: cf.dump() +expression: cf.dump().unwrap() --- +min_version = "2024.1.1" +[env] +foo="bar" diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-3.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-3.snap index 7f358280f..efa04aea7 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-3.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-3.snap @@ -2,4 +2,4 @@ source: src/config/config_file/mise_toml.rs expression: cf --- -/tmp/.mise.toml: +~/cwd/.test.mise.toml: diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-4.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-4.snap index 11ebdc792..4377425bc 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-4.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__env-4.snap @@ -2,4 +2,12 @@ source: src/config/config_file/mise_toml.rs expression: cf --- -MiseToml(/tmp/.mise.toml): +MiseToml(~/cwd/.test.mise.toml): { + min_version: "2024.1.1", + env: [ + Val( + "foo", + "bar", + ), + ], +} diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-3.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-3.snap index 7f358280f..efa04aea7 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-3.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-3.snap @@ -2,4 +2,4 @@ source: src/config/config_file/mise_toml.rs expression: cf --- -/tmp/.mise.toml: +~/cwd/.test.mise.toml: diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-4.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-4.snap index 09d6b2add..87b849d77 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-4.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__remove_alias-4.snap @@ -2,7 +2,7 @@ source: src/config/config_file/mise_toml.rs expression: cf --- -MiseToml(/tmp/.mise.toml): { +MiseToml(~/cwd/.test.mise.toml): { alias: { ForgeArg("node"): { "18": "18.0.0", diff --git a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__set_alias-2.snap b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__set_alias-2.snap index 7f358280f..efa04aea7 100644 --- a/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__set_alias-2.snap +++ b/src/config/config_file/snapshots/mise__config__config_file__mise_toml__tests__set_alias-2.snap @@ -2,4 +2,4 @@ source: src/config/config_file/mise_toml.rs expression: cf --- -/tmp/.mise.toml: +~/cwd/.test.mise.toml: diff --git a/src/config/config_file/tool_versions.rs b/src/config/config_file/tool_versions.rs index aeb09d267..73494581a 100644 --- a/src/config/config_file/tool_versions.rs +++ b/src/config/config_file/tool_versions.rs @@ -159,23 +159,25 @@ impl ConfigFile for ToolVersions { self.path.as_path() } - fn remove_plugin(&mut self, fa: &ForgeArg) { + fn remove_plugin(&mut self, fa: &ForgeArg) -> Result<()> { self.plugins.shift_remove(fa); + Ok(()) } - fn replace_versions(&mut self, fa: &ForgeArg, versions: &[String]) { + fn replace_versions(&mut self, fa: &ForgeArg, versions: &[String]) -> eyre::Result<()> { self.get_or_create_plugin(fa).versions.clear(); for version in versions { self.add_version(fa, version); } + Ok(()) } fn save(&self) -> Result<()> { - let s = self.dump(); + let s = self.dump()?; file::write(&self.path, s) } - fn dump(&self) -> String { + fn dump(&self) -> eyre::Result { let mut s = self.pre.clone(); let max_plugin_len = self @@ -195,7 +197,7 @@ impl ConfigFile for ToolVersions { s.push_str(&format!("{} {}{}", plugin, tv.versions.join(" "), tv.post)); } - s.trim_end().to_string() + "\n" + Ok(s.trim_end().to_string() + "\n") } fn to_toolset(&self) -> &Toolset { @@ -238,7 +240,7 @@ pub(crate) mod tests { "}; let path = env::current_dir().unwrap().join(".test-tool-versions"); let tv = ToolVersions::parse_str(orig, path).unwrap(); - assert_eq!(tv.dump(), orig); + assert_eq!(tv.dump().unwrap(), orig); } #[test] @@ -248,7 +250,7 @@ pub(crate) mod tests { "}; let path = env::current_dir().unwrap().join(".test-tool-versions"); let tv = ToolVersions::parse_str(orig, path).unwrap(); - assert_snapshot!(tv.dump(), @r###" + assert_snapshot!(tv.dump().unwrap(), @r###" ruby 3.0.5 "###); } @@ -263,7 +265,7 @@ pub(crate) mod tests { assert_cli!("trust", path.to_string_lossy()); let tv = ToolVersions::parse_str(orig, path.clone()).unwrap(); assert_cli!("trust", "--untrust", path.to_string_lossy()); - assert_snapshot!(tv.dump(), @r###" + assert_snapshot!(tv.dump().unwrap(), @r###" ruby 3.0.5 python 3.11.0 "###); diff --git a/src/test.rs b/src/test.rs index 9ccf1a77e..fa0e2bb30 100644 --- a/src/test.rs +++ b/src/test.rs @@ -85,6 +85,7 @@ pub fn reset_config() { "#}, ) .unwrap(); + let _ = file::remove_file(".test.mise.toml"); } pub fn replace_path(input: &str) -> String {