From f639066eaf49325fdbf1b697fb24c187b2d5038e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 26 Jun 2026 01:01:53 +0900 Subject: test(command): port command test bodies from Composer PHPUnit suite Faithfully port repository, base_dependency, exec, dump_autoload, run_script, licenses command tests from their PHP counterparts (expected values verbatim). Newly passing: repository (6), base_dependency (5), exec (2). Tests whose ported bodies hit a genuine unported path (HTTP/curl, event-dispatch re-entrancy, spl_autoload_register, php_uname, instance_of, un-delimited Preg patterns, Config::merge dropping list repos) keep faithful bodies but stay #[ignore] with precise reasons; no assertions weakened. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/tests/command/exec_command_test.rs | 72 +++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) (limited to 'crates/shirabe/tests/command/exec_command_test.rs') diff --git a/crates/shirabe/tests/command/exec_command_test.rs b/crates/shirabe/tests/command/exec_command_test.rs index d182754..95649f7 100644 --- a/crates/shirabe/tests/command/exec_command_test.rs +++ b/crates/shirabe/tests/command/exec_command_test.rs @@ -1,13 +1,77 @@ //! ref: composer/tests/Composer/Test/Command/ExecCommandTest.php +use crate::test_case::{RunOptions, get_application_tester, init_temp_composer}; +use serial_test::serial; +use shirabe_php_shim::PhpMixed; + +/// ref: ExecCommandTest::testListThrowsIfNoBinariesExist #[test] -#[ignore = "missing TestCase::init_temp_composer and get_application_tester (ApplicationTester with run/get_display) infrastructure"] +#[serial] fn test_list_throws_if_no_binaries_exist() { - todo!() + let tear_down = init_temp_composer(Some(&serde_json::json!({})), None, None, false); + let composer_dir = tear_down.working_dir(); + + let composer_bin_dir = format!("{}/vendor/bin", composer_dir.display()); + + let mut app_tester = get_application_tester(); + let err = app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("exec")), + (PhpMixed::from("--list"), PhpMixed::from(true)), + ], + RunOptions::default(), + ) + .expect_err("exec --list with no binaries should raise a RuntimeException"); + + assert!( + err.to_string().contains(&format!( + "No binaries found in composer.json or in bin-dir ({})", + composer_bin_dir + )), + "expected RuntimeException about no binaries, got: {:?}", + err.to_string(), + ); + + drop(tear_down); } +/// ref: ExecCommandTest::testList #[test] -#[ignore = "missing TestCase::init_temp_composer and get_application_tester (ApplicationTester with run/get_display) infrastructure"] +#[serial] fn test_list() { - todo!() + let tear_down = init_temp_composer( + Some(&serde_json::json!({ + "bin": [ + "a", + ], + })), + None, + None, + false, + ); + let composer_dir = tear_down.working_dir(); + + let composer_bin_dir = format!("{}/vendor/bin", composer_dir.display()); + std::fs::create_dir_all(&composer_bin_dir).unwrap(); + std::fs::write(format!("{}/b", composer_bin_dir), "").unwrap(); + std::fs::write(format!("{}/b.bat", composer_bin_dir), "").unwrap(); + std::fs::write(format!("{}/c", composer_bin_dir), "").unwrap(); + + let mut app_tester = get_application_tester(); + app_tester + .run( + vec![ + (PhpMixed::from("command"), PhpMixed::from("exec")), + (PhpMixed::from("--list"), PhpMixed::from(true)), + ], + RunOptions::default(), + ) + .unwrap(); + + let output = app_tester.get_display(); + + assert_eq!("Available binaries:\n- b\n- c\n- a (local)", output.trim(),); + + drop(tear_down); } -- cgit v1.3.1