Skip to content

Commit 1c92055

Browse files
dfranklandclaude
andcommitted
test(bundle): move the expand_globs tests to bundle/tests/
They only exercise `FileSetBuilder::expand_globs`, which is public, so nothing about them needs to sit inside the module. As an integration test they exercise the crate the way its callers do and cannot quietly come to depend on a private detail. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 12c3c0a commit 1c92055

2 files changed

Lines changed: 79 additions & 79 deletions

File tree

‎bundle/src/files.rs‎

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -520,82 +520,3 @@ impl BundledFile {
520520
.unwrap_or(&self.original_path)
521521
}
522522
}
523-
524-
/// What every argument taking a path shares, so these pin the behaviour once rather than
525-
/// once per caller. Deliberately free of any language server or test runner: expansion is
526-
/// the half that can be proven anywhere, and the `swift test` integration tests that cover
527-
/// the other half need a Swift toolchain to say anything at all.
528-
#[cfg(test)]
529-
mod expand_globs_tests {
530-
use super::*;
531-
532-
fn repo_with<const N: usize>(files: [&str; N]) -> (tempfile::TempDir, PathBuf) {
533-
let dir = tempfile::tempdir().unwrap();
534-
let root = dir.path().canonicalize().unwrap();
535-
for file in files {
536-
let path = root.join(file);
537-
if let Some(parent) = path.parent() {
538-
std::fs::create_dir_all(parent).unwrap();
539-
}
540-
std::fs::write(path, "").unwrap();
541-
}
542-
(dir, root)
543-
}
544-
545-
#[test]
546-
fn a_file_two_globs_both_match_is_returned_once() {
547-
let (_dir, root) = repo_with(["junit.xml", "junit-swift-testing.xml"]);
548-
549-
let files = FileSetBuilder::expand_globs(
550-
root.to_string_lossy(),
551-
&[String::from("junit*.xml"), String::from("junit.xml")],
552-
)
553-
.unwrap();
554-
555-
// The second pattern owns nothing: the first already claimed the file it names.
556-
assert_eq!(
557-
files,
558-
vec![root.join("junit-swift-testing.xml"), root.join("junit.xml")]
559-
);
560-
}
561-
562-
/// The dedupe is on the canonical path rather than the matched one, which is the only
563-
/// way a link and its target are recognised as one file.
564-
#[cfg(unix)]
565-
#[test]
566-
fn a_symlink_to_an_already_matched_file_is_not_returned_again() {
567-
let (_dir, root) = repo_with(["real.xml"]);
568-
std::os::unix::fs::symlink(root.join("real.xml"), root.join("link.xml")).unwrap();
569-
570-
let files =
571-
FileSetBuilder::expand_globs(root.to_string_lossy(), &[String::from("*.xml")]).unwrap();
572-
573-
assert_eq!(files, vec![root.join("real.xml")]);
574-
}
575-
576-
/// A relative pattern is resolved against the repo root, not the working directory, so
577-
/// where the uploader was invoked from does not change which files it finds.
578-
#[test]
579-
fn relative_globs_resolve_against_the_repo_root() {
580-
let (_dir, root) = repo_with(["reports/junit.xml"]);
581-
582-
let files =
583-
FileSetBuilder::expand_globs(root.to_string_lossy(), &[String::from("reports/*.xml")])
584-
.unwrap();
585-
586-
assert_eq!(files, vec![root.join("reports/junit.xml")]);
587-
}
588-
589-
#[test]
590-
fn a_glob_matching_nothing_owns_nothing() {
591-
let (_dir, root) = repo_with(["junit.xml"]);
592-
593-
let files = FileSetBuilder::expand_globs(
594-
root.to_string_lossy(),
595-
&[String::from("nothing-here/*.xml")],
596-
)
597-
.unwrap();
598-
599-
assert!(files.is_empty(), "got {files:?}");
600-
}
601-
}

‎bundle/tests/expand_globs_test.rs‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//! What every argument taking a path shares, pinned once rather than once per caller.
2+
//!
3+
//! Deliberately free of any language server or test runner: expansion is the half that can be
4+
//! proven anywhere, and the `swift test --xunit-output` integration tests that cover the other
5+
//! half need a Swift toolchain to say anything at all.
6+
7+
use std::path::PathBuf;
8+
9+
use bundle::FileSetBuilder;
10+
11+
fn repo_with<const N: usize>(files: [&str; N]) -> (tempfile::TempDir, PathBuf) {
12+
let dir = tempfile::tempdir().unwrap();
13+
let root = dir.path().canonicalize().unwrap();
14+
for file in files {
15+
let path = root.join(file);
16+
if let Some(parent) = path.parent() {
17+
std::fs::create_dir_all(parent).unwrap();
18+
}
19+
std::fs::write(path, "").unwrap();
20+
}
21+
(dir, root)
22+
}
23+
24+
#[test]
25+
fn a_file_two_globs_both_match_is_returned_once() {
26+
let (_dir, root) = repo_with(["junit.xml", "junit-swift-testing.xml"]);
27+
28+
let files = FileSetBuilder::expand_globs(
29+
root.to_string_lossy(),
30+
&[String::from("junit*.xml"), String::from("junit.xml")],
31+
)
32+
.unwrap();
33+
34+
// The second pattern owns nothing: the first already claimed the file it names.
35+
assert_eq!(
36+
files,
37+
vec![root.join("junit-swift-testing.xml"), root.join("junit.xml")]
38+
);
39+
}
40+
41+
/// The dedupe is on the canonical path rather than the matched one, which is the only way a
42+
/// link and its target are recognised as one file.
43+
#[cfg(unix)]
44+
#[test]
45+
fn a_symlink_to_an_already_matched_file_is_not_returned_again() {
46+
let (_dir, root) = repo_with(["real.xml"]);
47+
std::os::unix::fs::symlink(root.join("real.xml"), root.join("link.xml")).unwrap();
48+
49+
let files =
50+
FileSetBuilder::expand_globs(root.to_string_lossy(), &[String::from("*.xml")]).unwrap();
51+
52+
assert_eq!(files, vec![root.join("real.xml")]);
53+
}
54+
55+
/// A relative pattern is resolved against the repo root, not the working directory, so where
56+
/// the uploader was invoked from does not change which files it finds.
57+
#[test]
58+
fn relative_globs_resolve_against_the_repo_root() {
59+
let (_dir, root) = repo_with(["reports/junit.xml"]);
60+
61+
let files =
62+
FileSetBuilder::expand_globs(root.to_string_lossy(), &[String::from("reports/*.xml")])
63+
.unwrap();
64+
65+
assert_eq!(files, vec![root.join("reports/junit.xml")]);
66+
}
67+
68+
#[test]
69+
fn a_glob_matching_nothing_owns_nothing() {
70+
let (_dir, root) = repo_with(["junit.xml"]);
71+
72+
let files = FileSetBuilder::expand_globs(
73+
root.to_string_lossy(),
74+
&[String::from("nothing-here/*.xml")],
75+
)
76+
.unwrap();
77+
78+
assert!(files.is_empty(), "got {files:?}");
79+
}

0 commit comments

Comments
 (0)