From adfa7c6b295521a6f8fdf4084993a80a8030e49b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 19 Jun 2026 23:00:38 +0900 Subject: test(command): add basic smoke tests --- crates/shirabe/src/console/application.rs | 45 ++++++++++--------------------- 1 file changed, 14 insertions(+), 31 deletions(-) (limited to 'crates/shirabe/src/console/application.rs') diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 591114a..82aa03d 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -127,7 +127,6 @@ pub struct Application { version: String, command_loader: Option>, catch_exceptions: bool, - auto_exit: bool, definition: Option>>, helper_set: Option>>, terminal: Terminal, @@ -201,7 +200,6 @@ impl Application { version, command_loader: None, catch_exceptions: true, - auto_exit: true, definition: None, helper_set: None, terminal: Terminal::new(), @@ -318,7 +316,7 @@ impl Application { application: &std::rc::Rc>, input: Option>>, output: Option>>, - ) -> anyhow::Result { + ) -> anyhow::Result { let output = match output { Some(output) => Some(output), None => Some( @@ -334,7 +332,7 @@ impl Application { application: &std::rc::Rc>, input: std::rc::Rc>, output: std::rc::Rc>, - ) -> anyhow::Result { + ) -> anyhow::Result { application.borrow_mut().disable_plugins_by_default = input .borrow() .has_parameter_option(PhpMixed::from(vec!["--no-plugins"]), false); @@ -907,7 +905,7 @@ impl Application { } let mut start_time: Option = None; - let result_outcome: anyhow::Result = (|| -> anyhow::Result { + let result_outcome: anyhow::Result = (|| -> anyhow::Result { if input .borrow() .has_parameter_option(PhpMixed::from(vec!["--profile"]), false) @@ -921,7 +919,7 @@ impl Application { let _ = start_time.unwrap(); } - let result: i64 = Application::base_do_run(application, input.clone(), output.clone())?; + let result = Application::base_do_run(application, input.clone(), output.clone())?; if input .borrow() @@ -975,7 +973,7 @@ impl Application { ); } - Ok(see.get_code()) + Ok(see.get_code() as i32) } else { let mut ghe = GithubActionError::new(io.clone()); ghe.emit(&e.to_string(), None, None); @@ -1443,7 +1441,7 @@ impl Application { application: &std::rc::Rc>, input: Option>>, output: Option>>, - ) -> anyhow::Result { + ) -> anyhow::Result { if shirabe_php_shim::function_exists("putenv") { let (height, width) = { let app = application.borrow(); @@ -1479,7 +1477,7 @@ impl Application { this.render_throwable(e, output.clone()); }; - let result = (|| -> anyhow::Result { + let result = (|| -> anyhow::Result { application.borrow_mut().configure_io(&input, &output)?; let exit_code = Application::do_run(application, input.clone(), output.clone())?; @@ -1487,7 +1485,7 @@ impl Application { Ok(exit_code) })(); - let mut exit_code = match result { + let exit_code = match result { Ok(exit_code) => exit_code, Err(e) => { if !application.borrow().catch_exceptions { @@ -1512,14 +1510,6 @@ impl Application { // finally: handler restore. See TODO above; no-op here. - if application.borrow().auto_exit { - if exit_code > 255 { - exit_code = 255; - } - - shirabe_php_shim::exit(exit_code); - } - Ok(exit_code) } @@ -1528,7 +1518,7 @@ impl Application { application: &std::rc::Rc>, input: std::rc::Rc>, output: std::rc::Rc>, - ) -> anyhow::Result { + ) -> anyhow::Result { if input.borrow().has_parameter_option( PhpMixed::from(vec![ PhpMixed::from("--version".to_string()), @@ -1801,16 +1791,6 @@ impl Application { self.catch_exceptions = boolean; } - /// Gets whether to automatically exit after a command execution or not. - pub fn is_auto_exit_enabled(&self) -> bool { - self.auto_exit - } - - /// Sets whether to automatically exit after a command execution or not. - pub fn set_auto_exit(&mut self, boolean: bool) { - self.auto_exit = boolean; - } - /// Gets the name of the application. pub fn get_name(&self) -> String { self.name.clone() @@ -2545,7 +2525,7 @@ impl Application { command: std::rc::Rc>, input: std::rc::Rc>, output: std::rc::Rc>, - ) -> anyhow::Result { + ) -> anyhow::Result { if let Some(helper_set) = command.borrow().get_helper_set() { for (_alias, helper) in helper_set.borrow().get_iterator() { // if ($helper instanceof InputAwareInterface) $helper->setInput($input); @@ -2588,7 +2568,10 @@ impl Application { } } - command.borrow_mut().run(input.clone(), output.clone()) + command + .borrow_mut() + .run(input.clone(), output.clone()) + .map(|c| c as i32) } /// Gets the name of the command based on input. -- cgit v1.3.1