diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-20 05:32:36 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-20 05:32:36 +0900 |
| commit | b151ceaa798a7d2e9b55ffbc4e4b10ea8f0a59a8 (patch) | |
| tree | 1ca5e068027a9bd2a478f2b13c655c31537e2b54 /crates | |
| parent | 6a2040e9c1b200530269d65e5e57f897a4f95584 (diff) | |
| download | php-shirabe-b151ceaa798a7d2e9b55ffbc4e4b10ea8f0a59a8.tar.gz php-shirabe-b151ceaa798a7d2e9b55ffbc4e4b10ea8f0a59a8.tar.zst php-shirabe-b151ceaa798a7d2e9b55ffbc4e4b10ea8f0a59a8.zip | |
test(path-repository): un-ignore test_url_remains_relative
The PHP test implicitly requires the process cwd to be an ancestor of
the Fixtures dir (phpunit runs inside the composer checkout); cargo
runs tests from the crate manifest dir, which is not. Replicate the
phpunit precondition with a drop-restoring CwdGuard chdir'ing to the
__DIR__ equivalent, and serialize it (together with the only other
cwd-mutating test in the repository binary,
test_repository_writes_installed_php) via #[serial] so the
process-global cwd cannot race.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe/tests/repository/filesystem_repository_test.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/tests/repository/path_repository_test.rs | 30 |
2 files changed, 33 insertions, 1 deletions
diff --git a/crates/shirabe/tests/repository/filesystem_repository_test.rs b/crates/shirabe/tests/repository/filesystem_repository_test.rs index 6e7370dc..b0d18c68 100644 --- a/crates/shirabe/tests/repository/filesystem_repository_test.rs +++ b/crates/shirabe/tests/repository/filesystem_repository_test.rs @@ -2,6 +2,7 @@ use crate::test_case::{get_alias_package, get_package}; use indexmap::IndexMap; +use serial_test::serial; use shirabe::dependency_resolver::operation::OperationInterface; use shirabe::installed_versions::InstalledVersions; use shirabe::installer::{InstallationManagerInterface, InstallerInterface}; @@ -215,6 +216,9 @@ fn configure_links( } #[test] +// Serialized because CwdGuard changes the process-global cwd, which would race with the +// cwd-sensitive path_repository_test::test_url_remains_relative in this binary. +#[serial] fn test_repository_writes_installed_php() { let guard = CwdGuard::new(); let dir = guard.path(); diff --git a/crates/shirabe/tests/repository/path_repository_test.rs b/crates/shirabe/tests/repository/path_repository_test.rs index 1cd034d2..24bf64d5 100644 --- a/crates/shirabe/tests/repository/path_repository_test.rs +++ b/crates/shirabe/tests/repository/path_repository_test.rs @@ -2,6 +2,7 @@ use crate::test_case::get_package; use indexmap::IndexMap; +use serial_test::serial; use shirabe::config::Config; use shirabe::io::{IOInterface, NullIO}; use shirabe::repository::PathRepository; @@ -166,10 +167,37 @@ fn test_load_package_with_explicit_versions() { assert_eq!(expected, versions); } +/// Restores the previous cwd on drop so a panicking assertion cannot leak the changed cwd into +/// other tests. +struct CwdGuard { + prev_cwd: std::path::PathBuf, +} + +impl CwdGuard { + fn new(dir: &str) -> Self { + let prev_cwd = std::env::current_dir().unwrap(); + std::env::set_current_dir(dir).unwrap(); + Self { prev_cwd } + } +} + +impl Drop for CwdGuard { + fn drop(&mut self) { + let _ = std::env::set_current_dir(&self.prev_cwd); + } +} + /// Verify relative repository URLs remain relative, see #4439 -#[ignore = "relies on the process cwd being the test's __DIR__ (the Repository fixtures dir) so the computed relative url resolves; under cargo the cwd is the crate manifest dir, so the relative url does not point at the fixture and getPackages errors"] #[test] +#[serial] fn test_url_remains_relative() { + // PHP runs under phpunit with the process cwd inside the composer checkout, an ancestor of + // __DIR__, so stripping the cwd prefix yields a valid relative path; cargo runs tests from the + // crate manifest dir, which is not an ancestor of the fixtures, so replicate the phpunit + // precondition by chdir'ing to the __DIR__ equivalent for the duration of the test. #[serial] + // keeps other cwd-touching tests in this binary from interleaving. + let _cwd_guard = CwdGuard::new(&fixtures_dir().replace("/Fixtures", "")); + // realpath() does not fully expand the paths // PHP Bug https://bugs.php.net/bug.php?id=72642 let repository_url = [ |
