From ff17dcdb757656c5e81b10070a7bbcc4ef3e97f7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 06:39:08 +0900 Subject: refactor(path): build paths with Path::join Concatenating a directory, MAIN_SEPARATOR and a component reimplements what Path::join already does. Joining directly also drops the separator from the intermediate values it used to be baked into, such as ClassLoader's $pathEnd. Co-Authored-By: Claude Opus 5 (1M context) --- .../tests/repository/path_repository_test.rs | 81 ++++++++++++++-------- 1 file changed, 52 insertions(+), 29 deletions(-) (limited to 'crates/shirabe/tests/repository') diff --git a/crates/shirabe/tests/repository/path_repository_test.rs b/crates/shirabe/tests/repository/path_repository_test.rs index bd24504d..c892ddc7 100644 --- a/crates/shirabe/tests/repository/path_repository_test.rs +++ b/crates/shirabe/tests/repository/path_repository_test.rs @@ -10,6 +10,7 @@ use shirabe::util::http_downloader::HttpDownloader; use shirabe::util::r#loop::Loop; use shirabe::util::{Platform, ProcessExecutor}; use shirabe_php_shim::{PhpMixed, file_get_contents, hash, realpath, serialize}; +use std::path::Path; fn fixtures_dir() -> String { format!( @@ -49,8 +50,12 @@ fn coordinates(pairs: Vec<(&str, PhpMixed)>) -> IndexMap { #[test] fn test_load_package_from_file_system_with_incorrect_path() { - let repository_url = [fixtures_dir(), "path".to_string(), "missing".to_string()] - .join(std::path::MAIN_SEPARATOR_STR); + let repository_url = Path::new(&fixtures_dir()) + .join("path") + .join("missing") + .into_os_string() + .into_string() + .unwrap(); let mut repository = create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))])); assert!(repository.__get_packages().is_err()); @@ -58,12 +63,12 @@ fn test_load_package_from_file_system_with_incorrect_path() { #[test] fn test_load_package_from_file_system_with_version() { - let repository_url = [ - fixtures_dir(), - "path".to_string(), - "with-version".to_string(), - ] - .join(std::path::MAIN_SEPARATOR_STR); + let repository_url = Path::new(&fixtures_dir()) + .join("path") + .join("with-version") + .into_os_string() + .into_string() + .unwrap(); let mut repository = create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))])); repository.__get_packages().unwrap(); @@ -78,12 +83,12 @@ fn test_load_package_from_file_system_with_version() { #[test] fn test_load_package_from_file_system_without_version() { - let repository_url = [ - fixtures_dir(), - "path".to_string(), - "without-version".to_string(), - ] - .join(std::path::MAIN_SEPARATOR_STR); + let repository_url = Path::new(&fixtures_dir()) + .join("path") + .join("without-version") + .into_os_string() + .into_string() + .unwrap(); let mut repository = create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))])); let packages = repository.__get_packages().unwrap(); @@ -99,8 +104,12 @@ fn test_load_package_from_file_system_without_version() { #[test] fn test_load_package_from_file_system_with_wildcard() { - let repository_url = - [fixtures_dir(), "path".to_string(), "*".to_string()].join(std::path::MAIN_SEPARATOR_STR); + let repository_url = Path::new(&fixtures_dir()) + .join("path") + .join("*") + .into_os_string() + .into_string() + .unwrap(); let mut repository = create_path_repo(coordinates(vec![("url", PhpMixed::String(repository_url))])); let packages = repository.__get_packages().unwrap(); @@ -137,8 +146,12 @@ fn test_load_package_with_explicit_versions() { ); let options = coordinates(vec![("versions", PhpMixed::Array(versions))]); - let repository_url = - [fixtures_dir(), "path".to_string(), "*".to_string()].join(std::path::MAIN_SEPARATOR_STR); + let repository_url = Path::new(&fixtures_dir()) + .join("path") + .join("*") + .into_os_string() + .into_string() + .unwrap(); let mut repository = create_path_repo(coordinates(vec![ ("url", PhpMixed::String(repository_url)), ("options", PhpMixed::Array(options)), @@ -198,14 +211,16 @@ fn test_url_remains_relative() { // realpath() does not fully expand the paths // PHP Bug https://bugs.php.net/bug.php?id=72642 - let repository_url = [ - realpath(realpath(fixtures_dir().replace("/Fixtures", "")).unwrap_or_default()) + let repository_url = Path::new( + &realpath(realpath(fixtures_dir().replace("/Fixtures", "")).unwrap_or_default()) .unwrap_or_default(), - "Fixtures".to_string(), - "path".to_string(), - "with-version".to_string(), - ] - .join(std::path::MAIN_SEPARATOR_STR); + ) + .join("Fixtures") + .join("path") + .join("with-version") + .into_os_string() + .into_string() + .unwrap(); // getcwd() not necessarily match __DIR__ // PHP Bug https://bugs.php.net/bug.php?id=73797 let cwd = realpath(realpath(Platform::get_cwd(false).unwrap()).unwrap_or_default()) @@ -233,8 +248,12 @@ fn test_url_remains_relative() { #[test] fn test_reference_none() { let options = coordinates(vec![("reference", PhpMixed::String("none".to_string()))]); - let repository_url = - [fixtures_dir(), "path".to_string(), "*".to_string()].join(std::path::MAIN_SEPARATOR_STR); + let repository_url = Path::new(&fixtures_dir()) + .join("path") + .join("*") + .into_os_string() + .into_string() + .unwrap(); let mut repository = create_path_repo(coordinates(vec![ ("url", PhpMixed::String(repository_url)), ("options", PhpMixed::Array(options)), @@ -254,8 +273,12 @@ fn test_reference_config() { ("reference", PhpMixed::String("config".to_string())), ("relative", PhpMixed::Bool(true)), ]); - let repository_url = - [fixtures_dir(), "path".to_string(), "*".to_string()].join(std::path::MAIN_SEPARATOR_STR); + let repository_url = Path::new(&fixtures_dir()) + .join("path") + .join("*") + .into_os_string() + .into_string() + .unwrap(); let mut repository = create_path_repo(coordinates(vec![ ("url", PhpMixed::String(repository_url)), ("options", PhpMixed::Array(options.clone())), -- cgit v1.3.1-4-g156e