aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-24 00:47:20 +0900
committernsfisis <nsfisis@gmail.com>2026-06-24 00:47:53 +0900
commit340164c64e90d44b1bdf620b514166db1f76cc98 (patch)
tree86195fe5ff8582b64e0324e9f40619e36c04948f /crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs
parent8fe3390d064303b86133a1d2983144a4818a7121 (diff)
downloadphp-shirabe-340164c64e90d44b1bdf620b514166db1f76cc98.tar.gz
php-shirabe-340164c64e90d44b1bdf620b514166db1f76cc98.tar.zst
php-shirabe-340164c64e90d44b1bdf620b514166db1f76cc98.zip
test: port more unimplemented tests
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs')
-rw-r--r--crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs236
1 files changed, 213 insertions, 23 deletions
diff --git a/crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs b/crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs
index 48f0fc5..aed0dc3 100644
--- a/crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs
+++ b/crates/shirabe/tests/package/archiver/archivable_files_finder_test.rs
@@ -1,45 +1,235 @@
//! ref: composer/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php
-/// Builds a temp directory tree of fixture files under a unique tmp dir; the Filesystem and
-/// getUniqueTmpDirectory infrastructure is not ported.
-#[allow(dead_code)]
-fn set_up() -> String {
- todo!()
-}
+use shirabe::package::archiver::ArchivableFilesFinder;
+use shirabe::util::Filesystem;
+use shirabe_external_packages::composer::pcre::Preg;
+use shirabe_php_shim::{dirname, file_put_contents, preg_quote};
+use tempfile::TempDir;
-#[allow(dead_code)]
-fn tear_down(_sources: &str) {
- // Removes the temp directory tree created in set_up.
- todo!()
+struct SetUp {
+ _sources_dir: TempDir,
+ sources: String,
+ fs: Filesystem,
}
-#[allow(dead_code)]
-struct TearDown {
- sources: String,
+fn set_up() -> SetUp {
+ let mut fs = Filesystem::new(None);
+
+ let sources_dir = TempDir::new().unwrap();
+ let sources = fs.normalize_path(&sources_dir.path().canonicalize().unwrap().to_string_lossy());
+
+ let file_tree = [
+ ".foo",
+ "A/prefixA.foo",
+ "A/prefixB.foo",
+ "A/prefixC.foo",
+ "A/prefixD.foo",
+ "A/prefixE.foo",
+ "A/prefixF.foo",
+ "B/sub/prefixA.foo",
+ "B/sub/prefixB.foo",
+ "B/sub/prefixC.foo",
+ "B/sub/prefixD.foo",
+ "B/sub/prefixE.foo",
+ "B/sub/prefixF.foo",
+ "C/prefixA.foo",
+ "C/prefixB.foo",
+ "C/prefixC.foo",
+ "C/prefixD.foo",
+ "C/prefixE.foo",
+ "C/prefixF.foo",
+ "D/prefixA",
+ "D/prefixB",
+ "D/prefixC",
+ "D/prefixD",
+ "D/prefixE",
+ "D/prefixF",
+ "E/subtestA.foo",
+ "F/subtestA.foo",
+ "G/subtestA.foo",
+ "H/subtestA.foo",
+ "I/J/subtestA.foo",
+ "K/dirJ/subtestA.foo",
+ "toplevelA.foo",
+ "toplevelB.foo",
+ "prefixA.foo",
+ "prefixB.foo",
+ "prefixC.foo",
+ "prefixD.foo",
+ "prefixE.foo",
+ "prefixF.foo",
+ "parameters.yml",
+ "parameters.yml.dist",
+ "!important!.txt",
+ "!important_too!.txt",
+ "#weirdfile",
+ ];
+
+ for relative_path in file_tree {
+ let path = format!("{}/{}", sources, relative_path);
+ fs.ensure_directory_exists(&dirname(&path)).unwrap();
+ file_put_contents(&path, b"");
+ }
+
+ SetUp {
+ _sources_dir: sources_dir,
+ sources,
+ fs,
+ }
}
-impl Drop for TearDown {
- fn drop(&mut self) {
- tear_down(&self.sources);
+fn get_archivable_files(set_up: &SetUp, finder: ArchivableFilesFinder) -> Vec<String> {
+ let mut files: Vec<String> = vec![];
+ for file in finder {
+ if !file.is_dir() {
+ let real_path = file.canonicalize().unwrap();
+ files.push(Preg::replace(
+ &format!("#^{}#", preg_quote(&set_up.sources, Some('#'))),
+ "",
+ &set_up.fs.normalize_path(&real_path.to_string_lossy()),
+ ));
+ }
}
+
+ files.sort();
+
+ files
+}
+
+fn assert_archivable_files(set_up: &SetUp, finder: ArchivableFilesFinder, expected_files: &[&str]) {
+ let actual_files = get_archivable_files(set_up, finder);
+
+ let expected_files: Vec<String> = expected_files.iter().map(|s| s.to_string()).collect();
+ assert_eq!(expected_files, actual_files);
}
-// These set up a temp directory tree (including a git repo) and assert the files the finder
-// selects with manual/git/skip excludes; the git-backed fixture setup is not ported.
-#[ignore = "setUp needs TestCase::getUniqueTmpDirectory to build the on-disk fixture tree; not ported"]
+// The manual exclude patterns (e.g. `.*`, `prefixC.*`) compile, via ComposerExcludeFilter, to
+// look-ahead regexes like `(?=[^\.])...(?=$|/)`, which the regex crate cannot compile.
+#[ignore = "ComposerExcludeFilter builds look-ahead regexes the regex crate does not support"]
#[test]
fn test_manual_excludes() {
- todo!()
+ let set_up = set_up();
+
+ let excludes = vec![
+ "prefixB.foo".to_string(),
+ "!/prefixB.foo".to_string(),
+ "/prefixA.foo".to_string(),
+ "prefixC.*".to_string(),
+ "!*/*/*/prefixC.foo".to_string(),
+ ".*".to_string(),
+ ];
+
+ let finder = ArchivableFilesFinder::new(&set_up.sources, excludes, false).unwrap();
+
+ assert_archivable_files(
+ &set_up,
+ finder,
+ &[
+ "/!important!.txt",
+ "/!important_too!.txt",
+ "/#weirdfile",
+ "/A/prefixA.foo",
+ "/A/prefixD.foo",
+ "/A/prefixE.foo",
+ "/A/prefixF.foo",
+ "/B/sub/prefixA.foo",
+ "/B/sub/prefixC.foo",
+ "/B/sub/prefixD.foo",
+ "/B/sub/prefixE.foo",
+ "/B/sub/prefixF.foo",
+ "/C/prefixA.foo",
+ "/C/prefixD.foo",
+ "/C/prefixE.foo",
+ "/C/prefixF.foo",
+ "/D/prefixA",
+ "/D/prefixB",
+ "/D/prefixC",
+ "/D/prefixD",
+ "/D/prefixE",
+ "/D/prefixF",
+ "/E/subtestA.foo",
+ "/F/subtestA.foo",
+ "/G/subtestA.foo",
+ "/H/subtestA.foo",
+ "/I/J/subtestA.foo",
+ "/K/dirJ/subtestA.foo",
+ "/parameters.yml",
+ "/parameters.yml.dist",
+ "/prefixB.foo",
+ "/prefixD.foo",
+ "/prefixE.foo",
+ "/prefixF.foo",
+ "/toplevelA.foo",
+ "/toplevelB.foo",
+ ],
+ );
}
-#[ignore = "setUp needs TestCase::getUniqueTmpDirectory plus skipIfNotExecutable/Process::fromShellCommandline/PharData/RecursiveIteratorIterator; none ported"]
+// getArchivedFiles drives a git pipeline (Process::fromShellCommandline) and reads the produced
+// zip back through PharData + RecursiveIteratorIterator; neither the process helper nor the zip
+// archive reader is ported, so this case cannot run.
+#[ignore = "getArchivedFiles needs a git process pipeline plus PharData/RecursiveIteratorIterator zip reading; not ported"]
#[test]
fn test_git_excludes() {
todo!()
}
-#[ignore = "setUp needs TestCase::getUniqueTmpDirectory to build the on-disk fixture tree; not ported"]
#[test]
fn test_skip_excludes() {
- todo!()
+ let set_up = set_up();
+
+ let excludes = vec!["prefixB.foo".to_string()];
+
+ let finder = ArchivableFilesFinder::new(&set_up.sources, excludes, true).unwrap();
+
+ assert_archivable_files(
+ &set_up,
+ finder,
+ &[
+ "/!important!.txt",
+ "/!important_too!.txt",
+ "/#weirdfile",
+ "/.foo",
+ "/A/prefixA.foo",
+ "/A/prefixB.foo",
+ "/A/prefixC.foo",
+ "/A/prefixD.foo",
+ "/A/prefixE.foo",
+ "/A/prefixF.foo",
+ "/B/sub/prefixA.foo",
+ "/B/sub/prefixB.foo",
+ "/B/sub/prefixC.foo",
+ "/B/sub/prefixD.foo",
+ "/B/sub/prefixE.foo",
+ "/B/sub/prefixF.foo",
+ "/C/prefixA.foo",
+ "/C/prefixB.foo",
+ "/C/prefixC.foo",
+ "/C/prefixD.foo",
+ "/C/prefixE.foo",
+ "/C/prefixF.foo",
+ "/D/prefixA",
+ "/D/prefixB",
+ "/D/prefixC",
+ "/D/prefixD",
+ "/D/prefixE",
+ "/D/prefixF",
+ "/E/subtestA.foo",
+ "/F/subtestA.foo",
+ "/G/subtestA.foo",
+ "/H/subtestA.foo",
+ "/I/J/subtestA.foo",
+ "/K/dirJ/subtestA.foo",
+ "/parameters.yml",
+ "/parameters.yml.dist",
+ "/prefixA.foo",
+ "/prefixB.foo",
+ "/prefixC.foo",
+ "/prefixD.foo",
+ "/prefixE.foo",
+ "/prefixF.foo",
+ "/toplevelA.foo",
+ "/toplevelB.foo",
+ ],
+ );
}