Skip to content

Commit

Permalink
code formatting made better
Browse files Browse the repository at this point in the history
Signed-off-by: d4v1d03 <[email protected]>
  • Loading branch information
d4v1d03 committed Feb 15, 2024
1 parent ae330f9 commit ae47cd3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
3 changes: 1 addition & 2 deletions kclvm/driver/src/kpm_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -183,4 +182,4 @@ fn probe(path: PathBuf) -> Option<PathBuf> {
iter::once(path)
.chain(with_extension)
.find(|it| it.is_file())
}
}
11 changes: 6 additions & 5 deletions kclvm/driver/src/kpm_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
48 changes: 24 additions & 24 deletions kclvm/driver/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<MockCommandOutput, std::io::Error>,
}
// Define a mock structure to represent the output of Command::output
struct MockCommandOutput {
status: std::process::ExitStatus,
stderr: Vec<u8>,
}
// Define a mock structure to simulate the behavior of Command::output
struct MockCommand {
output: Result<MockCommandOutput, std::io::Error>,
}
// Define a mock structure to represent the output of Command::output
struct MockCommandOutput {
status: std::process::ExitStatus,
stderr: Vec<u8>,
}

#[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());
}
let result = update_kcl_module( manifest_path);
assert!(result.is_err());
}

0 comments on commit ae47cd3

Please sign in to comment.