Skip to content

Commit 7e51bca

Browse files
committed
test: add test for directory.rs
1 parent f26c4dd commit 7e51bca

File tree

3 files changed

+121
-4
lines changed

3 files changed

+121
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,17 @@ tests/integration_tests/version/
142142
- ✅ Enhanced `ZervFixture.with_vcs_data()` to accept `Option` types for better flexibility
143143
- ✅ Implemented `formats.rs`: Comprehensive format conversion tests (30 tests)
144144
- ✅ Implemented `schemas.rs`: Comprehensive schema tests (31 tests)
145-
- **Result**: 82 tests passing (100% success rate) - 7 source tests + 30 format tests + 31 schema tests + 14 other tests
146-
- **Performance**: Tests run in <1.3 seconds without Docker
145+
- ✅ Implemented `templates.rs`: Comprehensive template tests covering all helpers and edge cases (62 tests)
146+
- ✅ Implemented `directory.rs`: Directory flag tests with Git integration and error handling (4 tests)
147+
- **Result**: 172 tests passing (100% success rate) - 7 source tests + 30 format tests + 31 schema tests + 62 template tests + 4 directory tests + 38 other tests
148+
- **Performance**: Tests run in <0.5 seconds without Docker
147149
148150
**Remaining MainConfig Tests:**
149151
150152
- ✅ `formats.rs`: Test `--input-format` (semver/pep440/auto) and `--output-format` (semver/pep440/zerv) combinations, format validation errors, error message consistency (✅ PASSED - 30 tests)
151153
- ✅ `schemas.rs`: Test `--schema` (zerv-standard/zerv-calver) and `--schema-ron` (custom RON schema) options (✅ PASSED - 31 tests)
152-
- `templates.rs`: Test `--output-template` with Handlebars template rendering
153-
- `directory.rs`: Test `-C` flag for changing working directory before execution
154+
- `templates.rs`: Test `--output-template` with Handlebars template rendering, all helpers (sanitize, hash, prefix, timestamp, math), complex scenarios, edge cases (✅ PASSED - 62 tests)
155+
- `directory.rs`: Test `-C` flag for changing working directory before execution (✅ PASSED - 4 tests: 2 Git integration + 2 error handling)
154156
- ❌ `combinations.rs`: Test MainConfig option combinations (format + schema, template + format, etc.)
155157
156158
#### Phase 3: Implement Override Tests (`overrides/`)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
use zerv::test_utils::{
2+
GitRepoFixture,
3+
TestDir,
4+
should_run_docker_tests,
5+
};
6+
7+
use crate::util::TestCommand;
8+
9+
mod directory_git_integration {
10+
use super::*;
11+
12+
#[test]
13+
fn test_directory_flag_with_subdirectory() {
14+
if !should_run_docker_tests() {
15+
return;
16+
}
17+
18+
let git_repo =
19+
GitRepoFixture::tagged("v1.0.0").expect("Failed to create tagged Git repository");
20+
21+
let parent_dir = git_repo
22+
.path()
23+
.parent()
24+
.expect("Git repo should have parent directory");
25+
26+
let output = TestCommand::new()
27+
.current_dir(parent_dir)
28+
.args_from_str(format!(
29+
"version -C {} --source git --output-format semver",
30+
git_repo.path().file_name().unwrap().to_string_lossy()
31+
))
32+
.assert_success();
33+
34+
assert_eq!(
35+
output.stdout().trim(),
36+
"1.0.0",
37+
"Should detect version from Git repo in subdirectory using -C flag"
38+
);
39+
}
40+
41+
#[test]
42+
fn test_directory_flag_relative_vs_absolute() {
43+
if !should_run_docker_tests() {
44+
return;
45+
}
46+
47+
let git_repo =
48+
GitRepoFixture::tagged("v1.0.0").expect("Failed to create tagged Git repository");
49+
50+
let relative_output = TestCommand::new()
51+
.current_dir(git_repo.path().parent().unwrap())
52+
.args_from_str(format!(
53+
"version -C {} --source git --output-format semver",
54+
git_repo.path().file_name().unwrap().to_string_lossy()
55+
))
56+
.assert_success();
57+
58+
let absolute_output = TestCommand::new()
59+
.args_from_str(format!(
60+
"version -C {} --source git --output-format semver",
61+
git_repo.path().display()
62+
))
63+
.assert_success();
64+
65+
assert_eq!(
66+
relative_output.stdout().trim(),
67+
"1.0.0",
68+
"Relative path should work"
69+
);
70+
assert_eq!(
71+
absolute_output.stdout().trim(),
72+
"1.0.0",
73+
"Absolute path should work"
74+
);
75+
assert_eq!(
76+
relative_output.stdout(),
77+
absolute_output.stdout(),
78+
"Relative and absolute paths should produce identical output"
79+
);
80+
}
81+
}
82+
83+
mod directory_error_handling {
84+
use super::*;
85+
86+
#[test]
87+
fn test_directory_flag_nonexistent_path() {
88+
let output = TestCommand::new()
89+
.args_from_str("version -C /nonexistent/path/to/directory")
90+
.assert_failure();
91+
92+
let stderr = output.stderr();
93+
assert!(
94+
stderr.contains("Error") && stderr.contains("VCS not found"),
95+
"Should show VCS not found error when directory doesn't exist. Got: {stderr}"
96+
);
97+
}
98+
99+
#[test]
100+
fn test_directory_flag_exists_but_not_git() {
101+
let test_dir = TestDir::new().expect("Failed to create test directory");
102+
103+
let output = TestCommand::new()
104+
.args_from_str(format!("version -C {}", test_dir.path().display()))
105+
.assert_failure();
106+
107+
let stderr = output.stderr();
108+
assert_eq!(
109+
stderr.trim(),
110+
"Error: VCS not found: Not in a git repository (--source git)",
111+
"Should show proper error when directory exists but is not a git repo"
112+
);
113+
}
114+
}

tests/integration_tests/version/main/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod directory;
12
pub mod formats;
23
pub mod schemas;
34
pub mod sources;

0 commit comments

Comments
 (0)