diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 00:51:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 00:51:34 +0900 |
| commit | 7bea9042a79d3cbfe31cc2595e8b8c6a3788ba15 (patch) | |
| tree | 3ed5b522c21f8fd80249f02751e46264537620f7 /crates/shirabe | |
| parent | a01e3a45d1b183ee7fe9ca45543b0663d5995faa (diff) | |
| download | php-shirabe-7bea9042a79d3cbfe31cc2595e8b8c6a3788ba15.tar.gz php-shirabe-7bea9042a79d3cbfe31cc2595e8b8c6a3788ba15.tar.zst php-shirabe-7bea9042a79d3cbfe31cc2595e8b8c6a3788ba15.zip | |
test: port small leaf tests (config, filters, platform, formatter)
Port DefaultConfigTest, IgnoreAll/IgnoreNothingPlatformRequirementFilterTest,
PlatformTest, GitExcludeFilterTest, and HtmlOutputFormatterTest. Each PHP
Test/<Subdir>/ maps to a single integration-test binary via tests/<dir>/main.rs
(the target is named after the directory) whose #[test] functions are collected
from the module tree.
Tests that exercise unported library behavior (regex backreferences,
Preg::split, env expansion) are marked #[ignore].
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe')
12 files changed, 162 insertions, 0 deletions
diff --git a/crates/shirabe/tests/console/html_output_formatter_test.rs b/crates/shirabe/tests/console/html_output_formatter_test.rs index e3b65d9..af75551 100644 --- a/crates/shirabe/tests/console/html_output_formatter_test.rs +++ b/crates/shirabe/tests/console/html_output_formatter_test.rs @@ -1 +1,35 @@ //! ref: composer/tests/Composer/Test/Console/HtmlOutputFormatterTest.php + +use indexmap::IndexMap; +use shirabe::console::html_output_formatter::HtmlOutputFormatter; +use shirabe_external_packages::symfony::console::formatter::{ + OutputFormatterStyle, OutputFormatterStyleInterface, +}; + +#[test] +#[ignore = "HtmlOutputFormatter::format uses a regex pattern the regex crate cannot compile (backreferences)"] +fn test_formatting() { + let mut styles: IndexMap<String, Box<dyn OutputFormatterStyleInterface>> = IndexMap::new(); + styles.insert( + "warning".to_string(), + Box::new(OutputFormatterStyle::new( + Some("black"), + Some("yellow"), + vec![], + )), + ); + + let mut formatter = HtmlOutputFormatter::new(styles); + + assert_eq!( + Some( + "text <span style=\"color:green;\">green</span> <span style=\"color:yellow;\">yellow</span> <span style=\"color:black;background-color:yellow;\">black w/ yellow bg</span>" + .to_string() + ), + formatter + .format(Some( + "text <info>green</info> <comment>yellow</comment> <warning>black w/ yellow bg</warning>" + )) + .unwrap() + ); +} diff --git a/crates/shirabe/tests/console/main.rs b/crates/shirabe/tests/console/main.rs new file mode 100644 index 0000000..17685a4 --- /dev/null +++ b/crates/shirabe/tests/console/main.rs @@ -0,0 +1 @@ +mod html_output_formatter_test; diff --git a/crates/shirabe/tests/default_config_test.rs b/crates/shirabe/tests/default_config_test.rs index 61e3a2d..032be0f 100644 --- a/crates/shirabe/tests/default_config_test.rs +++ b/crates/shirabe/tests/default_config_test.rs @@ -1 +1,10 @@ //! ref: composer/tests/Composer/Test/DefaultConfigTest.php + +use shirabe::config::Config; +use shirabe_php_shim::PhpMixed; + +#[test] +fn test_default_values_are_as_expected() { + let config = Config::new(true, None); + assert_eq!(config.get("disable-tls"), PhpMixed::Bool(false)); +} diff --git a/crates/shirabe/tests/filter/main.rs b/crates/shirabe/tests/filter/main.rs new file mode 100644 index 0000000..6bcb099 --- /dev/null +++ b/crates/shirabe/tests/filter/main.rs @@ -0,0 +1 @@ +mod platform_requirement_filter; diff --git a/crates/shirabe/tests/filter/platform_requirement_filter/ignore_all_platform_requirement_filter_test.rs b/crates/shirabe/tests/filter/platform_requirement_filter/ignore_all_platform_requirement_filter_test.rs index cd34d0e..cd01dce 100644 --- a/crates/shirabe/tests/filter/platform_requirement_filter/ignore_all_platform_requirement_filter_test.rs +++ b/crates/shirabe/tests/filter/platform_requirement_filter/ignore_all_platform_requirement_filter_test.rs @@ -1 +1,27 @@ //! ref: composer/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreAllPlatformRequirementFilterTest.php + +use shirabe::filter::platform_requirement_filter::{ + IgnoreAllPlatformRequirementFilter, PlatformRequirementFilterInterface, +}; + +#[test] +fn test_is_ignored() { + for (req, expect_ignored) in data_is_ignored() { + let platform_requirement_filter = IgnoreAllPlatformRequirementFilter; + + assert_eq!(expect_ignored, platform_requirement_filter.is_ignored(req)); + assert_eq!( + expect_ignored, + platform_requirement_filter.is_upper_bound_ignored(req) + ); + } +} + +fn data_is_ignored() -> Vec<(&'static str, bool)> { + vec![ + // 'php is ignored' + ("php", true), + // 'monolog/monolog is not ignored' + ("monolog/monolog", false), + ] +} diff --git a/crates/shirabe/tests/filter/platform_requirement_filter/ignore_nothing_platform_requirement_filter_test.rs b/crates/shirabe/tests/filter/platform_requirement_filter/ignore_nothing_platform_requirement_filter_test.rs index d7c23e7..5ca444c 100644 --- a/crates/shirabe/tests/filter/platform_requirement_filter/ignore_nothing_platform_requirement_filter_test.rs +++ b/crates/shirabe/tests/filter/platform_requirement_filter/ignore_nothing_platform_requirement_filter_test.rs @@ -1 +1,24 @@ //! ref: composer/tests/Composer/Test/Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilterTest.php + +use shirabe::filter::platform_requirement_filter::{ + IgnoreNothingPlatformRequirementFilter, PlatformRequirementFilterInterface, +}; + +#[test] +fn test_is_ignored() { + for req in data_is_ignored() { + let platform_requirement_filter = IgnoreNothingPlatformRequirementFilter; + + assert!(!platform_requirement_filter.is_ignored(req)); + assert!(!platform_requirement_filter.is_upper_bound_ignored(req)); + } +} + +fn data_is_ignored() -> Vec<&'static str> { + vec![ + // 'php is not ignored' + "php", + // 'monolog/monolog is not ignored' + "monolog/monolog", + ] +} diff --git a/crates/shirabe/tests/filter/platform_requirement_filter/mod.rs b/crates/shirabe/tests/filter/platform_requirement_filter/mod.rs new file mode 100644 index 0000000..1199c1c --- /dev/null +++ b/crates/shirabe/tests/filter/platform_requirement_filter/mod.rs @@ -0,0 +1,2 @@ +mod ignore_all_platform_requirement_filter_test; +mod ignore_nothing_platform_requirement_filter_test; diff --git a/crates/shirabe/tests/package/archiver/git_exclude_filter_test.rs b/crates/shirabe/tests/package/archiver/git_exclude_filter_test.rs index 63374c4..431cb4f 100644 --- a/crates/shirabe/tests/package/archiver/git_exclude_filter_test.rs +++ b/crates/shirabe/tests/package/archiver/git_exclude_filter_test.rs @@ -1 +1,34 @@ //! ref: composer/tests/Composer/Test/Package/Archiver/GitExcludeFilterTest.php + +use shirabe::package::archiver::git_exclude_filter::GitExcludeFilter; + +#[test] +#[ignore = "Preg::split panics on the `\\s+` pattern in the regex-crate-based shim"] +fn test_pattern_escape() { + for (ignore, expected) in provide_patterns() { + let filter = GitExcludeFilter::new("/".to_string()); + + assert_eq!(expected, filter.parse_git_attributes_line(ignore)); + } +} + +fn provide_patterns() -> Vec<(&'static str, Option<(String, bool, bool)>)> { + vec![ + ( + "app/config/parameters.yml export-ignore", + Some(( + r"{(?=[^\.])app/(?=[^\.])config/(?=[^\.])parameters\.yml(?=$|/)}".to_string(), + false, + false, + )), + ), + ( + "app/config/parameters.yml -export-ignore", + Some(( + r"{(?=[^\.])app/(?=[^\.])config/(?=[^\.])parameters\.yml(?=$|/)}".to_string(), + true, + false, + )), + ), + ] +} diff --git a/crates/shirabe/tests/package/archiver/mod.rs b/crates/shirabe/tests/package/archiver/mod.rs new file mode 100644 index 0000000..b77fb71 --- /dev/null +++ b/crates/shirabe/tests/package/archiver/mod.rs @@ -0,0 +1 @@ +mod git_exclude_filter_test; diff --git a/crates/shirabe/tests/package/main.rs b/crates/shirabe/tests/package/main.rs new file mode 100644 index 0000000..64b2cc7 --- /dev/null +++ b/crates/shirabe/tests/package/main.rs @@ -0,0 +1 @@ +mod archiver; diff --git a/crates/shirabe/tests/util/main.rs b/crates/shirabe/tests/util/main.rs new file mode 100644 index 0000000..1ce0dd7 --- /dev/null +++ b/crates/shirabe/tests/util/main.rs @@ -0,0 +1 @@ +mod platform_test; diff --git a/crates/shirabe/tests/util/platform_test.rs b/crates/shirabe/tests/util/platform_test.rs index 90ce6ad..3d00370 100644 --- a/crates/shirabe/tests/util/platform_test.rs +++ b/crates/shirabe/tests/util/platform_test.rs @@ -1 +1,31 @@ //! ref: composer/tests/Composer/Test/Util/PlatformTest.php + +use shirabe::util::platform::Platform; +use shirabe_php_shim::defined; + +#[test] +#[ignore = "Platform::expand_path does not read the env var set via put_env in this runtime"] +fn test_expand_path() { + Platform::put_env("TESTENV", "/home/test"); + assert_eq!("/home/test/myPath", Platform::expand_path("%TESTENV%/myPath")); + assert_eq!("/home/test/myPath", Platform::expand_path("$TESTENV/myPath")); + assert_eq!( + format!( + "{}/test", + Platform::get_env("HOME") + .or_else(|| Platform::get_env("USERPROFILE")) + .unwrap_or_default() + ), + Platform::expand_path("~/test") + ); +} + +#[test] +fn test_is_windows() { + // Compare 2 common tests for Windows to the built-in Windows test + assert_eq!( + std::path::MAIN_SEPARATOR == '\\', + Platform::is_windows() + ); + assert_eq!(defined("PHP_WINDOWS_VERSION_MAJOR"), Platform::is_windows()); +} |
