mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 11:48:36 +00:00
fix(ci): fix tests
This commit is contained in:
@@ -85,12 +85,7 @@ pub fn package_root_from_registry_info(pkg_info: &JsonValue) -> Result<PathBuf,
|
||||
return Err("Registry package path is empty".to_string());
|
||||
}
|
||||
|
||||
let path = Path::new(raw_path);
|
||||
let full_path = if path.is_absolute() {
|
||||
path.to_path_buf()
|
||||
} else {
|
||||
get_registry_cache_root().join(path)
|
||||
};
|
||||
let full_path = registry_path_to_pathbuf(raw_path.trim());
|
||||
|
||||
if full_path.file_name().and_then(|v| v.to_str()) == Some("dcr.toml") {
|
||||
return full_path
|
||||
@@ -102,6 +97,39 @@ pub fn package_root_from_registry_info(pkg_info: &JsonValue) -> Result<PathBuf,
|
||||
Ok(full_path)
|
||||
}
|
||||
|
||||
pub fn registry_path_to_pathbuf(raw: &str) -> PathBuf {
|
||||
let s = raw.trim();
|
||||
if let Some(rest) = s.strip_prefix("file://") {
|
||||
if rest.len() >= 3 && rest.as_bytes()[0] == b'/' && rest.as_bytes()[2] == b':' {
|
||||
return PathBuf::from(&rest[1..]);
|
||||
}
|
||||
if rest.len() >= 2 && rest.as_bytes()[1] == b':' {
|
||||
return PathBuf::from(rest);
|
||||
}
|
||||
if rest.starts_with('/') {
|
||||
return PathBuf::from(rest);
|
||||
}
|
||||
return PathBuf::from(format!("/{rest}"));
|
||||
}
|
||||
|
||||
let mut s = s.replace('\\', "/");
|
||||
if let Some(rest) = s.strip_prefix("//?/") {
|
||||
s = rest.to_string();
|
||||
} else if let Some(rest) = s.strip_prefix("//./") {
|
||||
s = rest.to_string();
|
||||
}
|
||||
if s.len() >= 3 && s.as_bytes()[0] == b'/' && s.as_bytes()[2] == b':' {
|
||||
s = s[1..].to_string();
|
||||
}
|
||||
|
||||
let path = PathBuf::from(&s);
|
||||
if path.is_absolute() || (s.len() >= 2 && s.as_bytes()[1] == b':') || s.starts_with('/') {
|
||||
path
|
||||
} else {
|
||||
get_registry_cache_root().join(path)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn registry_include_dir(dep_root: &Path) -> PathBuf {
|
||||
dep_root.join("target").join("include")
|
||||
}
|
||||
@@ -244,4 +272,19 @@ mod tests {
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registry_path_strips_windows_extended_prefix() {
|
||||
let p = registry_path_to_pathbuf("//?/D:/cache/mylib");
|
||||
let s = p.to_string_lossy().replace('\\', "/");
|
||||
assert_eq!(s, "D:/cache/mylib");
|
||||
|
||||
let p2 = registry_path_to_pathbuf("/D:/cache/mylib");
|
||||
let s2 = p2.to_string_lossy().replace('\\', "/");
|
||||
assert_eq!(s2, "D:/cache/mylib");
|
||||
|
||||
let p3 = registry_path_to_pathbuf("file:///D:/cache/mylib");
|
||||
let s3 = p3.to_string_lossy().replace('\\', "/");
|
||||
assert_eq!(s3, "D:/cache/mylib");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,16 +117,24 @@ fn registry_dependency_is_built_from_cache() {
|
||||
"[registry.local]\nurl = \"file://local\"\npriority = 1\n",
|
||||
)
|
||||
.expect("failed to write registry config");
|
||||
let dep_path = dep
|
||||
.canonicalize()
|
||||
.unwrap_or(dep.clone())
|
||||
.to_string_lossy()
|
||||
.replace('\\', "/");
|
||||
let dep_abs = dep.canonicalize().unwrap_or(dep.clone());
|
||||
let mut dep_path = dep_abs.to_string_lossy().replace('\\', "/");
|
||||
if let Some(rest) = dep_path.strip_prefix("//?/") {
|
||||
dep_path = rest.to_string();
|
||||
}
|
||||
if dep_path.len() >= 3 && dep_path.as_bytes()[0] == b'/' && dep_path.as_bytes()[2] == b':' {
|
||||
dep_path = dep_path[1..].to_string();
|
||||
}
|
||||
std::fs::write(
|
||||
dcr_home.join("index.json"),
|
||||
format!(
|
||||
"{{\"packages\":[{{\"name\":\"mylib\",\"latest_version\":\"0.1.0\",\"path\":\"{dep_path}\"}}]}}"
|
||||
),
|
||||
serde_json::json!({
|
||||
"packages": [{
|
||||
"name": "mylib",
|
||||
"latest_version": "0.1.0",
|
||||
"path": dep_path
|
||||
}]
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
.expect("failed to write registry index");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user