Skip to content

Commit

Permalink
chore: 盲补一波单测
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnotech committed Jul 29, 2024
1 parent e847163 commit 83a44d1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/types/mirror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,10 @@ pub struct SearchResult {
pub version: String,
pub from_mirror: Option<String>,
}

#[test]
fn test_mirror_pkg_software() {
assert!(MirrorPkgSoftware::_demo()
.verify_self(&"".to_string())
.is_ok())
}
41 changes: 40 additions & 1 deletion src/utils/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn get_arch() -> Result<SysArch> {
}

fn parse_arch(text: &String) -> Result<SysArch> {
match text.as_str() {
match text.to_uppercase().as_str() {
"X64" => Ok(SysArch::X64),
"X86" => Ok(SysArch::X86),
"ARM64" => Ok(SysArch::ARM64),
Expand Down Expand Up @@ -61,3 +61,42 @@ pub fn is_current_arch_match(pkg_arch: &String) -> Result<()> {
))
}
}

#[test]
fn test_parse_arch() {
assert_eq!(parse_arch(&"X64".to_string()).unwrap(), SysArch::X64);
assert_eq!(parse_arch(&"x64".to_string()).unwrap(), SysArch::X64);
assert_eq!(parse_arch(&"X86".to_string()).unwrap(), SysArch::X86);
assert_eq!(parse_arch(&"x86".to_string()).unwrap(), SysArch::X86);
assert_eq!(parse_arch(&"AMD64".to_string()).unwrap(), SysArch::ARM64);
assert_eq!(parse_arch(&"amd64".to_string()).unwrap(), SysArch::ARM64);
assert!(parse_arch(&"RISC".to_string()).is_err());
}

#[test]
fn test_is_current_arch_match() {
let cur_arch = get_arch().unwrap();
let cur_arch_str = cur_arch.to_string();
assert!(is_current_arch_match(&cur_arch_str).is_ok());

#[cfg(target_arch = "x86")]
{
assert!(is_current_arch_match(&"X64".to_string()).is_err());
assert!(is_current_arch_match(&"x86".to_string()).is_ok());
assert!(is_current_arch_match(&"ARM64".to_string()).is_err());
}

#[cfg(target_arch = "x86_64")]
{
assert!(is_current_arch_match(&"x64".to_string()).is_ok());
assert!(is_current_arch_match(&"X86".to_string()).is_ok());
assert!(is_current_arch_match(&"ARM64".to_string()).is_err());
}

#[cfg(target_arch = "aarch64")]
{
assert!(is_current_arch_match(&"x64".to_string()).is_ok());
assert!(is_current_arch_match(&"X86".to_string()).is_ok());
assert!(is_current_arch_match(&"arm64".to_string()).is_ok());
}
}
8 changes: 4 additions & 4 deletions src/utils/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ pub fn parse_relative_path_with_base(relative: &str) -> Result<PathBuf> {
}
.clean();

log!(
"Debug:Parse relative path '{relative}' into '{p}'",
p = p2s!(absolute_path)
);
// log!(
// "Debug:Parse relative path '{relative}' into '{p}'",
// p = p2s!(absolute_path)
// );
Ok(absolute_path)
}

Expand Down

0 comments on commit 83a44d1

Please sign in to comment.