diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 12:40:10 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 12:40:10 +0900 |
| commit | 2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264 (patch) | |
| tree | ff8bbb00238526c376f521647adc9ea9f486b84c /crates/shirabe/tests | |
| parent | 4b92ecafd7634ad99aa432d58fbc1958d1f01270 (diff) | |
| download | php-shirabe-2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264.tar.gz php-shirabe-2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264.tar.zst php-shirabe-2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264.zip | |
test(tests): port setUp/tearDown as set_up/tear_down with TearDown
Port PHP setUp/tearDown across the ported integration tests using
same-named set_up()/tear_down() functions and a TearDown struct whose
Drop runs tear_down(). Fixture-init setUp returns its fixtures;
tmpdir-style setUp/tearDown carry state in TearDown fields. Parts that
depend on unported infrastructure (PHPUnit mocks, Config::merge, the PHP
error handler) stay todo!() and are only wired into ignored stubs to
avoid breaking live tests.
Also fix shirabe-php-shim putenv to handle the no-'=' form (PHP unsets
the variable), which Platform::clear_env relies on for the env-clearing
tearDowns.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests')
59 files changed, 1834 insertions, 19 deletions
diff --git a/crates/shirabe/tests/all_functional_test.rs b/crates/shirabe/tests/all_functional_test.rs index 99a7ad0..7b3b228 100644 --- a/crates/shirabe/tests/all_functional_test.rs +++ b/crates/shirabe/tests/all_functional_test.rs @@ -3,11 +3,30 @@ // These build the composer.phar and run the .test integration fixtures by invoking the // composer binary as a subprocess; the phar build and functional-test harness are not // ported. + +// setUp only does cwd management (chdir into Fixtures/functional), which is intentionally +// not ported, so it has no portable body. + +// The chdir back to oldcwd is cwd management (not ported); the removeDirectory of testDir +// targets a path produced by the unported functional-test run. +fn tear_down() { + todo!() +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + macro_rules! stub { ($name:ident) => { #[test] #[ignore = "not yet ported (builds composer.phar and runs the functional .test fixtures via the binary)"] fn $name() { + let _tear_down = TearDown; todo!() } }; diff --git a/crates/shirabe/tests/application_test.rs b/crates/shirabe/tests/application_test.rs index 8251310..856c1b7 100644 --- a/crates/shirabe/tests/application_test.rs +++ b/crates/shirabe/tests/application_test.rs @@ -3,32 +3,65 @@ // These drive the console Application (doRun, getDisplay, plugin disabling, command // resolution) via ApplicationTester, none of which are ported. +use shirabe::util::platform::Platform; + +fn set_up() { + Platform::put_env("COMPOSER_DISABLE_XDEBUG_WARN", "1"); +} + +fn tear_down() { + Platform::clear_env("COMPOSER_DISABLE_XDEBUG_WARN"); +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + #[test] #[ignore = "requires the console Application/ApplicationTester harness, which is not yet ported"] fn test_dev_warning() { + let _tear_down = TearDown; + set_up(); + todo!() } #[test] #[ignore = "requires the console Application/ApplicationTester harness, which is not yet ported"] fn test_dev_warning_suppressed_for_self_update() { + let _tear_down = TearDown; + set_up(); + todo!() } #[test] #[ignore = "requires the console Application/ApplicationTester harness, which is not yet ported"] fn test_process_isolation_works_multiple_times() { + let _tear_down = TearDown; + set_up(); + todo!() } #[test] #[ignore = "requires the console Application/ApplicationTester harness, which is not yet ported"] fn test_no_plugins_disables_plugins_when_script_commands_exist() { + let _tear_down = TearDown; + set_up(); + todo!() } #[test] #[ignore = "requires the console Application/ApplicationTester harness, which is not yet ported"] fn test_script_command_takes_priority_over_abbreviated_builtin_command() { + let _tear_down = TearDown; + set_up(); + todo!() } diff --git a/crates/shirabe/tests/autoload/autoload_generator_test.rs b/crates/shirabe/tests/autoload/autoload_generator_test.rs index ecd6e4e..6b7c11a 100644 --- a/crates/shirabe/tests/autoload/autoload_generator_test.rs +++ b/crates/shirabe/tests/autoload/autoload_generator_test.rs @@ -1,5 +1,27 @@ //! ref: composer/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +/// Creates the working/vendor temp directories, switches into the working dir, and +/// builds the AutoloadGenerator from a mocked Config/InstallationManager/ +/// InstalledRepository/EventDispatcher and a BufferIO. The mocks and temp-dir +/// helpers are not available here, so this remains a stub. +fn set_up() { + todo!() +} + +/// Restores the original working directory and removes the working/vendor +/// directories created by `set_up`, which is itself a stub. +fn tear_down() { + todo!() +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + // These exercise AutoloadGenerator end-to-end: they build packages, write fixture files to // a temp dir, run dump() through a mocked InstalledRepository/EventDispatcher and compare // the generated autoload files. The integration setup (fixtures, mocks, filesystem) is not diff --git a/crates/shirabe/tests/cache_test.rs b/crates/shirabe/tests/cache_test.rs index 3849705..1e346cf 100644 --- a/crates/shirabe/tests/cache_test.rs +++ b/crates/shirabe/tests/cache_test.rs @@ -1,25 +1,79 @@ //! ref: composer/tests/Composer/Test/CacheTest.php use std::cell::RefCell; +use std::fs; use std::rc::Rc; use shirabe::cache::Cache; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; +use shirabe::util::filesystem::Filesystem; use tempfile::TempDir; +struct SetUp { + root: TempDir, + files: Vec<std::path::PathBuf>, + cache: Cache, +} + +fn set_up() -> SetUp { + let root = TempDir::new().unwrap(); + let mut files: Vec<std::path::PathBuf> = Vec::new(); + let zeros = "0".repeat(1000); + + for i in 0..4 { + let path = root.path().join(format!("cached.file{}.zip", i)); + fs::write(&path, &zeros).unwrap(); + files.push(path); + } + + // The finder/filesystem/IO mocks and the Cache mock overriding getFinder are not ported. + let cache: Cache = todo!(); + + SetUp { root, files, cache } +} + +fn tear_down(root: &std::path::Path) { + if root.is_dir() { + let mut fs = Filesystem::new(None); + fs.remove_directory(root).unwrap(); + } +} + +struct TearDown { + root: std::path::PathBuf, +} + +impl TearDown { + fn new(root: std::path::PathBuf) -> Self { + TearDown { root } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.root); + } +} + // In PHP these mock Cache::getFinder() to feed the gc() routine a controlled set of // files. getFinder is pub(crate) and cannot be overridden from a test, so the // finder-driven removal paths cannot be exercised faithfully here. #[test] #[ignore = "mocks Cache::getFinder to drive gc(); getFinder cannot be overridden from a test"] fn test_remove_outdated_files() { + let SetUp { root, files, cache } = set_up(); + let _tear_down = TearDown::new(root.path().to_path_buf()); + let _ = (&files, &cache); todo!() } #[test] #[ignore = "mocks Cache::getFinder to drive gc(); getFinder cannot be overridden from a test"] fn test_remove_files_when_cache_is_too_large() { + let SetUp { root, files, cache } = set_up(); + let _tear_down = TearDown::new(root.path().to_path_buf()); + let _ = (&files, &cache); todo!() } diff --git a/crates/shirabe/tests/command/clear_cache_command_test.rs b/crates/shirabe/tests/command/clear_cache_command_test.rs index 0e03548..29a745b 100644 --- a/crates/shirabe/tests/command/clear_cache_command_test.rs +++ b/crates/shirabe/tests/command/clear_cache_command_test.rs @@ -1,19 +1,40 @@ //! ref: composer/tests/Composer/Test/Command/ClearCacheCommandTest.php +use shirabe::util::platform::Platform; + +fn tear_down() { + // --no-cache triggers the env to change so make sure the env is cleaned up after these tests run + Platform::clear_env("COMPOSER_CACHE_DIR"); +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + #[test] #[ignore = "requires the ApplicationTester/initTempComposer harness, which is not yet ported"] fn test_clear_cache_command_success() { + let _tear_down = TearDown; + todo!() } #[test] #[ignore = "requires the ApplicationTester/initTempComposer harness, which is not yet ported"] fn test_clear_cache_command_with_option_garbage_collection() { + let _tear_down = TearDown; + todo!() } #[test] #[ignore = "requires the ApplicationTester/initTempComposer harness, which is not yet ported"] fn test_clear_cache_command_with_option_no_cache() { + let _tear_down = TearDown; + todo!() } diff --git a/crates/shirabe/tests/command/global_command_test.rs b/crates/shirabe/tests/command/global_command_test.rs index 274f5cf..7877b3c 100644 --- a/crates/shirabe/tests/command/global_command_test.rs +++ b/crates/shirabe/tests/command/global_command_test.rs @@ -1,10 +1,27 @@ //! ref: composer/tests/Composer/Test/Command/GlobalCommandTest.php +use shirabe::util::platform::Platform; + +fn tear_down() { + Platform::clear_env("COMPOSER_HOME"); + Platform::clear_env("COMPOSER"); +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + macro_rules! stub { ($name:ident) => { #[test] #[ignore = "requires the ApplicationTester/initTempComposer harness, which is not yet ported"] fn $name() { + let _tear_down = TearDown; + todo!() } }; diff --git a/crates/shirabe/tests/command/init_command_test.rs b/crates/shirabe/tests/command/init_command_test.rs index 69d721b..e7cda3e 100644 --- a/crates/shirabe/tests/command/init_command_test.rs +++ b/crates/shirabe/tests/command/init_command_test.rs @@ -3,11 +3,20 @@ // The author/namespace/git-config helpers are protected methods exercised via reflection // in PHP; the run cases need the ApplicationTester. Neither is available here. +use shirabe_php_shim::server_set; + +fn set_up() { + server_set("COMPOSER_DEFAULT_AUTHOR", "John Smith".to_string()); + server_set("COMPOSER_DEFAULT_EMAIL", "john@example.com".to_string()); +} + macro_rules! stub { ($name:ident) => { #[test] #[ignore = "needs the ApplicationTester harness or reflection into protected InitCommand helpers"] fn $name() { + set_up(); + todo!() } }; diff --git a/crates/shirabe/tests/command/licenses_command_test.rs b/crates/shirabe/tests/command/licenses_command_test.rs index e1dfe20..26a7520 100644 --- a/crates/shirabe/tests/command/licenses_command_test.rs +++ b/crates/shirabe/tests/command/licenses_command_test.rs @@ -1,10 +1,18 @@ //! ref: composer/tests/Composer/Test/Command/LicensesCommandTest.php +fn set_up() { + // Builds the temp project and installed.json/composer.lock fixtures via + // initTempComposer/createInstalledJson/createComposerLock, none of which are ported yet. + todo!() +} + macro_rules! stub { ($name:ident) => { #[test] #[ignore = "requires the ApplicationTester/initTempComposer harness, which is not yet ported"] fn $name() { + set_up(); + todo!() } }; diff --git a/crates/shirabe/tests/command/self_update_command_test.rs b/crates/shirabe/tests/command/self_update_command_test.rs index a4b7358..d741302 100644 --- a/crates/shirabe/tests/command/self_update_command_test.rs +++ b/crates/shirabe/tests/command/self_update_command_test.rs @@ -1,25 +1,39 @@ //! ref: composer/tests/Composer/Test/Command/SelfUpdateCommandTest.php +/// Returns the path to the copied composer.phar used by the test bodies. +fn set_up() -> String { + // Depends on initTempComposer and the composer-test.phar fixture, neither ported yet. + todo!() +} + #[test] #[ignore = "requires the ApplicationTester harness, which is not yet ported"] fn test_successful_update() { + let _phar = set_up(); + todo!() } #[test] #[ignore = "requires the ApplicationTester harness, which is not yet ported"] fn test_update_to_specific_version() { + let _phar = set_up(); + todo!() } #[test] #[ignore = "requires the ApplicationTester harness, which is not yet ported"] fn test_update_with_invalid_option_throws_exception() { + let _phar = set_up(); + todo!() } #[test] #[ignore = "requires the ApplicationTester harness, which is not yet ported"] fn test_update_to_different_channel() { + let _phar = set_up(); + todo!() } diff --git a/crates/shirabe/tests/config/json_config_source_test.rs b/crates/shirabe/tests/config/json_config_source_test.rs index 293f32e..bab36a9 100644 --- a/crates/shirabe/tests/config/json_config_source_test.rs +++ b/crates/shirabe/tests/config/json_config_source_test.rs @@ -1,5 +1,36 @@ //! ref: composer/tests/Composer/Test/Config/JsonConfigSourceTest.php +use shirabe::util::filesystem::Filesystem; +use std::path::PathBuf; +use tempfile::TempDir; + +fn set_up() -> TearDown { + let fs = Filesystem::new(None); + // getUniqueTmpDirectory creates a fresh unique temp directory. + let working_dir = TempDir::new().unwrap(); + TearDown { fs, working_dir } +} + +struct TearDown { + fs: Filesystem, + working_dir: TempDir, +} + +impl TearDown { + fn working_dir(&self) -> PathBuf { + self.working_dir.path().to_path_buf() + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + let working_dir = self.working_dir.path(); + if working_dir.is_dir() { + self.fs.remove_directory(working_dir).unwrap(); + } + } +} + // JsonConfigSource edits composer.json through JsonManipulator, whose text-rewriting // operations reach addcslashes (todo!()) in the php-shim. macro_rules! stub { @@ -7,6 +38,7 @@ macro_rules! stub { #[test] #[ignore = "JsonConfigSource uses JsonManipulator, which reaches addcslashes (todo!()) in the php-shim"] fn $name() { + let _tear_down = set_up(); todo!() } }; diff --git a/crates/shirabe/tests/dependency_resolver/default_policy_test.rs b/crates/shirabe/tests/dependency_resolver/default_policy_test.rs index b852c46..979261e 100644 --- a/crates/shirabe/tests/dependency_resolver/default_policy_test.rs +++ b/crates/shirabe/tests/dependency_resolver/default_policy_test.rs @@ -1,5 +1,53 @@ //! ref: composer/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php +use indexmap::IndexMap; +use shirabe::dependency_resolver::default_policy::DefaultPolicy; +use shirabe::repository::array_repository::ArrayRepository; +use shirabe::repository::lock_array_repository::LockArrayRepository; +use shirabe::repository::repository_set::RepositorySet; +use shirabe::util::platform::Platform; + +#[allow(dead_code)] +struct Fixtures { + repository_set: RepositorySet, + repo: ArrayRepository, + repo_locked: LockArrayRepository, + policy: DefaultPolicy, +} + +fn set_up() -> Fixtures { + let repository_set = RepositorySet::new( + "dev", + IndexMap::new(), + vec![], + IndexMap::new(), + IndexMap::new(), + IndexMap::new(), + ); + let repo = ArrayRepository::new(vec![]).unwrap(); + let repo_locked = LockArrayRepository::new(vec![]).unwrap(); + + let policy = DefaultPolicy::new(false, false, None); + + Fixtures { + repository_set, + repo, + repo_locked, + policy, + } +} + +fn tear_down() { + Platform::clear_env("COMPOSER_PREFER_DEV_OVER_PRERELEASE"); +} + +struct TearDown; +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + // These build a Pool from packages and exercise DefaultPolicy::selectPreferredPackages. // Constructing the packages/constraints parses versions through a look-around regex the // regex crate cannot compile, and the setup mirrors the solver fixtures. @@ -8,6 +56,8 @@ macro_rules! stub { #[test] #[ignore = "not yet ported (DefaultPolicy over a Pool; constraint parsing uses a look-around regex)"] fn $name() { + let _tear_down = TearDown; + let _fixtures = set_up(); todo!() } }; diff --git a/crates/shirabe/tests/dependency_resolver/rule_set_iterator_test.rs b/crates/shirabe/tests/dependency_resolver/rule_set_iterator_test.rs index d654dd7..9bb939b 100644 --- a/crates/shirabe/tests/dependency_resolver/rule_set_iterator_test.rs +++ b/crates/shirabe/tests/dependency_resolver/rule_set_iterator_test.rs @@ -5,6 +5,7 @@ use std::rc::Rc; use indexmap::IndexMap; use shirabe::dependency_resolver::generic_rule::GenericRule; +use shirabe::dependency_resolver::pool::Pool; use shirabe::dependency_resolver::rule::{RULE_LEARNED, RULE_ROOT_REQUIRE, ReasonData, Rule}; use shirabe::dependency_resolver::rule_set::RuleSet; use shirabe::dependency_resolver::rule_set_iterator::RuleSetIterator; @@ -23,8 +24,16 @@ fn root_require_rule() -> Rc<RefCell<Rule>> { )))) } -// Mirrors the original setUp(). -fn make_rules() -> Rules { +fn set_up() -> (Pool, Rules) { + let pool = Pool::new( + vec![], + vec![], + IndexMap::new(), + IndexMap::new(), + IndexMap::new(), + IndexMap::new(), + ); + let mut rules: Rules = IndexMap::new(); rules.insert( RuleSet::TYPE_REQUEST, @@ -39,12 +48,13 @@ fn make_rules() -> Rules { ))))], ); rules.insert(RuleSet::TYPE_PACKAGE, vec![]); - rules + + (pool, rules) } #[test] fn test_foreach() { - let rules = make_rules(); + let (_pool, rules) = set_up(); let mut rule_set_iterator = RuleSetIterator::new(rules.clone()); let mut result: Vec<Rc<RefCell<Rule>>> = Vec::new(); @@ -67,7 +77,7 @@ fn test_foreach() { #[test] fn test_keys() { - let rules = make_rules(); + let (_pool, rules) = set_up(); let mut rule_set_iterator = RuleSetIterator::new(rules); let mut result: Vec<i64> = Vec::new(); diff --git a/crates/shirabe/tests/dependency_resolver/solver_test.rs b/crates/shirabe/tests/dependency_resolver/solver_test.rs index 9fc0434..8d41086 100644 --- a/crates/shirabe/tests/dependency_resolver/solver_test.rs +++ b/crates/shirabe/tests/dependency_resolver/solver_test.rs @@ -1,5 +1,46 @@ //! ref: composer/tests/Composer/Test/DependencyResolver/SolverTest.php +use indexmap::IndexMap; +use shirabe::dependency_resolver::default_policy::DefaultPolicy; +use shirabe::dependency_resolver::request::Request; +use shirabe::repository::array_repository::ArrayRepository; +use shirabe::repository::handle::LockArrayRepositoryHandle; +use shirabe::repository::lock_array_repository::LockArrayRepository; +use shirabe::repository::repository_set::RepositorySet; + +#[allow(dead_code)] +struct Fixtures { + repo_set: RepositorySet, + repo: ArrayRepository, + repo_locked: LockArrayRepositoryHandle, + request: Request, + policy: DefaultPolicy, +} + +fn set_up() -> Fixtures { + let repo_set = RepositorySet::new( + "stable", + IndexMap::new(), + vec![], + IndexMap::new(), + IndexMap::new(), + IndexMap::new(), + ); + let repo = ArrayRepository::new(vec![]).unwrap(); + let repo_locked = LockArrayRepositoryHandle::new(LockArrayRepository::new(vec![]).unwrap()); + + let request = Request::new(Some(repo_locked.clone())); + let policy = DefaultPolicy::new(false, false, None); + + Fixtures { + repo_set, + repo, + repo_locked, + request, + policy, + } +} + // These run the dependency Solver over packages/requests built from version constraints, // whose parsing goes through a look-around regex the regex crate cannot compile; the setup // also mirrors the larger solver fixtures. @@ -8,6 +49,7 @@ macro_rules! stub { #[test] #[ignore = "not yet ported (runs the Solver; constraint parsing uses a look-around regex)"] fn $name() { + let _fixtures = set_up(); todo!() } }; diff --git a/crates/shirabe/tests/downloader/download_manager_test.rs b/crates/shirabe/tests/downloader/download_manager_test.rs index a047420..4bb0f0b 100644 --- a/crates/shirabe/tests/downloader/download_manager_test.rs +++ b/crates/shirabe/tests/downloader/download_manager_test.rs @@ -1,5 +1,10 @@ //! ref: composer/tests/Composer/Test/Downloader/DownloadManagerTest.php +fn set_up() { + // The Filesystem and IO mocks are not ported. + todo!() +} + // These mock IO and individual downloaders to drive DownloadManager's selection/download/ // update/remove logic; mocking is not available here. macro_rules! stub { @@ -7,6 +12,7 @@ macro_rules! stub { #[test] #[ignore = "mocks IO and individual downloaders to drive DownloadManager; mocking is not available"] fn $name() { + set_up(); todo!() } }; diff --git a/crates/shirabe/tests/downloader/file_downloader_test.rs b/crates/shirabe/tests/downloader/file_downloader_test.rs index 4e9cbc6..6e123e1 100644 --- a/crates/shirabe/tests/downloader/file_downloader_test.rs +++ b/crates/shirabe/tests/downloader/file_downloader_test.rs @@ -1,5 +1,10 @@ //! ref: composer/tests/Composer/Test/Downloader/FileDownloaderTest.php +fn set_up() { + // The HttpDownloader mock (disableOriginalConstructor) is not ported. + todo!() +} + // These construct a FileDownloader with a mocked IO/HttpDownloader (curl_multi_init todo!()) // and a mocked Cache/Package to drive download/checksum behaviour. macro_rules! stub { @@ -7,6 +12,7 @@ macro_rules! stub { #[test] #[ignore = "mocks IO/HttpDownloader (curl_multi_init todo!()) and Cache/Package"] fn $name() { + set_up(); todo!() } }; diff --git a/crates/shirabe/tests/downloader/fossil_downloader_test.rs b/crates/shirabe/tests/downloader/fossil_downloader_test.rs index 89e0a9d..9c9dbe4 100644 --- a/crates/shirabe/tests/downloader/fossil_downloader_test.rs +++ b/crates/shirabe/tests/downloader/fossil_downloader_test.rs @@ -1,5 +1,35 @@ //! ref: composer/tests/Composer/Test/Downloader/FossilDownloaderTest.php +use shirabe::util::filesystem::Filesystem; +use tempfile::TempDir; + +fn set_up() -> TempDir { + TempDir::new().unwrap() +} + +fn tear_down(working_dir: &std::path::Path) { + if working_dir.is_dir() { + let mut fs = Filesystem::new(None); + fs.remove_directory(working_dir).unwrap(); + } +} + +struct TearDown { + working_dir: std::path::PathBuf, +} + +impl TearDown { + fn new(working_dir: std::path::PathBuf) -> Self { + TearDown { working_dir } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.working_dir); + } +} + // Every case constructs a FossilDownloader with a mocked IO/Config and a mocked // ProcessExecutor to feed fossil command output; a real HttpDownloader reaches // curl_multi_init (todo!()), and ProcessExecutor mocking is not available. @@ -7,35 +37,53 @@ #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_install_for_package_without_source_reference() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_install() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_updatefor_package_without_source_reference() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_update() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_remove() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_get_installation_source() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } diff --git a/crates/shirabe/tests/downloader/git_downloader_test.rs b/crates/shirabe/tests/downloader/git_downloader_test.rs index c332b5d..ad5e305 100644 --- a/crates/shirabe/tests/downloader/git_downloader_test.rs +++ b/crates/shirabe/tests/downloader/git_downloader_test.rs @@ -1,5 +1,46 @@ //! ref: composer/tests/Composer/Test/Downloader/GitDownloaderTest.php +use shirabe::util::filesystem::Filesystem; +use tempfile::TempDir; + +fn set_up() -> TempDir { + // skipIfNotExecutable('git') + let () = todo!(); + // initGitVersion('1.0.0') resets the Composer\Util\Git static version cache via + // reflection; the static cache is not reachable from a test here. + #[allow(unreachable_code)] + { + let _fs = Filesystem::new(None); + TempDir::new().unwrap() + } +} + +fn tear_down(working_dir: &std::path::Path) { + if working_dir.is_dir() { + let mut fs = Filesystem::new(None); + fs.remove_directory(working_dir).unwrap(); + } + // initGitVersion(false) resets the Composer\Util\Git static version cache via + // reflection; the static cache is not reachable from a test here. + todo!() +} + +struct TearDown { + working_dir: std::path::PathBuf, +} + +impl TearDown { + fn new(working_dir: std::path::PathBuf) -> Self { + TearDown { working_dir } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.working_dir); + } +} + // These construct a GitDownloader with a mocked IO/Config and a mocked ProcessExecutor to // feed git command output; mocking is not available, and a real HttpDownloader reaches // curl_multi_init (todo!()). @@ -8,6 +49,9 @@ macro_rules! stub { #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn $name() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } }; diff --git a/crates/shirabe/tests/downloader/hg_downloader_test.rs b/crates/shirabe/tests/downloader/hg_downloader_test.rs index 23c09f9..0bbcdf7 100644 --- a/crates/shirabe/tests/downloader/hg_downloader_test.rs +++ b/crates/shirabe/tests/downloader/hg_downloader_test.rs @@ -1,5 +1,35 @@ //! ref: composer/tests/Composer/Test/Downloader/HgDownloaderTest.php +use shirabe::util::filesystem::Filesystem; +use tempfile::TempDir; + +fn set_up() -> TempDir { + TempDir::new().unwrap() +} + +fn tear_down(working_dir: &std::path::Path) { + if working_dir.is_dir() { + let mut fs = Filesystem::new(None); + fs.remove_directory(working_dir).unwrap(); + } +} + +struct TearDown { + working_dir: std::path::PathBuf, +} + +impl TearDown { + fn new(working_dir: std::path::PathBuf) -> Self { + TearDown { working_dir } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.working_dir); + } +} + // Every case constructs an HgDownloader with a mocked IO/Config and a mocked // ProcessExecutor to feed hg command output; a real HttpDownloader reaches // curl_multi_init (todo!()), and ProcessExecutor mocking is not available. @@ -7,35 +37,53 @@ #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_download_for_package_without_source_reference() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_download() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_updatefor_package_without_source_reference() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_update() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_remove() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } #[test] #[ignore = "mocks ProcessExecutor/IO and needs an HttpDownloader (curl_multi_init todo!())"] fn test_get_installation_source() { + let working_dir = set_up(); + let _tear_down = TearDown::new(working_dir.path().to_path_buf()); + let _ = &working_dir; todo!() } diff --git a/crates/shirabe/tests/downloader/perforce_downloader_test.rs b/crates/shirabe/tests/downloader/perforce_downloader_test.rs index 41ced48..e0f7637 100644 --- a/crates/shirabe/tests/downloader/perforce_downloader_test.rs +++ b/crates/shirabe/tests/downloader/perforce_downloader_test.rs @@ -1,28 +1,44 @@ //! ref: composer/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +use tempfile::TempDir; + +fn set_up() -> TempDir { + let test_path = TempDir::new().unwrap(); + // repoConfig/config/io/processExecutor/repository/package/downloader rely on + // ProcessExecutorMock and PHPUnit mocks of the repository and Package, which are not + // ported. + let () = todo!(); + #[allow(unreachable_code)] + test_path +} + // These mock Perforce, the repository config and a Package to drive PerforceDownloader's // initialization and install paths; mocking is not available here. #[test] #[ignore = "mocks Perforce/repository/Package; mocking is not available"] fn test_init_perforce_instantiates_a_new_perforce_object() { + let _test_path = set_up(); todo!() } #[test] #[ignore = "mocks Perforce/repository/Package; mocking is not available"] fn test_init_perforce_does_nothing_if_perforce_already_set() { + let _test_path = set_up(); todo!() } #[test] #[ignore = "mocks Perforce/repository/Package; mocking is not available"] fn test_do_install_with_tag() { + let _test_path = set_up(); todo!() } #[test] #[ignore = "mocks Perforce/repository/Package; mocking is not available"] fn test_do_install_with_no_tag() { + let _test_path = set_up(); todo!() } diff --git a/crates/shirabe/tests/downloader/xz_downloader_test.rs b/crates/shirabe/tests/downloader/xz_downloader_test.rs index 9650991..d01779b 100644 --- a/crates/shirabe/tests/downloader/xz_downloader_test.rs +++ b/crates/shirabe/tests/downloader/xz_downloader_test.rs @@ -1,7 +1,50 @@ //! ref: composer/tests/Composer/Test/Downloader/XzDownloaderTest.php +use shirabe::util::Platform; +use shirabe::util::filesystem::Filesystem; +use tempfile::TempDir; + +fn set_up() -> TempDir { + if Platform::is_windows() { + // markTestSkipped('Skip test on Windows') + todo!() + } + if std::mem::size_of::<usize>() == 4 { + // markTestSkipped('Skip test on 32bit') + todo!() + } + TempDir::new().unwrap() +} + +fn tear_down(test_dir: &std::path::Path) { + if Platform::is_windows() { + return; + } + let mut fs = Filesystem::new(None); + fs.remove_directory(test_dir).unwrap(); +} + +struct TearDown { + test_dir: std::path::PathBuf, +} + +impl TearDown { + fn new(test_dir: std::path::PathBuf) -> Self { + TearDown { test_dir } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.test_dir); + } +} + #[test] #[ignore = "needs a real HttpDownloader/Loop and an XzDownloader download cycle; HttpDownloader construction reaches curl_multi_init (todo!()) in the php-shim"] fn test_error_messages() { + let test_dir = set_up(); + let _tear_down = TearDown::new(test_dir.path().to_path_buf()); + let _ = &test_dir; todo!() } diff --git a/crates/shirabe/tests/downloader/zip_downloader_test.rs b/crates/shirabe/tests/downloader/zip_downloader_test.rs index 0c8657c..aa4646c 100644 --- a/crates/shirabe/tests/downloader/zip_downloader_test.rs +++ b/crates/shirabe/tests/downloader/zip_downloader_test.rs @@ -1,5 +1,50 @@ //! ref: composer/tests/Composer/Test/Downloader/ZipDownloaderTest.php +use shirabe::util::filesystem::Filesystem; +use tempfile::TempDir; + +struct SetUp { + test_dir: TempDir, + filename: std::path::PathBuf, +} + +fn set_up() -> SetUp { + let test_dir = TempDir::new().unwrap(); + // The IO/Config/HttpDownloader/Package mocks are not ported; HttpDownloader construction + // additionally reaches curl_multi_init (todo!()). + let () = todo!(); + #[allow(unreachable_code)] + { + let filename = test_dir.path().join("composer-test.zip"); + std::fs::write(&filename, "zip").unwrap(); + SetUp { test_dir, filename } + } +} + +fn tear_down(test_dir: &std::path::Path) { + let mut fs = Filesystem::new(None); + fs.remove_directory(test_dir).unwrap(); + // setPrivateProperty('hasZipArchive', null) resets a ZipDownloader static via reflection; + // the static is not reachable from a test here. + todo!() +} + +struct TearDown { + test_dir: std::path::PathBuf, +} + +impl TearDown { + fn new(test_dir: std::path::PathBuf) -> Self { + TearDown { test_dir } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.test_dir); + } +} + // These construct a ZipDownloader with a mocked IO/HttpDownloader/ProcessExecutor and rely // on ZipArchive extraction (todo!() in the php-shim) plus mocked unzip behaviour. macro_rules! stub { @@ -7,6 +52,9 @@ macro_rules! stub { #[test] #[ignore = "mocks IO/HttpDownloader/ProcessExecutor and uses ZipArchive (todo!())"] fn $name() { + let set_up = set_up(); + let _tear_down = TearDown::new(set_up.test_dir.path().to_path_buf()); + let _ = (&set_up.test_dir, &set_up.filename); todo!() } }; diff --git a/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs b/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs index 86e33f2..3d9ee0a 100644 --- a/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs +++ b/crates/shirabe/tests/event_dispatcher/event_dispatcher_test.rs @@ -1,5 +1,19 @@ //! ref: composer/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php +use shirabe::util::platform::Platform; + +fn tear_down() { + Platform::clear_env("COMPOSER_SKIP_SCRIPTS"); +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + // These build an EventDispatcher with a mocked Composer/IO/ProcessExecutor and run script // listeners (executing CLI/PHP callbacks); mocking and the script-execution machinery are // not available here. @@ -8,6 +22,7 @@ macro_rules! stub { #[test] #[ignore = "mocks Composer/IO/ProcessExecutor and executes script listeners; not ported"] fn $name() { + let _tear_down = TearDown; todo!() } }; diff --git a/crates/shirabe/tests/factory_test.rs b/crates/shirabe/tests/factory_test.rs index b927d61..cfbbaee 100644 --- a/crates/shirabe/tests/factory_test.rs +++ b/crates/shirabe/tests/factory_test.rs @@ -3,21 +3,39 @@ use shirabe::factory::Factory; use shirabe::util::platform::Platform; +fn tear_down() { + Platform::clear_env("COMPOSER"); +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + #[test] #[ignore = "mocks an IOInterface with a writeError expectation and a Config returning disable-tls=true; mocking is not available"] fn test_default_values_are_as_expected() { + let _tear_down = TearDown; + todo!() } #[test] -#[ignore = "depends on COMPOSER being unset, but sibling tests set it and the tearDown that clears it is not ported"] +#[ignore = "depends on COMPOSER being unset, but sibling tests set it and race it on the process-global env under parallel execution"] fn test_get_composer_json_path() { + let _tear_down = TearDown; + assert_eq!("./composer.json", Factory::get_composer_file().unwrap()); } #[test] -#[ignore = "mutates the global COMPOSER env and races the from_env case in parallel; the tearDown that clears it is not ported"] +#[ignore = "mutates the global COMPOSER env and races the from_env case under parallel execution"] fn test_get_composer_json_path_fails_if_dir() { + let _tear_down = TearDown; + let dir = env!("CARGO_MANIFEST_DIR"); Platform::put_env("COMPOSER", dir); let err = Factory::get_composer_file().unwrap_err(); @@ -32,6 +50,8 @@ fn test_get_composer_json_path_fails_if_dir() { #[test] fn test_get_composer_json_path_from_env() { + let _tear_down = TearDown; + Platform::put_env("COMPOSER", " foo.json "); assert_eq!("foo.json", Factory::get_composer_file().unwrap()); } diff --git a/crates/shirabe/tests/installed_versions_test.rs b/crates/shirabe/tests/installed_versions_test.rs index 1357fd4..163e664 100644 --- a/crates/shirabe/tests/installed_versions_test.rs +++ b/crates/shirabe/tests/installed_versions_test.rs @@ -3,11 +3,25 @@ // setUpBeforeClass reflects into ClassLoader::registeredLoaders and the cases load // installed.php fixtures via InstalledVersions::reload; the reflection and fixture loading // are not ported. + +use tempfile::TempDir; + +fn set_up() -> TempDir { + let root = TempDir::new().unwrap(); + + // Loading the installed_relative.php fixture and InstalledVersions::reload are not ported. + todo!(); + + #[allow(unreachable_code)] + root +} + macro_rules! stub { ($name:ident) => { #[test] #[ignore = "needs reflection into ClassLoader::registeredLoaders and installed.php fixtures (not ported)"] fn $name() { + let _root = set_up(); todo!() } }; diff --git a/crates/shirabe/tests/installer/binary_installer_test.rs b/crates/shirabe/tests/installer/binary_installer_test.rs index 81df0ea..0a22243 100644 --- a/crates/shirabe/tests/installer/binary_installer_test.rs +++ b/crates/shirabe/tests/installer/binary_installer_test.rs @@ -1,5 +1,25 @@ //! ref: composer/tests/Composer/Test/Installer/BinaryInstallerTest.php +/// Creates the root/vendor/bin temp directories and a mocked IO. The temp-dir +/// helpers (`getUniqueTmpDirectory`/`ensureDirectoryExistsAndClear`) and the IO +/// mock are not available here, so this remains a stub. +fn set_up() { + todo!() +} + +/// Removes the root dir created by `set_up`, which is itself a stub. +fn tear_down() { + todo!() +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + // This installs a PHP binary and then executes it via ProcessExecutor, asserting the // program's output. It needs a real PHP runtime, the binary-proxy generation, and a // mocked Package's getBinaries(), none of which are available here. diff --git a/crates/shirabe/tests/installer/installation_manager_test.rs b/crates/shirabe/tests/installer/installation_manager_test.rs index 0ec4651..58d0834 100644 --- a/crates/shirabe/tests/installer/installation_manager_test.rs +++ b/crates/shirabe/tests/installer/installation_manager_test.rs @@ -1,5 +1,11 @@ //! ref: composer/tests/Composer/Test/Installer/InstallationManagerTest.php +/// Builds mocked Loop/repository/IO. The mocks are not available here, so this +/// remains a stub. +fn set_up() { + todo!() +} + // These mock individual installers, the repository and IO to drive InstallationManager's // add/execute/install/update/uninstall logic; mocking is not available here. macro_rules! stub { diff --git a/crates/shirabe/tests/installer/library_installer_test.rs b/crates/shirabe/tests/installer/library_installer_test.rs index 4f2e33e..1262970 100644 --- a/crates/shirabe/tests/installer/library_installer_test.rs +++ b/crates/shirabe/tests/installer/library_installer_test.rs @@ -1,5 +1,25 @@ //! ref: composer/tests/Composer/Test/Installer/LibraryInstallerTest.php +/// Sets up a Composer/Config over root/vendor/bin temp dirs plus mocked +/// DownloadManager/repository/IO. The temp-dir helpers and the mocks are not +/// available here, so this remains a stub. +fn set_up() { + todo!() +} + +/// Removes the root dir created by `set_up`, which is itself a stub. +fn tear_down() { + todo!() +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + // These construct a LibraryInstaller over a temp dir with a mocked IO/Filesystem/repository // and mocked packages to drive install/update/uninstall and path resolution. macro_rules! stub { diff --git a/crates/shirabe/tests/installer/metapackage_installer_test.rs b/crates/shirabe/tests/installer/metapackage_installer_test.rs index daf2e20..60aac92 100644 --- a/crates/shirabe/tests/installer/metapackage_installer_test.rs +++ b/crates/shirabe/tests/installer/metapackage_installer_test.rs @@ -13,6 +13,13 @@ use shirabe::repository::{InstalledArrayRepository, RepositoryInterface}; use crate::test_case::get_package; +/// Builds mocked repository/IO and a MetapackageInstaller over them. The mocks +/// are not available here; the live tests below intentionally diverge to use a +/// real InstalledArrayRepository instead, so this stub is not injected. +fn set_up() { + todo!() +} + fn run<F: std::future::Future>(future: F) -> F::Output { tokio::runtime::Builder::new_current_thread() .build() diff --git a/crates/shirabe/tests/installer/suggested_packages_reporter_test.rs b/crates/shirabe/tests/installer/suggested_packages_reporter_test.rs index f32b10c..e47a73a 100644 --- a/crates/shirabe/tests/installer/suggested_packages_reporter_test.rs +++ b/crates/shirabe/tests/installer/suggested_packages_reporter_test.rs @@ -1,5 +1,11 @@ //! ref: composer/tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php +/// Builds an IO mock and a SuggestedPackagesReporter over it. The IO mock +/// (`getIOMock`) is not available here, so this remains a stub. +fn set_up() { + todo!() +} + // These construct a SuggestedPackagesReporter with a mocked IO and assert its accumulated // suggestions and formatted output; mocking is not available here. macro_rules! stub { diff --git a/crates/shirabe/tests/installer_test.rs b/crates/shirabe/tests/installer_test.rs index c7d3a91..5e0f941 100644 --- a/crates/shirabe/tests/installer_test.rs +++ b/crates/shirabe/tests/installer_test.rs @@ -3,11 +3,30 @@ // These are large end-to-end installer integration cases driven by fixtures and a mocked // Composer/IO/repositories; the full install pipeline (and constraint parsing through a // look-around regex) is not ported. + +use shirabe::util::platform::Platform; + +// The chdir back to prevCwd (cwd management) and removeDirectory of tempComposerHome (a +// path produced by the unported install pipeline) are not ported; only the env clears are. +fn tear_down() { + Platform::clear_env("COMPOSER_POOL_OPTIMIZER"); + Platform::clear_env("COMPOSER_FUND"); +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + macro_rules! stub { ($name:ident) => { #[test] #[ignore = "not yet ported (end-to-end Installer integration over fixtures; constraint parsing uses a look-around regex)"] fn $name() { + let _tear_down = TearDown; todo!() } }; diff --git a/crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs b/crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs index 381c032..dcca80a 100644 --- a/crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs +++ b/crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs @@ -1,5 +1,29 @@ //! ref: composer/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php +/// Builds a temp directory tree of fixture files under a unique tmp dir; the Filesystem and +/// getUniqueTmpDirectory infrastructure is not ported. +#[allow(dead_code)] +fn set_up() -> String { + todo!() +} + +#[allow(dead_code)] +fn tear_down(_sources: &str) { + // Removes the temp directory tree created in set_up. + todo!() +} + +#[allow(dead_code)] +struct TearDown { + sources: String, +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.sources); + } +} + // These set up a temp directory tree (including a git repo) and assert the files the finder // selects with manual/git/skip excludes; the git-backed fixture setup is not ported. macro_rules! stub { diff --git a/crates/shirabe/tests/package/archiver/archive_manager_test.rs b/crates/shirabe/tests/package/archiver/archive_manager_test.rs index 5f9e413..912512d 100644 --- a/crates/shirabe/tests/package/archiver/archive_manager_test.rs +++ b/crates/shirabe/tests/package/archiver/archive_manager_test.rs @@ -1,5 +1,30 @@ //! ref: composer/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php +/// Builds an ArchiveManager via Factory/DownloadManager/Loop and derives targetDir under a +/// unique tmp dir (testDir); none of that factory/fixture infrastructure is ported. +/// Returns (test_dir, target_dir). +#[allow(dead_code)] +fn set_up() -> (String, String) { + todo!() +} + +#[allow(dead_code)] +fn tear_down(_test_dir: &str) { + // Removes testDir created in set_up. + todo!() +} + +#[allow(dead_code)] +struct TearDown { + test_dir: String, +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.test_dir); + } +} + // These drive ArchiveManager end-to-end (building tar archives via PharData, todo!()) and // the filename-derivation helpers over packages; the archiving and fixture setup are not // ported. diff --git a/crates/shirabe/tests/package/archiver/zip_archiver_test.rs b/crates/shirabe/tests/package/archiver/zip_archiver_test.rs index 1c884d8..5f41c78 100644 --- a/crates/shirabe/tests/package/archiver/zip_archiver_test.rs +++ b/crates/shirabe/tests/package/archiver/zip_archiver_test.rs @@ -1,5 +1,30 @@ //! ref: composer/tests/Composer/Test/Package/Archiver/ZipArchiverTest.php +/// Creates the Filesystem/ProcessExecutor and a unique tmp testDir; that infrastructure is +/// not ported. Returns testDir. +#[allow(dead_code)] +fn set_up() -> String { + todo!() +} + +/// Unlinks the zip files collected in filesToCleanup, then (parent) removes testDir. +#[allow(dead_code)] +fn tear_down(_files_to_cleanup: &[String], _test_dir: &str) { + todo!() +} + +#[allow(dead_code)] +struct TearDown { + files_to_cleanup: Vec<String>, + test_dir: String, +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.files_to_cleanup, &self.test_dir); + } +} + // ZipArchiver::archive builds a zip via ZipArchive, which is todo!() in the php-shim. #[test] diff --git a/crates/shirabe/tests/package/dumper/array_dumper_test.rs b/crates/shirabe/tests/package/dumper/array_dumper_test.rs index c89f5ed..6ed12fe 100644 --- a/crates/shirabe/tests/package/dumper/array_dumper_test.rs +++ b/crates/shirabe/tests/package/dumper/array_dumper_test.rs @@ -6,6 +6,10 @@ use shirabe::package::handle::{CompletePackageHandle, RootPackageHandle}; use shirabe_php_shim::PhpMixed; use shirabe_semver::version_parser::VersionParser; +fn set_up() -> ArrayDumper { + ArrayDumper::new() +} + fn complete_package() -> CompletePackageHandle { let norm = VersionParser.normalize("1.0.0", None).unwrap(); CompletePackageHandle::new("dummy/pkg".to_string(), norm, "1.0.0".to_string()) @@ -18,7 +22,8 @@ fn root_package() -> RootPackageHandle { #[test] fn test_required_information() { - let config = ArrayDumper::new().dump(complete_package().into()); + let dumper = set_up(); + let config = dumper.dump(complete_package().into()); let mut expected: IndexMap<String, PhpMixed> = IndexMap::new(); expected.insert( @@ -37,10 +42,11 @@ fn test_required_information() { #[test] fn test_root_package() { + let dumper = set_up(); let package = root_package(); package.set_minimum_stability("dev".to_string()); - let config = ArrayDumper::new().dump(package.into()); + let config = dumper.dump(package.into()); assert_eq!( Some(&PhpMixed::String("dev".to_string())), @@ -50,20 +56,22 @@ fn test_root_package() { #[test] fn test_dump_abandoned() { + let dumper = set_up(); let package = complete_package(); package.set_abandoned(PhpMixed::Bool(true)); - let config = ArrayDumper::new().dump(package.into()); + let config = dumper.dump(package.into()); assert_eq!(Some(&PhpMixed::Bool(true)), config.get("abandoned")); } #[test] fn test_dump_abandoned_replacement() { + let dumper = set_up(); let package = complete_package(); package.set_abandoned(PhpMixed::String("foo/bar".to_string())); - let config = ArrayDumper::new().dump(package.into()); + let config = dumper.dump(package.into()); assert_eq!( Some(&PhpMixed::String("foo/bar".to_string())), diff --git a/crates/shirabe/tests/package/loader/array_loader_test.rs b/crates/shirabe/tests/package/loader/array_loader_test.rs index fce85a7..79b5d78 100644 --- a/crates/shirabe/tests/package/loader/array_loader_test.rs +++ b/crates/shirabe/tests/package/loader/array_loader_test.rs @@ -1,5 +1,11 @@ //! ref: composer/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php +use shirabe::package::loader::ArrayLoader; + +fn set_up() -> ArrayLoader { + ArrayLoader::new(None, false) +} + // ArrayLoader::load parses version/link constraints through a look-around regex the regex // crate cannot compile. macro_rules! stub { @@ -7,6 +13,7 @@ macro_rules! stub { #[test] #[ignore = "ArrayLoader::load parses constraints via a look-around regex the regex crate cannot compile"] fn $name() { + let _loader = set_up(); todo!() } }; diff --git a/crates/shirabe/tests/package/version/version_guesser_test.rs b/crates/shirabe/tests/package/version/version_guesser_test.rs index ef4b232..9b974dd 100644 --- a/crates/shirabe/tests/package/version/version_guesser_test.rs +++ b/crates/shirabe/tests/package/version/version_guesser_test.rs @@ -1,5 +1,26 @@ //! ref: composer/tests/Composer/Test/Package/Version/VersionGuesserTest.php +#[allow(dead_code)] +fn set_up() { + // Resets GitUtil's cached `version` static via ReflectionProperty; the static is not + // exposed here and reflection-based mutation has no ported equivalent. + todo!() +} + +#[allow(dead_code)] +fn tear_down() { + todo!() +} + +#[allow(dead_code)] +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + // These drive VersionGuesser with a mocked ProcessExecutor feeding git/hg command output; // mocking is not available here. macro_rules! stub { diff --git a/crates/shirabe/tests/platform/hhvm_detector_test.rs b/crates/shirabe/tests/platform/hhvm_detector_test.rs index 8c420e5..1b35450 100644 --- a/crates/shirabe/tests/platform/hhvm_detector_test.rs +++ b/crates/shirabe/tests/platform/hhvm_detector_test.rs @@ -1,13 +1,23 @@ //! ref: composer/tests/Composer/Test/Platform/HhvmDetectorTest.php +use shirabe::platform::hhvm_detector::HhvmDetector; + +fn set_up() -> HhvmDetector { + let hhvm_detector = HhvmDetector::new(None, None); + hhvm_detector.reset(); + hhvm_detector +} + #[test] #[ignore = "skipped unless running under HHVM (HHVM_VERSION_ID defined), which never holds here"] fn test_hhvm_version_when_executing_in_hhvm() { + let _hhvm_detector = set_up(); todo!() } #[test] #[ignore = "needs an installed hhvm executable plus ExecutableFinder/ProcessExecutor; skipped in PHP when hhvm is absent"] fn test_hhvm_version_when_executing_in_php() { + let _hhvm_detector = set_up(); todo!() } diff --git a/crates/shirabe/tests/plugin/plugin_installer_test.rs b/crates/shirabe/tests/plugin/plugin_installer_test.rs index 4fed7c6..1243a49 100644 --- a/crates/shirabe/tests/plugin/plugin_installer_test.rs +++ b/crates/shirabe/tests/plugin/plugin_installer_test.rs @@ -1,5 +1,26 @@ //! ref: composer/tests/Composer/Test/Plugin/PluginInstallerTest.php +/// Builds the Composer instance from mocked DownloadManager/RepositoryManager/ +/// InstallationManager/EventDispatcher and an InstalledRepository mock, plus the +/// plugin fixtures temp directory. The mocks and the plugin machinery are not +/// available here, so this remains a stub. +fn set_up() { + todo!() +} + +/// Removes the fixtures directory created by `set_up`, which is itself a stub. +fn tear_down() { + todo!() +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + // The plugin system requires the PHP runtime to load and instantiate plugin classes; the // PluginManager/PluginInstaller is intentionally not implemented yet (TODO(plugin)). macro_rules! stub { diff --git a/crates/shirabe/tests/repository/artifact_repository_test.rs b/crates/shirabe/tests/repository/artifact_repository_test.rs index 58cb888..5e70650 100644 --- a/crates/shirabe/tests/repository/artifact_repository_test.rs +++ b/crates/shirabe/tests/repository/artifact_repository_test.rs @@ -3,20 +3,32 @@ // ArtifactRepository::getPackages scans the fixture directory and opens each archive via // ZipArchive / PharData, both of which are todo!() in the php-shim. +use shirabe_php_shim::extension_loaded; + +fn set_up() { + if !extension_loaded("zip") { + // markTestSkipped('You need the zip extension to run this test.') + todo!() + } +} + #[test] #[ignore = "ArtifactRepository reads archives via ZipArchive/PharData, which are todo!() in the php-shim"] fn test_extracts_configs_from_zip_archives() { + set_up(); todo!() } #[test] #[ignore = "ArtifactRepository reads archives via ZipArchive/PharData, which are todo!() in the php-shim"] fn test_absolute_repo_url_creates_absolute_url_packages() { + set_up(); todo!() } #[test] #[ignore = "ArtifactRepository reads archives via ZipArchive/PharData, which are todo!() in the php-shim"] fn test_relative_repo_url_creates_relative_url_packages() { + set_up(); todo!() } diff --git a/crates/shirabe/tests/repository/filter_repository_test.rs b/crates/shirabe/tests/repository/filter_repository_test.rs index 1074fb4..a244f52 100644 --- a/crates/shirabe/tests/repository/filter_repository_test.rs +++ b/crates/shirabe/tests/repository/filter_repository_test.rs @@ -10,8 +10,7 @@ use shirabe_semver::constraint::{AnyConstraint, MatchAllConstraint}; use crate::test_case::get_package; -/// ref: FilterRepositoryTest::setUp -fn array_repo() -> RepositoryInterfaceHandle { +fn set_up() -> RepositoryInterfaceHandle { let repo = ArrayRepository::new(vec![ get_package("foo/aaa", "1.0.0"), get_package("foo/bbb", "1.0.0"), @@ -86,7 +85,7 @@ fn test_repo_matching() { ]; for (expected, cfg) in cases { - let mut repo = FilterRepository::new(array_repo(), cfg).unwrap(); + let mut repo = FilterRepository::new(set_up(), cfg).unwrap(); let packages = repo.get_packages().unwrap(); let names: Vec<String> = packages.iter().map(|p| p.get_name()).collect(); @@ -97,12 +96,12 @@ fn test_repo_matching() { #[test] fn test_both_filters_disallowed() { - assert!(FilterRepository::new(array_repo(), config(Some(&[]), Some(&[]))).is_err()); + assert!(FilterRepository::new(set_up(), config(Some(&[]), Some(&[]))).is_err()); } #[test] fn test_security_advisories_disabled_in_child() { - let mut repo = FilterRepository::new(array_repo(), config(Some(&["foo/*"]), None)).unwrap(); + let mut repo = FilterRepository::new(set_up(), config(Some(&["foo/*"]), None)).unwrap(); assert!(!repo.has_security_advisories().unwrap()); @@ -116,7 +115,7 @@ fn test_security_advisories_disabled_in_child() { #[test] fn test_canonical_default_true() { - let mut repo = FilterRepository::new(array_repo(), config(None, None)).unwrap(); + let mut repo = FilterRepository::new(set_up(), config(None, None)).unwrap(); let mut map: IndexMap<String, Option<AnyConstraint>> = IndexMap::new(); map.insert("foo/aaa".to_string(), Some(match_all())); @@ -133,7 +132,7 @@ fn test_non_canonical() { use shirabe_php_shim::PhpMixed; let mut cfg: IndexMap<String, PhpMixed> = IndexMap::new(); cfg.insert("canonical".to_string(), PhpMixed::Bool(false)); - let mut repo = FilterRepository::new(array_repo(), cfg).unwrap(); + let mut repo = FilterRepository::new(set_up(), cfg).unwrap(); let mut map: IndexMap<String, Option<AnyConstraint>> = IndexMap::new(); map.insert("foo/aaa".to_string(), Some(match_all())); diff --git a/crates/shirabe/tests/repository/repository_manager_test.rs b/crates/shirabe/tests/repository/repository_manager_test.rs index 60deb7e..dec018a 100644 --- a/crates/shirabe/tests/repository/repository_manager_test.rs +++ b/crates/shirabe/tests/repository/repository_manager_test.rs @@ -4,26 +4,69 @@ // curl_multi_init, todo!()) with a mocked IO/Config/EventDispatcher and exercise repo // creation/prepending/wrapping. +use shirabe::util::filesystem::Filesystem; +use tempfile::TempDir; + +struct SetUp { + tmpdir: TempDir, +} + +fn set_up() -> SetUp { + let tmpdir = TempDir::new().unwrap(); + SetUp { tmpdir } +} + +fn tear_down(tmpdir: &std::path::Path) { + if tmpdir.is_dir() { + let mut fs = Filesystem::new(None); + fs.remove_directory(tmpdir).unwrap(); + } +} + +struct TearDown { + tmpdir: std::path::PathBuf, +} + +impl TearDown { + fn new(tmpdir: std::path::PathBuf) -> Self { + TearDown { tmpdir } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.tmpdir); + } +} + #[test] #[ignore = "RepositoryManager::new builds an HttpDownloader (curl_multi_init todo!()) and mocks IO/Config"] fn test_prepend() { + let SetUp { tmpdir } = set_up(); + let _tear_down = TearDown::new(tmpdir.path().to_path_buf()); todo!() } #[test] #[ignore = "RepositoryManager::new builds an HttpDownloader (curl_multi_init todo!()) and mocks IO/Config"] fn test_repo_creation() { + let SetUp { tmpdir } = set_up(); + let _tear_down = TearDown::new(tmpdir.path().to_path_buf()); todo!() } #[test] #[ignore = "RepositoryManager::new builds an HttpDownloader (curl_multi_init todo!()) and mocks IO/Config"] fn test_invalid_repo_creation_throws() { + let SetUp { tmpdir } = set_up(); + let _tear_down = TearDown::new(tmpdir.path().to_path_buf()); todo!() } #[test] #[ignore = "RepositoryManager::new builds an HttpDownloader (curl_multi_init todo!()) and mocks IO/Config"] fn test_filter_repo_wrapping() { + let SetUp { tmpdir } = set_up(); + let _tear_down = TearDown::new(tmpdir.path().to_path_buf()); todo!() } diff --git a/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs b/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs index f488182..a67bce3 100644 --- a/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs @@ -3,10 +3,70 @@ use std::cell::RefCell; use std::rc::Rc; +use indexmap::IndexMap; use shirabe::config::Config; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; use shirabe::repository::vcs::ForgejoDriver; +use shirabe::util::filesystem::Filesystem; +use shirabe_php_shim::PhpMixed; +use tempfile::TempDir; + +struct SetUp { + home: TempDir, + config: Config, + // The IOInterface and HttpDownloader mocks are not ported. + io: (), + http_downloader: (), +} + +fn set_up() -> SetUp { + let home = TempDir::new().unwrap(); + let mut config = Config::new(true, None); + let mut top: IndexMap<String, PhpMixed> = IndexMap::new(); + let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new(); + config_section.insert( + "home".to_string(), + PhpMixed::String(home.path().to_string_lossy().into_owned()), + ); + config_section.insert( + "forgejo-domains".to_string(), + PhpMixed::List(vec![PhpMixed::String("codeberg.org".to_string())]), + ); + top.insert("config".to_string(), PhpMixed::Array(config_section)); + config.merge(&top, Config::SOURCE_UNKNOWN); + + let io = (); + let http_downloader = (); + + SetUp { + home, + config, + io, + http_downloader, + } +} + +fn tear_down(home: &std::path::Path) { + let mut fs = Filesystem::new(None); + fs.remove_directory(home).unwrap(); +} + +struct TearDown { + home: std::path::PathBuf, +} + +impl TearDown { + fn new(home: std::path::PathBuf) -> Self { + TearDown { home } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.home); + } +} fn supports_provider() -> Vec<(bool, &'static str)> { vec![ @@ -35,23 +95,55 @@ fn test_supports() { #[test] #[ignore = "constructs a ForgejoDriver and mocks the HttpDownloader (curl_multi_init todo!())"] fn test_public_repository() { + let SetUp { + home, + config, + io, + http_downloader, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); + let _ = (&config, &io, &http_downloader); todo!() } #[test] #[ignore = "constructs a ForgejoDriver and mocks the HttpDownloader (curl_multi_init todo!())"] fn test_get_branches() { + let SetUp { + home, + config, + io, + http_downloader, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); + let _ = (&config, &io, &http_downloader); todo!() } #[test] #[ignore = "constructs a ForgejoDriver and mocks the HttpDownloader (curl_multi_init todo!())"] fn test_get_tags() { + let SetUp { + home, + config, + io, + http_downloader, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); + let _ = (&config, &io, &http_downloader); todo!() } #[test] #[ignore = "constructs a ForgejoDriver and mocks the HttpDownloader (curl_multi_init todo!())"] fn test_get_empty_file_content() { + let SetUp { + home, + config, + io, + http_downloader, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); + let _ = (&config, &io, &http_downloader); todo!() } diff --git a/crates/shirabe/tests/repository/vcs/fossil_driver_test.rs b/crates/shirabe/tests/repository/vcs/fossil_driver_test.rs index e677b3d..a3986c2 100644 --- a/crates/shirabe/tests/repository/vcs/fossil_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/fossil_driver_test.rs @@ -3,10 +3,55 @@ use std::cell::RefCell; use std::rc::Rc; +use indexmap::IndexMap; use shirabe::config::Config; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; use shirabe::repository::vcs::FossilDriver; +use shirabe::util::filesystem::Filesystem; +use shirabe_php_shim::PhpMixed; +use tempfile::TempDir; + +struct SetUp { + home: TempDir, + config: Config, +} + +fn set_up() -> SetUp { + let home = TempDir::new().unwrap(); + let mut config = Config::new(true, None); + let mut top: IndexMap<String, PhpMixed> = IndexMap::new(); + let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new(); + config_section.insert( + "home".to_string(), + PhpMixed::String(home.path().to_string_lossy().into_owned()), + ); + top.insert("config".to_string(), PhpMixed::Array(config_section)); + config.merge(&top, Config::SOURCE_UNKNOWN); + + SetUp { home, config } +} + +fn tear_down(home: &std::path::Path) { + let mut fs = Filesystem::new(None); + fs.remove_directory(home).unwrap(); +} + +struct TearDown { + home: std::path::PathBuf, +} + +impl TearDown { + fn new(home: std::path::PathBuf) -> Self { + TearDown { home } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.home); + } +} fn support_provider() -> Vec<(&'static str, bool)> { vec![ diff --git a/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs b/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs index e48c609..b6759b5 100644 --- a/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs @@ -3,10 +3,69 @@ use std::cell::RefCell; use std::rc::Rc; +use indexmap::IndexMap; use shirabe::config::Config; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; use shirabe::repository::vcs::GitBitbucketDriver; +use shirabe::util::filesystem::Filesystem; +use shirabe_php_shim::PhpMixed; +use tempfile::TempDir; + +struct SetUp { + home: TempDir, + config: Config, + // The IOInterface mock and the HttpDownloaderMock are not ported. + io: (), + http_downloader: (), +} + +fn set_up() -> SetUp { + // The IOInterface mock is created via PHPUnit's getMockBuilder, which is not ported. + let io: () = todo!(); + + let home = TempDir::new().unwrap(); + let mut config = Config::new(true, None); + let mut top: IndexMap<String, PhpMixed> = IndexMap::new(); + let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new(); + config_section.insert( + "home".to_string(), + PhpMixed::String(home.path().to_string_lossy().into_owned()), + ); + top.insert("config".to_string(), PhpMixed::Array(config_section)); + config.merge(&top, Config::SOURCE_UNKNOWN); + + // The HttpDownloaderMock is created via getHttpDownloaderMock, which is not ported. + let http_downloader: () = todo!(); + + SetUp { + home, + config, + io, + http_downloader, + } +} + +fn tear_down(home: &std::path::Path) { + let mut fs = Filesystem::new(None); + fs.remove_directory(home).unwrap(); +} + +struct TearDown { + home: std::path::PathBuf, +} + +impl TearDown { + fn new(home: std::path::PathBuf) -> Self { + TearDown { home } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.home); + } +} #[test] fn test_supports() { @@ -46,29 +105,64 @@ fn test_supports() { #[test] #[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"] fn test_get_root_identifier_wrong_scm_type() { + let SetUp { + home, + config: _, + io: _, + http_downloader: _, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"] fn test_driver() { + let SetUp { + home, + config: _, + io: _, + http_downloader: _, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"] fn test_get_params() { + let SetUp { + home, + config: _, + io: _, + http_downloader: _, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"] fn test_initialize_invalid_repository_url() { + let SetUp { + home, + config: _, + io: _, + http_downloader: _, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"] fn test_invalid_support_data() { + let SetUp { + home, + config: _, + io: _, + http_downloader: _, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } diff --git a/crates/shirabe/tests/repository/vcs/git_driver_test.rs b/crates/shirabe/tests/repository/vcs/git_driver_test.rs index 85c9f0b..c36470c 100644 --- a/crates/shirabe/tests/repository/vcs/git_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/git_driver_test.rs @@ -4,11 +4,76 @@ // that reaches curl_multi_init, todo!()) to feed git command output; mocking is not // available here. +use indexmap::IndexMap; +use shirabe::config::Config; +use shirabe::util::filesystem::Filesystem; +use shirabe::util::platform::Platform; +use shirabe_php_shim::PhpMixed; +use tempfile::TempDir; + +struct SetUp { + home: TempDir, + config: Config, + network_env: Option<String>, +} + +fn set_up() -> SetUp { + let home = TempDir::new().unwrap(); + let mut config = Config::new(true, None); + let mut top: IndexMap<String, PhpMixed> = IndexMap::new(); + let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new(); + config_section.insert( + "home".to_string(), + PhpMixed::String(home.path().to_string_lossy().into_owned()), + ); + top.insert("config".to_string(), PhpMixed::Array(config_section)); + config.merge(&top, Config::SOURCE_UNKNOWN); + let network_env = Platform::get_env("COMPOSER_DISABLE_NETWORK"); + + SetUp { + home, + config, + network_env, + } +} + +fn tear_down(home: &std::path::Path, network_env: &Option<String>) { + let mut fs = Filesystem::new(None); + fs.remove_directory(home).unwrap(); + match network_env { + None => Platform::clear_env("COMPOSER_DISABLE_NETWORK"), + Some(network_env) => Platform::put_env("COMPOSER_DISABLE_NETWORK", network_env), + } +} + +struct TearDown { + home: std::path::PathBuf, + network_env: Option<String>, +} + +impl TearDown { + fn new(home: std::path::PathBuf, network_env: Option<String>) -> Self { + TearDown { home, network_env } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.home, &self.network_env); + } +} + macro_rules! git_stub { ($name:ident) => { #[test] #[ignore = "constructs a GitDriver and mocks a ProcessExecutor/HttpDownloader (curl_multi_init todo!())"] fn $name() { + let SetUp { + home, + config: _, + network_env, + } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf(), network_env); todo!() } }; diff --git a/crates/shirabe/tests/repository/vcs/github_driver_test.rs b/crates/shirabe/tests/repository/vcs/github_driver_test.rs index d0067d5..3e97599 100644 --- a/crates/shirabe/tests/repository/vcs/github_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/github_driver_test.rs @@ -3,10 +3,55 @@ use std::cell::RefCell; use std::rc::Rc; +use indexmap::IndexMap; use shirabe::config::Config; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; use shirabe::repository::vcs::GitHubDriver; +use shirabe::util::filesystem::Filesystem; +use shirabe_php_shim::PhpMixed; +use tempfile::TempDir; + +struct SetUp { + home: TempDir, + config: Config, +} + +fn set_up() -> SetUp { + let home = TempDir::new().unwrap(); + let mut config = Config::new(true, None); + let mut top: IndexMap<String, PhpMixed> = IndexMap::new(); + let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new(); + config_section.insert( + "home".to_string(), + PhpMixed::String(home.path().to_string_lossy().into_owned()), + ); + top.insert("config".to_string(), PhpMixed::Array(config_section)); + config.merge(&top, Config::SOURCE_UNKNOWN); + + SetUp { home, config } +} + +fn tear_down(home: &std::path::Path) { + let mut fs = Filesystem::new(None); + fs.remove_directory(home).unwrap(); +} + +struct TearDown { + home: std::path::PathBuf, +} + +impl TearDown { + fn new(home: std::path::PathBuf) -> Self { + TearDown { home } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.home); + } +} fn supports_provider() -> Vec<(bool, &'static str)> { vec![ @@ -21,6 +66,9 @@ fn supports_provider() -> Vec<(bool, &'static str)> { #[test] #[ignore = "GitHubDriver::supports reaches non-strict in_array, which is todo!() in the php-shim"] fn test_supports() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); + for (expected, repo_url) in supports_provider() { let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new())); let config = Rc::new(RefCell::new(Config::new(true, None))); @@ -38,53 +86,71 @@ fn test_supports() { #[test] #[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"] fn test_private_repository() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"] fn test_public_repository() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"] fn test_public_repository2() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"] fn test_invalid_support_data() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"] fn test_funding_format() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"] fn test_public_repository_archived() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"] fn test_private_repository_no_interaction() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"] fn test_initialize_invalid_repo_url() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } #[test] #[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"] fn test_get_empty_file_content() { + let SetUp { home, config: _ } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); todo!() } diff --git a/crates/shirabe/tests/repository/vcs/hg_driver_test.rs b/crates/shirabe/tests/repository/vcs/hg_driver_test.rs index d7ff5c3..155d7ce 100644 --- a/crates/shirabe/tests/repository/vcs/hg_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/hg_driver_test.rs @@ -3,10 +3,58 @@ use std::cell::RefCell; use std::rc::Rc; +use indexmap::IndexMap; use shirabe::config::Config; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; use shirabe::repository::vcs::HgDriver; +use shirabe::util::filesystem::Filesystem; +use shirabe_php_shim::PhpMixed; +use tempfile::TempDir; + +struct SetUp { + home: TempDir, + config: Config, + // The IOInterface mock is not ported. + io: (), +} + +fn set_up() -> SetUp { + let io = (); + let home = TempDir::new().unwrap(); + let mut config = Config::new(true, None); + let mut top: IndexMap<String, PhpMixed> = IndexMap::new(); + let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new(); + config_section.insert( + "home".to_string(), + PhpMixed::String(home.path().to_string_lossy().into_owned()), + ); + top.insert("config".to_string(), PhpMixed::Array(config_section)); + config.merge(&top, Config::SOURCE_UNKNOWN); + + SetUp { home, config, io } +} + +fn tear_down(home: &std::path::Path) { + let mut fs = Filesystem::new(None); + fs.remove_directory(home).unwrap(); +} + +struct TearDown { + home: std::path::PathBuf, +} + +impl TearDown { + fn new(home: std::path::PathBuf) -> Self { + TearDown { home } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.home); + } +} fn supports_data_provider() -> Vec<&'static str> { vec![ @@ -34,17 +82,26 @@ fn test_supports() { #[test] #[ignore = "needs an HgDriver instance (HttpDownloader reaches curl_multi_init, todo!()) and a mocked ProcessExecutor"] fn test_get_branches_filter_invalid_branch_names() { + let SetUp { home, config, io } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); + let _ = (&config, &io); todo!() } #[test] #[ignore = "needs an HgDriver instance (HttpDownloader reaches curl_multi_init, todo!()) and a mocked ProcessExecutor"] fn test_file_get_content_invalid_identifier() { + let SetUp { home, config, io } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); + let _ = (&config, &io); todo!() } #[test] #[ignore = "needs an HgDriver instance (HttpDownloader reaches curl_multi_init, todo!()) and a mocked ProcessExecutor"] fn test_get_change_date_invalid_identifier() { + let SetUp { home, config, io } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); + let _ = (&config, &io); todo!() } diff --git a/crates/shirabe/tests/repository/vcs/perforce_driver_test.rs b/crates/shirabe/tests/repository/vcs/perforce_driver_test.rs index c8353de..1c28487 100644 --- a/crates/shirabe/tests/repository/vcs/perforce_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/perforce_driver_test.rs @@ -3,10 +3,100 @@ use std::cell::RefCell; use std::rc::Rc; +use indexmap::IndexMap; use shirabe::config::Config; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; use shirabe::repository::vcs::PerforceDriver; +use shirabe::util::filesystem::Filesystem; +use shirabe_php_shim::PhpMixed; +use tempfile::TempDir; + +const TEST_URL: &str = "TEST_PERFORCE_URL"; +const TEST_DEPOT: &str = "TEST_DEPOT_CONFIG"; +const TEST_BRANCH: &str = "TEST_BRANCH_CONFIG"; + +struct SetUp { + test_path: TempDir, + config: Config, + repo_config: IndexMap<String, PhpMixed>, + // The IOInterface, ProcessExecutor, HttpDownloader and Perforce mocks, the + // driver instance and the reflection-based perforce override are not ported. + io: (), + process: (), + http_downloader: (), + perforce: (), + driver: (), +} + +fn get_test_config(test_path: &std::path::Path) -> Config { + let mut config = Config::new(true, None); + let mut top: IndexMap<String, PhpMixed> = IndexMap::new(); + let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new(); + config_section.insert( + "home".to_string(), + PhpMixed::String(test_path.to_string_lossy().into_owned()), + ); + top.insert("config".to_string(), PhpMixed::Array(config_section)); + config.merge(&top, Config::SOURCE_UNKNOWN); + + config +} + +fn set_up() -> SetUp { + let test_path = TempDir::new().unwrap(); + let config = get_test_config(test_path.path()); + let mut repo_config: IndexMap<String, PhpMixed> = IndexMap::new(); + repo_config.insert("url".to_string(), PhpMixed::String(TEST_URL.to_string())); + repo_config.insert( + "depot".to_string(), + PhpMixed::String(TEST_DEPOT.to_string()), + ); + repo_config.insert( + "branch".to_string(), + PhpMixed::String(TEST_BRANCH.to_string()), + ); + + let io = (); + let process = (); + let http_downloader = (); + let perforce = (); + // The driver construction and overrideDriverInternalPerforce (reflection) are not ported. + let driver = (); + + SetUp { + test_path, + config, + repo_config, + io, + process, + http_downloader, + perforce, + driver, + } +} + +fn tear_down(test_path: &std::path::Path) { + // cleanup directory under test path + let mut fs = Filesystem::new(None); + fs.remove_directory(test_path).unwrap(); +} + +struct TearDown { + test_path: std::path::PathBuf, +} + +impl TearDown { + fn new(test_path: std::path::PathBuf) -> Self { + TearDown { test_path } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.test_path); + } +} #[test] fn test_supports_returns_false_no_deep_check() { @@ -21,29 +111,129 @@ fn test_supports_returns_false_no_deep_check() { #[test] #[ignore = "mocks Perforce/repository/IO; mocking is not available"] fn test_initialize_captures_variables_from_repo_config() { + let SetUp { + test_path, + config, + repo_config, + io, + process, + http_downloader, + perforce, + driver, + } = set_up(); + let _tear_down = TearDown::new(test_path.path().to_path_buf()); + let _ = ( + &config, + &repo_config, + &io, + &process, + &http_downloader, + &perforce, + &driver, + ); todo!() } #[test] #[ignore = "mocks Perforce/repository/IO; mocking is not available"] fn test_initialize_logs_in_and_connects_client() { + let SetUp { + test_path, + config, + repo_config, + io, + process, + http_downloader, + perforce, + driver, + } = set_up(); + let _tear_down = TearDown::new(test_path.path().to_path_buf()); + let _ = ( + &config, + &repo_config, + &io, + &process, + &http_downloader, + &perforce, + &driver, + ); todo!() } #[test] #[ignore = "mocks Perforce/repository/IO; mocking is not available"] fn test_has_composer_file_returns_false_on_no_composer_file() { + let SetUp { + test_path, + config, + repo_config, + io, + process, + http_downloader, + perforce, + driver, + } = set_up(); + let _tear_down = TearDown::new(test_path.path().to_path_buf()); + let _ = ( + &config, + &repo_config, + &io, + &process, + &http_downloader, + &perforce, + &driver, + ); todo!() } #[test] #[ignore = "mocks Perforce/repository/IO; mocking is not available"] fn test_has_composer_file_returns_true_with_one_or_more_composer_files() { + let SetUp { + test_path, + config, + repo_config, + io, + process, + http_downloader, + perforce, + driver, + } = set_up(); + let _tear_down = TearDown::new(test_path.path().to_path_buf()); + let _ = ( + &config, + &repo_config, + &io, + &process, + &http_downloader, + &perforce, + &driver, + ); todo!() } #[test] #[ignore = "mocks Perforce/repository/IO; mocking is not available"] fn test_cleanup() { + let SetUp { + test_path, + config, + repo_config, + io, + process, + http_downloader, + perforce, + driver, + } = set_up(); + let _tear_down = TearDown::new(test_path.path().to_path_buf()); + let _ = ( + &config, + &repo_config, + &io, + &process, + &http_downloader, + &perforce, + &driver, + ); todo!() } diff --git a/crates/shirabe/tests/repository/vcs/svn_driver_test.rs b/crates/shirabe/tests/repository/vcs/svn_driver_test.rs index 262f0c3..9625088 100644 --- a/crates/shirabe/tests/repository/vcs/svn_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/svn_driver_test.rs @@ -3,10 +3,55 @@ use std::cell::RefCell; use std::rc::Rc; +use indexmap::IndexMap; use shirabe::config::Config; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; use shirabe::repository::vcs::SvnDriver; +use shirabe::util::filesystem::Filesystem; +use shirabe_php_shim::PhpMixed; +use tempfile::TempDir; + +struct SetUp { + home: TempDir, + config: Config, +} + +fn set_up() -> SetUp { + let home = TempDir::new().unwrap(); + let mut config = Config::new(true, None); + let mut top: IndexMap<String, PhpMixed> = IndexMap::new(); + let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new(); + config_section.insert( + "home".to_string(), + PhpMixed::String(home.path().to_string_lossy().into_owned()), + ); + top.insert("config".to_string(), PhpMixed::Array(config_section)); + config.merge(&top, Config::SOURCE_UNKNOWN); + + SetUp { home, config } +} + +fn tear_down(home: &std::path::Path) { + let mut fs = Filesystem::new(None); + fs.remove_directory(home).unwrap(); +} + +struct TearDown { + home: std::path::PathBuf, +} + +impl TearDown { + fn new(home: std::path::PathBuf) -> Self { + TearDown { home } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.home); + } +} fn support_provider() -> Vec<(&'static str, bool)> { vec![ @@ -35,5 +80,8 @@ fn test_support() { #[test] #[ignore = "constructs an SvnDriver and mocks a ProcessExecutor for the svn invocation"] fn test_wrong_credentials_in_url() { + let SetUp { home, config } = set_up(); + let _tear_down = TearDown::new(home.path().to_path_buf()); + let _ = &config; todo!() } diff --git a/crates/shirabe/tests/repository/vcs_repository_test.rs b/crates/shirabe/tests/repository/vcs_repository_test.rs index b9486fc..c687b3d 100644 --- a/crates/shirabe/tests/repository/vcs_repository_test.rs +++ b/crates/shirabe/tests/repository/vcs_repository_test.rs @@ -1,10 +1,55 @@ //! ref: composer/tests/Composer/Test/Repository/VcsRepositoryTest.php +use shirabe::util::filesystem::Filesystem; + +struct SetUp { + composer_home: std::path::PathBuf, + git_repo: std::path::PathBuf, +} + +fn set_up() -> SetUp { + // setUp lazily runs initialize(), which shells out to git to build a fixture repository + // on disk; the ExecutableFinder/ProcessExecutor-driven setup and the markTestSkipped + // skip path are not ported. + todo!() +} + +fn tear_down(composer_home: &std::path::Path, git_repo: &std::path::Path) { + let mut fs = Filesystem::new(None); + fs.remove_directory(composer_home).unwrap(); + fs.remove_directory(git_repo).unwrap(); +} + +struct TearDown { + composer_home: std::path::PathBuf, + git_repo: std::path::PathBuf, +} + +impl TearDown { + fn new(composer_home: std::path::PathBuf, git_repo: std::path::PathBuf) -> Self { + TearDown { + composer_home, + git_repo, + } + } +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.composer_home, &self.git_repo); + } +} + // testLoadVersions initialises a real git repository on disk and drives a VcsRepository over // it, then asserts the loaded package versions; the git fixture setup and constraint parsing // (look-around regex) are not ported. #[test] #[ignore = "not yet ported (initialises a git repo on disk and loads versions; constraint parsing uses a look-around regex)"] fn test_load_versions() { + let SetUp { + composer_home, + git_repo, + } = set_up(); + let _tear_down = TearDown::new(composer_home, git_repo); todo!() } diff --git a/crates/shirabe/tests/util/auth_helper_test.rs b/crates/shirabe/tests/util/auth_helper_test.rs index ebdd1f1..91bd9dd 100644 --- a/crates/shirabe/tests/util/auth_helper_test.rs +++ b/crates/shirabe/tests/util/auth_helper_test.rs @@ -2,6 +2,13 @@ // These mock IO/Config to drive AuthHelper's header/option building and interactive auth // storage; mocking is not available here. + +#[allow(dead_code)] +fn set_up() { + // Builds mocked IOInterface/Config and a real AuthHelper; mocking is not available. + todo!() +} + macro_rules! stub { ($name:ident) => { #[test] diff --git a/crates/shirabe/tests/util/bitbucket_test.rs b/crates/shirabe/tests/util/bitbucket_test.rs index 2eb015a..a89b85e 100644 --- a/crates/shirabe/tests/util/bitbucket_test.rs +++ b/crates/shirabe/tests/util/bitbucket_test.rs @@ -2,6 +2,13 @@ // These mock IO/Config/HttpDownloader to drive Bitbucket's OAuth/access-token flow; mocking // is not available and a real HttpDownloader reaches curl_multi_init (todo!()). + +#[allow(dead_code)] +fn set_up() { + // Builds mocked IO/HttpDownloader/Config and records time(); mocking is not available. + todo!() +} + macro_rules! stub { ($name:ident) => { #[test] diff --git a/crates/shirabe/tests/util/error_handler_test.rs b/crates/shirabe/tests/util/error_handler_test.rs index 92ce4e8..8f42bca 100644 --- a/crates/shirabe/tests/util/error_handler_test.rs +++ b/crates/shirabe/tests/util/error_handler_test.rs @@ -5,6 +5,27 @@ // trigger those by undefined-index access / array_merge misuse. There is no equivalent // runtime mechanism in Rust to port faithfully. +#[allow(dead_code)] +fn set_up() { + // ErrorHandler::register() installs a PHP set_error_handler; no Rust equivalent. + todo!() +} + +#[allow(dead_code)] +fn tear_down() { + // restore_error_handler() is PHP runtime machinery; no Rust equivalent. + todo!() +} + +#[allow(dead_code)] +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + #[test] #[ignore = "relies on PHP's set_error_handler converting an undefined-array-key notice into an ErrorException; no Rust equivalent"] fn test_error_handler_capture_notice() { diff --git a/crates/shirabe/tests/util/filesystem_test.rs b/crates/shirabe/tests/util/filesystem_test.rs index 4ed9c14..e101c79 100644 --- a/crates/shirabe/tests/util/filesystem_test.rs +++ b/crates/shirabe/tests/util/filesystem_test.rs @@ -3,6 +3,54 @@ // These exercise Filesystem path helpers and on-disk operations (sizes, copy, symlinks and // junctions over a temp tree). The filesystem fixtures and platform-specific symlink/junction // behaviour are not ported. +use shirabe::util::filesystem::Filesystem; +use shirabe_php_shim::{dirname, is_dir, is_file}; + +#[allow(dead_code)] +struct SetUp { + fs: Filesystem, + working_dir: String, + test_file: String, +} + +#[allow(dead_code)] +fn set_up() -> SetUp { + let fs = Filesystem::new(None); + // getUniqueTmpDirectory is base TestCase infrastructure that is not ported. + let working_dir: String = todo!(); + #[allow(unreachable_code)] + let unique_tmp: String = todo!(); + #[allow(unreachable_code)] + let test_file: String = format!("{unique_tmp}/composer_test_file"); + #[allow(unreachable_code)] + SetUp { + fs, + working_dir, + test_file, + } +} + +#[allow(dead_code)] +fn tear_down(set_up: &mut SetUp) { + if is_dir(&set_up.working_dir) { + let _ = set_up.fs.remove_directory(&set_up.working_dir); + } + if is_file(&set_up.test_file) { + let _ = set_up.fs.remove_directory(dirname(&set_up.test_file)); + } +} + +#[allow(dead_code)] +struct TearDown { + set_up: SetUp, +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&mut self.set_up); + } +} + macro_rules! stub { ($name:ident) => { #[test] diff --git a/crates/shirabe/tests/util/git_test.rs b/crates/shirabe/tests/util/git_test.rs index 69539ef..4802180 100644 --- a/crates/shirabe/tests/util/git_test.rs +++ b/crates/shirabe/tests/util/git_test.rs @@ -2,6 +2,13 @@ // These mock IO/Config/ProcessExecutor to drive Git::runCommand and mirror syncing; mocking // is not available here. + +#[allow(dead_code)] +fn set_up() { + // Builds mocked IO/Config/ProcessExecutor/Filesystem and a real Git; mocking is not available. + todo!() +} + macro_rules! stub { ($name:ident) => { #[test] diff --git a/crates/shirabe/tests/util/http/proxy_manager_test.rs b/crates/shirabe/tests/util/http/proxy_manager_test.rs index 50be143..0ed059d 100644 --- a/crates/shirabe/tests/util/http/proxy_manager_test.rs +++ b/crates/shirabe/tests/util/http/proxy_manager_test.rs @@ -2,11 +2,48 @@ // ProxyManager reads HTTP(S)_PROXY / CGI_HTTP_PROXY / no_proxy environment variables; the // env-dependent setup (without its setUp/tearDown isolation) is not ported. +use shirabe::util::http::proxy_manager::ProxyManager; +use shirabe::util::platform::Platform; + +fn set_up() { + Platform::clear_env("HTTP_PROXY"); + Platform::clear_env("http_proxy"); + Platform::clear_env("HTTPS_PROXY"); + Platform::clear_env("https_proxy"); + Platform::clear_env("NO_PROXY"); + Platform::clear_env("no_proxy"); + Platform::clear_env("CGI_HTTP_PROXY"); + Platform::clear_env("cgi_http_proxy"); + ProxyManager::reset(); +} + +fn tear_down() { + Platform::clear_env("HTTP_PROXY"); + Platform::clear_env("http_proxy"); + Platform::clear_env("HTTPS_PROXY"); + Platform::clear_env("https_proxy"); + Platform::clear_env("NO_PROXY"); + Platform::clear_env("no_proxy"); + Platform::clear_env("CGI_HTTP_PROXY"); + Platform::clear_env("cgi_http_proxy"); + ProxyManager::reset(); +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + macro_rules! stub { ($name:ident) => { #[test] #[ignore = "not yet ported (ProxyManager is driven by proxy environment variables)"] fn $name() { + let _tear_down = TearDown; + set_up(); todo!() } }; diff --git a/crates/shirabe/tests/util/ini_helper_test.rs b/crates/shirabe/tests/util/ini_helper_test.rs index e214a78..59dc967 100644 --- a/crates/shirabe/tests/util/ini_helper_test.rs +++ b/crates/shirabe/tests/util/ini_helper_test.rs @@ -1,7 +1,40 @@ //! ref: composer/tests/Composer/Test/Util/IniHelperTest.php use shirabe::util::ini_helper::IniHelper; -use shirabe_php_shim::{PATH_SEPARATOR, putenv}; +use shirabe::util::platform::Platform; +use shirabe_php_shim::{PATH_SEPARATOR, getenv, putenv}; + +#[allow(dead_code)] +fn set_up() -> TearDown { + // Register our name with XdebugHandler. + // TODO: XdebugHandler is the external composer/xdebug-handler package and is not ported. + todo!(); + // Save current state + #[allow(unreachable_code)] + let env_original = getenv("COMPOSER_ORIGINAL_INIS"); + TearDown { env_original } +} + +#[allow(dead_code)] +fn tear_down(env_original: &Option<String>) { + // Restore original state + if let Some(env_original) = env_original { + putenv(&format!("COMPOSER_ORIGINAL_INIS={env_original}")); + } else { + Platform::clear_env("COMPOSER_ORIGINAL_INIS"); + } +} + +#[allow(dead_code)] +struct TearDown { + env_original: Option<String>, +} + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(&self.env_original); + } +} fn set_env(paths: &[&str]) { putenv(&format!( diff --git a/crates/shirabe/tests/util/perforce_test.rs b/crates/shirabe/tests/util/perforce_test.rs index 3958b83..59b9fd8 100644 --- a/crates/shirabe/tests/util/perforce_test.rs +++ b/crates/shirabe/tests/util/perforce_test.rs @@ -2,6 +2,14 @@ // These mock IO and a ProcessExecutor to drive Perforce client/stream/command behaviour; // mocking is not available here. + +#[allow(dead_code)] +fn set_up() { + // Builds mocked ProcessExecutor/IO, the test repo config, and a Windows-flagged Perforce; + // mocking is not available. + todo!() +} + macro_rules! stub { ($name:ident) => { #[test] diff --git a/crates/shirabe/tests/util/stream_context_factory_test.rs b/crates/shirabe/tests/util/stream_context_factory_test.rs index 6f484fa..f75c78d 100644 --- a/crates/shirabe/tests/util/stream_context_factory_test.rs +++ b/crates/shirabe/tests/util/stream_context_factory_test.rs @@ -3,11 +3,44 @@ // These build a stream context and assert proxy/option handling driven by HTTP(S)_PROXY / // no_proxy environment variables; the env-dependent setup (without its setUp/tearDown // isolation) is not ported. +use shirabe::util::http::proxy_manager::ProxyManager; +use shirabe::util::platform::Platform; + +fn set_up() { + Platform::clear_env("HTTP_PROXY"); + Platform::clear_env("http_proxy"); + Platform::clear_env("HTTPS_PROXY"); + Platform::clear_env("https_proxy"); + Platform::clear_env("NO_PROXY"); + Platform::clear_env("no_proxy"); + ProxyManager::reset(); +} + +fn tear_down() { + Platform::clear_env("HTTP_PROXY"); + Platform::clear_env("http_proxy"); + Platform::clear_env("HTTPS_PROXY"); + Platform::clear_env("https_proxy"); + Platform::clear_env("NO_PROXY"); + Platform::clear_env("no_proxy"); + ProxyManager::reset(); +} + +struct TearDown; + +impl Drop for TearDown { + fn drop(&mut self) { + tear_down(); + } +} + macro_rules! stub { ($name:ident) => { #[test] #[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] fn $name() { + let _tear_down = TearDown; + set_up(); todo!() } }; |
