diff options
Diffstat (limited to 'crates/shirabe/tests/documentation_test.rs')
| -rw-r--r-- | crates/shirabe/tests/documentation_test.rs | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/crates/shirabe/tests/documentation_test.rs b/crates/shirabe/tests/documentation_test.rs index 7c9bef1..07694d8 100644 --- a/crates/shirabe/tests/documentation_test.rs +++ b/crates/shirabe/tests/documentation_test.rs @@ -1,7 +1,58 @@ //! ref: composer/tests/Composer/Test/DocumentationTest.php +use std::cell::RefCell; +use std::rc::Rc; + +use shirabe::console::application::ApplicationHandle; +use shirabe_external_packages::symfony::console::command::Command; +use shirabe_external_packages::symfony::console::descriptor::application_description::ApplicationDescription; + +fn get_command_name(command: &Rc<RefCell<dyn Command>>) -> String { + let mut name = command.borrow().get_name().unwrap_or_default(); + for alias in command.borrow().get_aliases() { + name = format!("{} / {}", name, alias); + } + + name +} + +fn provide_command_cases() -> Vec<Rc<RefCell<dyn Command>>> { + let application = ApplicationHandle::new("Composer".to_string(), "".to_string()).unwrap(); + // setAutoExit(false) is the default in Shirabe. The setCatchErrors() call is guarded by + // method_exists() in PHP and has no Rust equivalent. + application.set_catch_exceptions(false); + + let mut description = + ApplicationDescription::new(application.__base_application(), None, false); + + let mut commands = Vec::new(); + for command in description.get_commands().values() { + if ["about", "completion", "list"] + .contains(&command.borrow().get_name().as_deref().unwrap_or("")) + { + continue; + } + commands.push(command.clone()); + } + + commands +} + #[test] -#[ignore = "Application::set_auto_exit (setAutoExit) does not exist, required by provideCommandCases"] fn test_command() { - todo!() + let doc_content = std::fs::read_to_string(format!( + "{}/../../composer/doc/03-cli.md", + env!("CARGO_MANIFEST_DIR") + )) + .unwrap(); + + for command in provide_command_cases() { + assert!( + // TODO: test description + // TODO: test options + doc_content.contains(&format!("\n## {}\n\n", get_command_name(&command))), + "doc/03-cli.md does not contain a section for command \"{}\"", + get_command_name(&command), + ); + } } |
