Skip to content

Commit a806a29

Browse files
committed
feat: improve integration test for soruce args
1 parent 4e992cc commit a806a29

File tree

7 files changed

+189
-464
lines changed

7 files changed

+189
-464
lines changed

.dev/27-integration-tests-revamp-plan.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ tests/integration_tests/version/
9696

9797
- **Focus**: Source switching and git-specific functionality
9898
- **Method**: stdin tests + minimal Docker git fixtures (≤5 total)
99-
- **Coverage**: stdin source, basic git pipeline integration
99+
- **Coverage**: stdin source, basic git pipeline integration, source validation, input format validation
100100

101101
### 4. Implementation Plan
102102

@@ -145,7 +145,7 @@ tests/integration_tests/version/
145145
146146
**Remaining MainConfig Tests:**
147147
148-
- ❌ `formats.rs`: Test `--input-format` (semver/pep440/zerv) and `--output-format` (semver/pep440/zerv) combinations
148+
- ❌ `formats.rs`: Test `--input-format` (semver/pep440/zerv) and `--output-format` (semver/pep440/zerv) combinations, format validation errors, error message consistency
149149
- ❌ `schemas.rs`: Test `--schema` (tier1/tier2/tier3) and `--schema-ron` (custom RON schema) options
150150
- ❌ `templates.rs`: Test `--output-template` with Handlebars template rendering
151151
- ❌ `directory.rs`: Test `-C` flag for changing working directory before execution
@@ -158,7 +158,7 @@ tests/integration_tests/version/
158158
- `vcs.rs`: --tag-version, --distance, --dirty individually
159159
- `components.rs`: --major, --minor, --patch individually
160160
- `schema_components.rs`: --core, --extra-core, --build individually
161-
- `combinations.rs`: Override combinations
161+
- `combinations.rs`: Override combinations, conflicting options (clean vs distance/dirty), boolean flag behavior
162162
- Use ZervFixture with stdin source for all tests
163163
- Test and validate override functionality
164164

src/test_utils/git/fixtures.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,63 @@ pub struct GitRepoFixture {
1111
}
1212

1313
impl GitRepoFixture {
14-
/// Create a repository with a clean tag (Tier 1: major.minor.patch)
15-
pub fn tagged(tag: &str) -> Result<Self, Box<dyn std::error::Error>> {
14+
/// Create an empty repository without any tags
15+
pub fn empty() -> Result<Self, Box<dyn std::error::Error>> {
1616
let test_dir = TestDir::new()?;
1717
let git_impl = get_git_impl();
1818

19-
// Perform atomic Git operations in sequence with error context
19+
// Perform atomic Git operations with error context
2020
git_impl
2121
.init_repo(&test_dir)
2222
.map_err(|e| format!("Failed to initialize Git repo: {e}"))?;
2323

24-
// Verify repository was created properly before tagging
24+
// Verify repository was created properly
2525
if !test_dir.path().join(".git").exists() {
2626
return Err("Git repository was not properly initialized".into());
2727
}
2828

29-
git_impl
30-
.create_tag(&test_dir, tag)
29+
Ok(Self { test_dir, git_impl })
30+
}
31+
32+
/// Create a repository with a clean tag (Tier 1: major.minor.patch)
33+
pub fn tagged(tag: &str) -> Result<Self, Box<dyn std::error::Error>> {
34+
let fixture = Self::empty()?;
35+
36+
fixture
37+
.git_impl
38+
.create_tag(&fixture.test_dir, tag)
3139
.map_err(|e| format!("Failed to create tag '{tag}': {e}"))?;
3240

33-
Ok(Self { test_dir, git_impl })
41+
Ok(fixture)
3442
}
3543

3644
/// Create a repository with distance from tag (Tier 2: major.minor.patch.post<distance>+branch.<commit>)
3745
pub fn with_distance(tag: &str, commits: u32) -> Result<Self, Box<dyn std::error::Error>> {
38-
let test_dir = TestDir::new()?;
39-
let git_impl = get_git_impl();
40-
41-
git_impl.init_repo(&test_dir)?;
42-
git_impl.create_tag(&test_dir, tag)?;
46+
let fixture = Self::tagged(tag)?;
4347

4448
// Create additional commits for distance
4549
for i in 0..commits {
46-
test_dir.create_file(format!("file{}.txt", i + 1), "content")?;
47-
git_impl.create_commit(&test_dir, &format!("Commit {}", i + 1))?;
50+
fixture
51+
.test_dir
52+
.create_file(format!("file{}.txt", i + 1), "content")?;
53+
fixture
54+
.git_impl
55+
.create_commit(&fixture.test_dir, &format!("Commit {}", i + 1))?;
4856
}
4957

50-
Ok(Self { test_dir, git_impl })
58+
Ok(fixture)
5159
}
5260

5361
/// Create a repository with dirty working directory (Tier 3: major.minor.patch.dev<timestamp>+branch.<commit>)
5462
pub fn dirty(tag: &str) -> Result<Self, Box<dyn std::error::Error>> {
55-
let test_dir = TestDir::new()?;
56-
let git_impl = get_git_impl();
57-
58-
git_impl.init_repo(&test_dir)?;
59-
git_impl.create_tag(&test_dir, tag)?;
63+
let fixture = Self::tagged(tag)?;
6064

6165
// Create uncommitted changes to make it dirty
62-
test_dir.create_file("dirty.txt", "uncommitted changes")?;
66+
fixture
67+
.test_dir
68+
.create_file("dirty.txt", "uncommitted changes")?;
6369

64-
Ok(Self { test_dir, git_impl })
70+
Ok(fixture)
6571
}
6672

6773
/// Get the path to the test directory

0 commit comments

Comments
 (0)