diff --git a/kclvm/driver/src/kpm_metadata.rs b/kclvm/driver/src/kpm_metadata.rs index 5f489beda..996d404fa 100644 --- a/kclvm/driver/src/kpm_metadata.rs +++ b/kclvm/driver/src/kpm_metadata.rs @@ -3,7 +3,6 @@ use kclvm_parser::LoadProgramOptions; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, env, iter, path::PathBuf, process::Command}; - const MANIFEST_FILE: &str = "kcl.mod"; /// [`fill_pkg_maps_for_k_file`] will call `kpm metadata` to obtain the metadata @@ -183,4 +182,4 @@ fn probe(path: PathBuf) -> Option { iter::once(path) .chain(with_extension) .find(|it| it.is_file()) -} \ No newline at end of file +} diff --git a/kclvm/driver/src/kpm_update.rs b/kclvm/driver/src/kpm_update.rs index d791f17a3..56e673f0c 100644 --- a/kclvm/driver/src/kpm_update.rs +++ b/kclvm/driver/src/kpm_update.rs @@ -2,11 +2,10 @@ use anyhow::{bail, Result}; use std::{path::PathBuf, process::Command}; use crate::kpm_metadata::get_path_for_executable; - const MANIFEST_FILE: &str = "kcl.mod"; - -pub(crate) fn update_kcl_module(manifest_path: PathBuf) -> Result<()> {match lookup_the_nearest_file_dir(manifest_path.clone(), MANIFEST_FILE) { +pub(crate) fn update_kcl_module(manifest_path: PathBuf) -> Result<()> { + match lookup_the_nearest_file_dir(manifest_path.clone(), MANIFEST_FILE) { Some(mod_dir) => { match Command::new(kcl()) .arg("mod") @@ -26,7 +25,10 @@ pub(crate) fn update_kcl_module(manifest_path: PathBuf) -> Result<()> {match loo Err(err) => bail!("update failed with error: {}", err), } } - None => bail!("Manifest file '{}' not found in directory hierarchy", MANIFEST_FILE), + None => bail!( + "Manifest file '{}' not found in directory hierarchy", + MANIFEST_FILE + ), } } pub fn kcl() -> PathBuf { @@ -47,7 +49,6 @@ pub(crate) fn lookup_the_nearest_file_dir( if found_path.is_file() { return current_dir.canonicalize().ok(); } - match current_dir.parent() { Some(parent) => current_dir = parent.to_path_buf(), None => return None, diff --git a/kclvm/driver/src/tests.rs b/kclvm/driver/src/tests.rs index 1c3406217..fe08f347f 100644 --- a/kclvm/driver/src/tests.rs +++ b/kclvm/driver/src/tests.rs @@ -1,6 +1,6 @@ +use super::*; use std::path::{Path, PathBuf}; use std::{env, fs, panic}; -use super::*; use kclvm_config::modfile::get_vendor_home; use kclvm_config::settings::KeyValuePair; @@ -383,32 +383,32 @@ fn test_get_pkg_list() { } #[cfg(test)] - // Define a mock structure to simulate the behavior of Command::output - struct MockCommand { - output: Result, - } - // Define a mock structure to represent the output of Command::output - struct MockCommandOutput { - status: std::process::ExitStatus, - stderr: Vec, - } +// Define a mock structure to simulate the behavior of Command::output + struct MockCommand { + output: Result, +} +// Define a mock structure to represent the output of Command::output +struct MockCommandOutput { + status: std::process::ExitStatus, + stderr: Vec, + } - #[test] - fn test_update_kcl_module_success() { - let manifest_path = PathBuf::from("path/to/manifest"); - let result = update_kcl_module( manifest_path); - assert!(result.is_ok()); - } +#[test] +fn test_update_kcl_module_success() { + let manifest_path = PathBuf::from("path/to/manifest"); + let result = update_kcl_module( manifest_path); + assert!(result.is_ok() + ); +} - #[test] - fn test_update_kcl_module_failure() { - - let manifest_path = PathBuf::from("path/to/manifest"); - fn mock_command_new_failing(_command: &str) -> MockCommand { +#[test] +fn test_update_kcl_module_failure() { + let manifest_path = PathBuf::from("path/to/manifest"); + fn mock_command_new_failing(_command: &str) -> MockCommand { MockCommand { output: Err(std::io::Error::new(std::io::ErrorKind::Other, "Command failed")), } } - let result = update_kcl_module( manifest_path); - assert!(result.is_err()); - } \ No newline at end of file + let result = update_kcl_module( manifest_path); + assert!(result.is_err()); +} \ No newline at end of file