diff options
Diffstat (limited to 'crates/shirabe/tests/common')
| -rw-r--r-- | crates/shirabe/tests/common/config_stub.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/tests/common/http_downloader_mock.rs | 18 | ||||
| -rw-r--r-- | crates/shirabe/tests/common/io_mock.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/tests/common/process_executor_mock.rs | 11 | ||||
| -rw-r--r-- | crates/shirabe/tests/common/test_case.rs | 36 |
5 files changed, 45 insertions, 36 deletions
diff --git a/crates/shirabe/tests/common/config_stub.rs b/crates/shirabe/tests/common/config_stub.rs index bf81462a..656dea60 100644 --- a/crates/shirabe/tests/common/config_stub.rs +++ b/crates/shirabe/tests/common/config_stub.rs @@ -11,8 +11,6 @@ use indexmap::IndexMap; use shirabe::config::Config; use shirabe_php_shim::PhpMixed; -use std::cell::RefCell; -use std::rc::Rc; pub struct ConfigStubBuilder { use_environment: bool, @@ -65,8 +63,8 @@ impl ConfigStubBuilder { config } - pub fn build_shared(self) -> Rc<RefCell<Config>> { - Rc::new(RefCell::new(self.build())) + pub fn build_shared(self) -> std::rc::Rc<std::cell::RefCell<Config>> { + std::rc::Rc::new(std::cell::RefCell::new(self.build())) } } diff --git a/crates/shirabe/tests/common/http_downloader_mock.rs b/crates/shirabe/tests/common/http_downloader_mock.rs index 85d3ec81..59519ca4 100644 --- a/crates/shirabe/tests/common/http_downloader_mock.rs +++ b/crates/shirabe/tests/common/http_downloader_mock.rs @@ -9,8 +9,6 @@ use shirabe::util::http_downloader::{ HttpDownloader, HttpDownloaderMockExpectation, HttpDownloaderMockHandler, }; use shirabe_php_shim::PhpMixed; -use std::cell::RefCell; -use std::rc::Rc; // A single HTTP request expectation as written in the PHP tests: a `url` plus an // optional response (`status`/`body`/`headers`). `options` of `None` matches any @@ -41,7 +39,7 @@ pub fn expect_full( } } -pub struct HttpDownloaderMockGuard(Rc<RefCell<HttpDownloader>>); +pub struct HttpDownloaderMockGuard(std::rc::Rc<std::cell::RefCell<HttpDownloader>>); impl Drop for HttpDownloaderMockGuard { fn drop(&mut self) { @@ -60,10 +58,16 @@ pub fn get_http_downloader_mock( expectations: Vec<HttpDownloaderMockExpectation>, strict: bool, default_handler: HttpDownloaderMockHandler, -) -> (Rc<RefCell<HttpDownloader>>, HttpDownloaderMockGuard) { - let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new())); - let config = Rc::new(RefCell::new(Config::new(false, None))); - let downloader = Rc::new(RefCell::new(HttpDownloader::__new_mock(io, config))); +) -> ( + std::rc::Rc<std::cell::RefCell<HttpDownloader>>, + HttpDownloaderMockGuard, +) { + let io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>> = + std::rc::Rc::new(std::cell::RefCell::new(NullIO::new())); + let config = std::rc::Rc::new(std::cell::RefCell::new(Config::new(false, None))); + let downloader = std::rc::Rc::new(std::cell::RefCell::new(HttpDownloader::__new_mock( + io, config, + ))); downloader .borrow_mut() .__expects(expectations, strict, default_handler); diff --git a/crates/shirabe/tests/common/io_mock.rs b/crates/shirabe/tests/common/io_mock.rs index 7b932a87..e54c45b9 100644 --- a/crates/shirabe/tests/common/io_mock.rs +++ b/crates/shirabe/tests/common/io_mock.rs @@ -8,9 +8,7 @@ use shirabe::util::platform::Platform; use shirabe_external_packages::composer::pcre::Preg; use shirabe_external_packages::symfony::console::output::output_interface; use shirabe_php_shim::{PHP_EOL, PhpMixed, preg_quote}; -use std::cell::RefCell; use std::collections::VecDeque; -use std::rc::Rc; // A single entry of the IO expectation list. PHP models these as associative // arrays (`{text, regex?}` / `{ask, reply}` / `{auth: [repo, user, pass]}`); the @@ -344,7 +342,7 @@ fn trim_eol(question: &str) -> &str { question.trim_end_matches(['\r', '\n']) } -pub struct IOMockGuard(Rc<RefCell<IOMock>>); +pub struct IOMockGuard(std::rc::Rc<std::cell::RefCell<IOMock>>); impl Drop for IOMockGuard { fn drop(&mut self) { @@ -358,7 +356,9 @@ impl Drop for IOMockGuard { // For testing only. Mirrors TestCase::getIOMock: returns a shared IOMock handle // plus a guard that runs assert_complete when it drops at the end of the test scope. -pub fn get_io_mock(verbosity: i64) -> anyhow::Result<(Rc<RefCell<IOMock>>, IOMockGuard)> { - let mock = Rc::new(RefCell::new(IOMock::new(verbosity)?)); +pub fn get_io_mock( + verbosity: i64, +) -> anyhow::Result<(std::rc::Rc<std::cell::RefCell<IOMock>>, IOMockGuard)> { + let mock = std::rc::Rc::new(std::cell::RefCell::new(IOMock::new(verbosity)?)); Ok((mock.clone(), IOMockGuard(mock))) } diff --git a/crates/shirabe/tests/common/process_executor_mock.rs b/crates/shirabe/tests/common/process_executor_mock.rs index 698d8d26..33d9dfba 100644 --- a/crates/shirabe/tests/common/process_executor_mock.rs +++ b/crates/shirabe/tests/common/process_executor_mock.rs @@ -2,8 +2,6 @@ use shirabe::util::process_executor::{MockExpectation, MockHandler, ProcessExecutor}; use shirabe_php_shim::PhpMixed; -use std::cell::RefCell; -use std::rc::Rc; // A command expectation as written in the PHP tests: either a bare command // (`'git command'` / `['git', '--version']`) or the full @@ -72,7 +70,7 @@ impl<const N: usize> IntoMockCmd for [&str; N] { } } -pub struct ProcessExecutorMockGuard(Rc<RefCell<ProcessExecutor>>); +pub struct ProcessExecutorMockGuard(std::rc::Rc<std::cell::RefCell<ProcessExecutor>>); impl Drop for ProcessExecutorMockGuard { fn drop(&mut self) { @@ -91,8 +89,11 @@ pub fn get_process_executor_mock( expectations: Vec<MockExpectation>, strict: bool, default_handler: MockHandler, -) -> (Rc<RefCell<ProcessExecutor>>, ProcessExecutorMockGuard) { - let process = Rc::new(RefCell::new(ProcessExecutor::new(None))); +) -> ( + std::rc::Rc<std::cell::RefCell<ProcessExecutor>>, + ProcessExecutorMockGuard, +) { + let process = std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(None))); process .borrow_mut() .__expects(expectations, strict, default_handler); diff --git a/crates/shirabe/tests/common/test_case.rs b/crates/shirabe/tests/common/test_case.rs index 7365f734..5bfc2d0f 100644 --- a/crates/shirabe/tests/common/test_case.rs +++ b/crates/shirabe/tests/common/test_case.rs @@ -30,9 +30,7 @@ use shirabe_external_packages::symfony::console::output::stream_output::StreamOu use shirabe_php_shim::{PhpMixed, PhpResource}; use shirabe_semver::VersionParser; use shirabe_semver::constraint::{AnyConstraint, SimpleConstraint}; -use std::cell::RefCell; use std::path::PathBuf; -use std::rc::Rc; use tempfile::TempDir; /// ref: TestCase::getPackage (default class CompletePackage) @@ -170,17 +168,22 @@ pub fn init_temp_composer( } } -fn null_io() -> Rc<RefCell<dyn IOInterface>> { - Rc::new(RefCell::new(NullIO::new())) +fn null_io() -> std::rc::Rc<std::cell::RefCell<dyn IOInterface>> { + std::rc::Rc::new(std::cell::RefCell::new(NullIO::new())) } /// ref: FactoryMock::createInstallationManager (the real installers are never created in tests, so a /// bare InstallationManager over a mock HttpDownloader suffices). -fn installation_manager(io: &Rc<RefCell<dyn IOInterface>>) -> Rc<RefCell<InstallationManager>> { - let config = Rc::new(RefCell::new(Config::new(false, None))); - let http_downloader = Rc::new(RefCell::new(HttpDownloader::__new_mock(io.clone(), config))); - let r#loop = Rc::new(RefCell::new(Loop::new(http_downloader, None))); - Rc::new(RefCell::new(InstallationManager::new( +fn installation_manager( + io: &std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, +) -> std::rc::Rc<std::cell::RefCell<InstallationManager>> { + let config = std::rc::Rc::new(std::cell::RefCell::new(Config::new(false, None))); + let http_downloader = std::rc::Rc::new(std::cell::RefCell::new(HttpDownloader::__new_mock( + io.clone(), + config, + ))); + let r#loop = std::rc::Rc::new(std::cell::RefCell::new(Loop::new(http_downloader, None))); + std::rc::Rc::new(std::cell::RefCell::new(InstallationManager::new( r#loop, io.clone(), None, @@ -227,7 +230,9 @@ pub fn create_composer_lock( let io = null_io(); let json_file = JsonFile::new("./composer.lock".to_string(), None, None).unwrap(); let composer_file_contents = std::fs::read_to_string("./composer.json").unwrap_or_default(); - let process = Rc::new(RefCell::new(ProcessExecutor::new(Some(io.clone())))); + let process = std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(Some( + io.clone(), + )))); let mut locker = Locker::new( io.clone(), json_file, @@ -279,7 +284,7 @@ pub struct ApplicationTester { application: ApplicationHandle, inputs: Vec<String>, status_code: Option<i32>, - output: Option<Rc<RefCell<dyn OutputInterface>>>, + output: Option<std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>>, /// Handles retained before injection so `get_display`/`get_error_output` can read the memory /// streams without relying on a `get_stream()` accessor across the ConsoleOutput composition gap. output_stream: Option<PhpResource>, @@ -320,7 +325,8 @@ impl ApplicationTester { self.init_output(&options); - let input: Rc<RefCell<dyn InputInterface>> = Rc::new(RefCell::new(array_input)); + let input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>> = + std::rc::Rc::new(std::cell::RefCell::new(array_input)); let output = self.output.clone().expect("init_output initializes output"); let status_code = self.application.run(Some(input), Some(output))?; @@ -346,7 +352,7 @@ impl ApplicationTester { if let Some(verbosity) = options.verbosity { output.set_verbosity(verbosity); } - self.output = Some(Rc::new(RefCell::new(output))); + self.output = Some(std::rc::Rc::new(std::cell::RefCell::new(output))); } else { let stdout = shirabe_php_shim::php_fopen_resource("php://memory", "w"); let stderr = shirabe_php_shim::php_fopen_resource("php://memory", "w"); @@ -363,10 +369,10 @@ impl ApplicationTester { error_output.set_verbosity(output.get_verbosity()); error_output.set_decorated(output.is_decorated()); - output.set_error_output(Rc::new(RefCell::new(error_output))); + output.set_error_output(std::rc::Rc::new(std::cell::RefCell::new(error_output))); output.__set_stream(stdout); - self.output = Some(Rc::new(RefCell::new(output))); + self.output = Some(std::rc::Rc::new(std::cell::RefCell::new(output))); } } |
