From c396d54f0302658304aa924a85b470f02d348182 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 21 Jun 2026 00:51:53 +0900 Subject: test: port ForgejoUrl, Silencer, PlatformRequirementFilterFactory tests Factory's instance-creation tests pass. ForgejoUrl (undelimited regex panic), Silencer (trigger_error/microtime todo!()), and the factory's unknown-type case (get_debug_type todo!()) are marked #[ignore]. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/tests/util/forgejo_url_test.rs | 42 +++++++++++++++++++++++++ crates/shirabe/tests/util/main.rs | 2 ++ crates/shirabe/tests/util/silencer_test.rs | 44 +++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) (limited to 'crates/shirabe/tests/util') diff --git a/crates/shirabe/tests/util/forgejo_url_test.rs b/crates/shirabe/tests/util/forgejo_url_test.rs index 970578e..17dae04 100644 --- a/crates/shirabe/tests/util/forgejo_url_test.rs +++ b/crates/shirabe/tests/util/forgejo_url_test.rs @@ -1 +1,43 @@ //! ref: composer/tests/Composer/Test/Util/ForgejoUrlTest.php + +use shirabe::util::forgejo_url::ForgejoUrl; + +#[test] +#[ignore = "Preg::match panics: ForgejoUrl::URL_REGEX is an undelimited pattern"] +fn test_create() { + for repo_url in create_provider() { + let forgejo_url = ForgejoUrl::try_from(Some(repo_url)); + + assert!(forgejo_url.is_some()); + let forgejo_url = forgejo_url.unwrap(); + assert_eq!("codeberg.org", forgejo_url.origin_url); + assert_eq!("acme", forgejo_url.owner); + assert_eq!("repo", forgejo_url.repository); + assert_eq!( + "https://codeberg.org/api/v1/repos/acme/repo", + forgejo_url.api_url + ); + } +} + +fn create_provider() -> Vec<&'static str> { + vec![ + "git@codeberg.org:acme/repo.git", + "https://codeberg.org/acme/repo", + "https://codeberg.org/acme/repo.git", + ] +} + +#[test] +#[ignore = "Preg::match panics: ForgejoUrl::URL_REGEX is an undelimited pattern"] +fn test_create_invalid() { + assert!(ForgejoUrl::create("https://example.org").is_err()); +} + +#[test] +#[ignore = "Preg::match panics: ForgejoUrl::URL_REGEX is an undelimited pattern"] +fn test_generate_ssh_url() { + let forgejo_url = ForgejoUrl::create("git@codeberg.org:acme/repo.git").unwrap(); + + assert_eq!("git@codeberg.org:acme/repo.git", forgejo_url.generate_ssh_url()); +} diff --git a/crates/shirabe/tests/util/main.rs b/crates/shirabe/tests/util/main.rs index 1ce0dd7..349aeb6 100644 --- a/crates/shirabe/tests/util/main.rs +++ b/crates/shirabe/tests/util/main.rs @@ -1 +1,3 @@ +mod forgejo_url_test; mod platform_test; +mod silencer_test; diff --git a/crates/shirabe/tests/util/silencer_test.rs b/crates/shirabe/tests/util/silencer_test.rs index 8152b6e..42d0be4 100644 --- a/crates/shirabe/tests/util/silencer_test.rs +++ b/crates/shirabe/tests/util/silencer_test.rs @@ -1 +1,45 @@ //! ref: composer/tests/Composer/Test/Util/SilencerTest.php + +use shirabe::util::silencer::Silencer; +use shirabe_php_shim::{E_USER_WARNING, RuntimeException, error_reporting, microtime, trigger_error}; + +/// Test succeeds when no warnings are emitted externally, and original level is restored. +#[test] +#[ignore = "trigger_error is todo!() in the php-shim"] +fn test_silencer() { + let before = error_reporting(None); + + // Check warnings are suppressed correctly + Silencer::suppress(None); + trigger_error("Test", E_USER_WARNING); + Silencer::restore(); + + // Check all parameters and return values are passed correctly in a silenced call. + let result = Silencer::call(|| { + trigger_error("Test", E_USER_WARNING); + + let (a, b, c) = (2, 3, 4); + Ok(a * b * c) + }) + .unwrap(); + assert_eq!(24, result); + + // Check the error reporting setting was restored correctly + assert_eq!(before, error_reporting(None)); +} + +/// Test whether exception from silent callbacks are correctly forwarded. +#[test] +#[ignore = "microtime is todo!() in the php-shim"] +fn test_silenced_exception() { + let verification = format!("{}", microtime(false)); + let err = Silencer::call(|| -> anyhow::Result<()> { + Err(RuntimeException { + message: verification.clone(), + code: 0, + } + .into()) + }) + .unwrap_err(); + assert_eq!(verification, err.to_string()); +} -- cgit v1.3.1