diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe/src/installer/installation_manager.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/tests/installer/installation_manager_test.rs | 40 |
2 files changed, 44 insertions, 5 deletions
diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs index 6c46754c..2d60997c 100644 --- a/crates/shirabe/src/installer/installation_manager.rs +++ b/crates/shirabe/src/installer/installation_manager.rs @@ -133,6 +133,15 @@ impl InstallationManager { self.cache = std::cell::RefCell::new(IndexMap::new()); } + /// For testing only: adds an installer as a pre-built shared handle, so the caller keeps an + /// identity handle usable for PHP `assertSame`-style comparisons (`Rc::ptr_eq`) and for + /// `remove_installer`. `add_installer` cannot serve because `Rc::from(Box)` reallocates, + /// losing the caller's pointer identity. + pub fn __add_installer(&mut self, installer: std::rc::Rc<dyn InstallerInterface>) { + array_unshift(&mut self.installers, installer); + self.cache = std::cell::RefCell::new(IndexMap::new()); + } + /// Removes installer pub fn remove_installer(&mut self, installer: &dyn InstallerInterface) { let target = installer as *const dyn InstallerInterface as *const (); diff --git a/crates/shirabe/tests/installer/installation_manager_test.rs b/crates/shirabe/tests/installer/installation_manager_test.rs index f5012ef7..867e759a 100644 --- a/crates/shirabe/tests/installer/installation_manager_test.rs +++ b/crates/shirabe/tests/installer/installation_manager_test.rs @@ -283,13 +283,43 @@ fn test_add_get_installer() { assert!(manager.get_installer("unregistered").is_err()); } -#[ignore = "removeInstaller compares installers by object identity, but add_installer moves the Box<dyn InstallerInterface> into the manager, leaving no &dyn reference to pass back to remove_installer; faithful reproduction needs a shared-ownership installer registry"] #[test] fn test_add_remove_installer() { - // TODO(phase-d): removeInstaller compares installers by object identity, but add_installer - // moves the Box<dyn InstallerInterface> into the manager, leaving no &dyn reference to pass - // back to remove_installer; faithful reproduction needs a shared-ownership installer registry. - todo!() + let set_up = set_up(); + let mut installer = MockInstaller::new(); + installer + .expect_supports() + .times(2) + .returning(|arg| arg == "vendor"); + // The manager stores installers as Rc, so the PHP object-identity semantics (assertSame, + // removeInstaller) map to Rc::ptr_eq on a handle registered via __add_installer. + let installer: std::rc::Rc<dyn InstallerInterface> = std::rc::Rc::new(installer); + + let mut installer2 = MockInstaller::new(); + installer2 + .expect_supports() + .times(1) + .returning(|arg| arg == "vendor"); + let installer2: std::rc::Rc<dyn InstallerInterface> = std::rc::Rc::new(installer2); + + let mut manager = + shirabe::installer::InstallationManager::new(set_up.loop_.clone(), set_up.io.clone(), None); + + manager.__add_installer(installer.clone()); + assert!(std::rc::Rc::ptr_eq( + &installer, + &manager.get_installer("vendor").unwrap() + )); + manager.__add_installer(installer2.clone()); + assert!(std::rc::Rc::ptr_eq( + &installer2, + &manager.get_installer("vendor").unwrap() + )); + manager.remove_installer(&*installer2); + assert!(std::rc::Rc::ptr_eq( + &installer, + &manager.get_installer("vendor").unwrap() + )); } #[ignore = "partial mock of InstallationManager (onlyMethods install/update/uninstall) with expects(once)->with(...) is not reproducible without method-overriding mocks; execute() also takes the batched download path"] |
