Skip to content

Commit d4738bb

Browse files
committed
test: move tests
1 parent 47865d6 commit d4738bb

File tree

5 files changed

+355
-192
lines changed

5 files changed

+355
-192
lines changed

src/cli/flow/args/flow_specific.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,57 @@ impl Default for FlowSpecificConfig {
3636
}
3737
}
3838
}
39+
40+
#[cfg(test)]
41+
mod tests {
42+
use super::*;
43+
44+
#[test]
45+
fn test_flow_specific_config_default() {
46+
let config = FlowSpecificConfig::default();
47+
assert_eq!(config.branch_rules, None);
48+
assert!(!config.with_pre_release);
49+
assert!(!config.base_only);
50+
assert_eq!(config.post_mode, post_modes::TAG);
51+
}
52+
53+
#[test]
54+
fn test_flow_specific_config_with_pre_release_true() {
55+
let config = FlowSpecificConfig {
56+
with_pre_release: true,
57+
base_only: false,
58+
..Default::default()
59+
};
60+
assert!(config.with_pre_release);
61+
assert!(!config.base_only);
62+
}
63+
64+
#[test]
65+
fn test_flow_specific_config_base_only_true() {
66+
let config = FlowSpecificConfig {
67+
with_pre_release: false,
68+
base_only: true,
69+
..Default::default()
70+
};
71+
assert!(!config.with_pre_release);
72+
assert!(config.base_only);
73+
}
74+
75+
#[test]
76+
fn test_flow_specific_config_post_mode_tag() {
77+
let config = FlowSpecificConfig {
78+
post_mode: post_modes::TAG.to_string(),
79+
..Default::default()
80+
};
81+
assert_eq!(config.post_mode, post_modes::TAG);
82+
}
83+
84+
#[test]
85+
fn test_flow_specific_config_post_mode_commit() {
86+
let config = FlowSpecificConfig {
87+
post_mode: post_modes::COMMIT.to_string(),
88+
..Default::default()
89+
};
90+
assert_eq!(config.post_mode, post_modes::COMMIT);
91+
}
92+
}

src/cli/flow/args/main.rs

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
use clap::Parser;
2+
3+
use super::{
4+
FlowSpecificConfig,
5+
OverridesConfig,
6+
};
7+
use crate::cli::common::args::{
8+
InputConfig,
9+
OutputConfig,
10+
Validation as CommonValidation,
11+
};
12+
use crate::error::ZervError;
13+
14+
/// Generate version with intelligent pre-release management based on Git branch patterns
15+
#[derive(Parser)]
16+
#[command(
17+
about = "Generate version with intelligent pre-release management based on Git branch patterns"
18+
)]
19+
#[command(
20+
long_about = "Generate version strings with automatic pre-release detection based on Git branch patterns.
21+
This command acts as an intelligent wrapper around 'zerv version' that automatically determines
22+
pre-release information from the current Git branch using configurable pattern matching.
23+
24+
INPUT/OUTPUT OPTIONS:
25+
-s, --source <TYPE> Input source: git, stdin
26+
-f, --input-format <FMT> Input format: auto, semver, pep440
27+
-o, --output-format <FMT> Output format: semver, pep440, zerv
28+
-t, --output-template <TPL> Custom output template (Handlebars)
29+
-p, --output-prefix <PFX> Add prefix to version output
30+
31+
BRANCH PATTERN DETECTION:
32+
--branch-rules <RON> Custom branch pattern rules in RON format
33+
Default: develop -> alpha, release/* -> rc
34+
35+
OUTPUT MODES:
36+
--with-pre-release Show full version including pre-release (default)
37+
--base-only Show only base version without pre-release
38+
39+
POST DISTANCE MODES:
40+
--post-mode <MODE> Post calculation: tag (default), commit
41+
42+
OVERRIDES:
43+
--tag-version <TAG> Override detected tag version
44+
--distance <NUM> Override distance from tag
45+
--dirty Override dirty state to true
46+
--no-dirty Override dirty state to false
47+
--clean Force clean state (distance=0, dirty=false)
48+
--current-branch <NAME> Override branch name for pattern matching
49+
--commit-hash <HASH> Override commit hash
50+
51+
EXAMPLES:
52+
# Basic flow version with automatic pre-release detection
53+
zerv flow
54+
55+
# Custom branch rules (RON format)
56+
zerv flow --branch-rules \"[(branch_pattern: \"feature/*\", pre_release: \"beta\", number: 2)]\"
57+
58+
# Different output formats
59+
zerv flow --output-format pep440
60+
zerv flow --output-format zerv
61+
zerv flow --output-prefix v
62+
63+
# Show base version only
64+
zerv flow --base-only
65+
66+
# Override branch for testing
67+
zerv flow --current-branch release/v1.2.0
68+
69+
# Force clean release state
70+
zerv flow --clean
71+
72+
# Use in different directory
73+
zerv flow -C /path/to/repo"
74+
)]
75+
#[derive(Debug, Default)]
76+
pub struct FlowArgs {
77+
#[command(flatten)]
78+
pub input: InputConfig,
79+
80+
#[command(flatten)]
81+
pub output: OutputConfig,
82+
83+
#[command(flatten)]
84+
pub flow_specific: FlowSpecificConfig,
85+
86+
#[command(flatten)]
87+
pub overrides: OverridesConfig,
88+
}
89+
90+
impl FlowArgs {
91+
/// Validate arguments and return early errors
92+
/// This provides early validation before flow processing
93+
/// Note: source and format validation is handled by clap's value parser
94+
pub fn validate(&mut self) -> Result<(), ZervError> {
95+
// Use shared validation for input/output
96+
CommonValidation::validate_io(&self.input, &self.output)?;
97+
98+
// Validate flow-specific modules
99+
use super::Validation;
100+
Validation::validate_flow_specific(&self.flow_specific)?;
101+
Validation::validate_overrides(&self.overrides)?;
102+
Validation::validate_branch_rules(&self.flow_specific.branch_rules)?;
103+
104+
Ok(())
105+
}
106+
107+
/// Get the dirty override state (None = use VCS, Some(bool) = override)
108+
pub fn dirty_override(&self) -> Option<bool> {
109+
self.overrides.dirty_override()
110+
}
111+
}
112+
113+
#[cfg(test)]
114+
mod tests {
115+
use super::*;
116+
use crate::cli::common::args::{
117+
InputConfig,
118+
OutputConfig,
119+
};
120+
121+
#[test]
122+
fn test_flow_args_default() {
123+
let args = FlowArgs::default();
124+
assert_eq!(args.input.source, "git");
125+
assert_eq!(args.output.output_format, "semver");
126+
assert!(!args.flow_specific.with_pre_release);
127+
assert!(!args.flow_specific.base_only);
128+
assert_eq!(args.flow_specific.post_mode, "tag");
129+
assert_eq!(args.dirty_override(), None);
130+
}
131+
132+
#[test]
133+
fn test_flow_args_validation_success() {
134+
let mut args = FlowArgs::default();
135+
// Should validate successfully with defaults
136+
assert!(args.validate().is_ok());
137+
}
138+
139+
#[test]
140+
fn test_flow_args_dirty_override_integration() {
141+
let args = FlowArgs {
142+
overrides: OverridesConfig {
143+
dirty: true,
144+
no_dirty: false,
145+
..Default::default()
146+
},
147+
..FlowArgs::default()
148+
};
149+
assert_eq!(args.dirty_override(), Some(true));
150+
151+
let args = FlowArgs {
152+
overrides: OverridesConfig {
153+
dirty: false,
154+
no_dirty: true,
155+
..Default::default()
156+
},
157+
..FlowArgs::default()
158+
};
159+
assert_eq!(args.dirty_override(), Some(false));
160+
}
161+
162+
#[test]
163+
fn test_flow_args_with_input_output() {
164+
let mut args = FlowArgs {
165+
input: InputConfig {
166+
source: "git".to_string(),
167+
input_format: "auto".to_string(),
168+
directory: Some("/test/path".to_string()),
169+
},
170+
output: OutputConfig {
171+
output_format: "zerv".to_string(),
172+
output_prefix: Some("v".to_string()),
173+
output_template: None,
174+
},
175+
..FlowArgs::default()
176+
};
177+
assert_eq!(args.input.source, "git");
178+
assert_eq!(args.output.output_format, "zerv");
179+
assert_eq!(args.output.output_prefix, Some("v".to_string()));
180+
assert!(args.validate().is_ok());
181+
}
182+
}

src/cli/flow/args/mod.rs

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,9 @@
11
pub mod flow_specific;
2+
pub mod main;
23
pub mod overrides;
34
pub mod validation;
45

5-
use clap::Parser;
66
pub use flow_specific::FlowSpecificConfig;
7+
pub use main::FlowArgs;
78
pub use overrides::OverridesConfig;
89
pub use validation::Validation;
9-
10-
use crate::cli::common::args::{
11-
InputConfig,
12-
OutputConfig,
13-
Validation as CommonValidation,
14-
};
15-
16-
/// Generate version with intelligent pre-release management based on Git branch patterns
17-
#[derive(Parser)]
18-
#[command(
19-
about = "Generate version with intelligent pre-release management based on Git branch patterns"
20-
)]
21-
#[command(
22-
long_about = "Generate version strings with automatic pre-release detection based on Git branch patterns.
23-
This command acts as an intelligent wrapper around 'zerv version' that automatically determines
24-
pre-release information from the current Git branch using configurable pattern matching.
25-
26-
INPUT/OUTPUT OPTIONS:
27-
-s, --source <TYPE> Input source: git, stdin
28-
-f, --input-format <FMT> Input format: auto, semver, pep440
29-
-o, --output-format <FMT> Output format: semver, pep440, zerv
30-
-t, --output-template <TPL> Custom output template (Handlebars)
31-
-p, --output-prefix <PFX> Add prefix to version output
32-
33-
BRANCH PATTERN DETECTION:
34-
--branch-rules <RON> Custom branch pattern rules in RON format
35-
Default: develop -> alpha, release/* -> rc
36-
37-
OUTPUT MODES:
38-
--with-pre-release Show full version including pre-release (default)
39-
--base-only Show only base version without pre-release
40-
41-
POST DISTANCE MODES:
42-
--post-mode <MODE> Post calculation: tag (default), commit
43-
44-
OVERRIDES:
45-
--tag-version <TAG> Override detected tag version
46-
--distance <NUM> Override distance from tag
47-
--dirty Override dirty state to true
48-
--no-dirty Override dirty state to false
49-
--clean Force clean state (distance=0, dirty=false)
50-
--current-branch <NAME> Override branch name for pattern matching
51-
--commit-hash <HASH> Override commit hash
52-
53-
EXAMPLES:
54-
# Basic flow version with automatic pre-release detection
55-
zerv flow
56-
57-
# Custom branch rules (RON format)
58-
zerv flow --branch-rules \"[(branch_pattern: \"feature/*\", pre_release: \"beta\", number: 2)]\"
59-
60-
# Different output formats
61-
zerv flow --output-format pep440
62-
zerv flow --output-format zerv
63-
zerv flow --output-prefix v
64-
65-
# Show base version only
66-
zerv flow --base-only
67-
68-
# Override branch for testing
69-
zerv flow --current-branch release/v1.2.0
70-
71-
# Force clean release state
72-
zerv flow --clean
73-
74-
# Use in different directory
75-
zerv flow -C /path/to/repo"
76-
)]
77-
#[derive(Debug, Default)]
78-
pub struct FlowArgs {
79-
#[command(flatten)]
80-
pub input: InputConfig,
81-
82-
#[command(flatten)]
83-
pub output: OutputConfig,
84-
85-
#[command(flatten)]
86-
pub flow_specific: FlowSpecificConfig,
87-
88-
#[command(flatten)]
89-
pub overrides: OverridesConfig,
90-
}
91-
92-
// TODO: implement tests for this folder.
93-
impl FlowArgs {
94-
/// Validate arguments and return early errors
95-
/// This provides early validation before flow processing
96-
/// Note: source and format validation is handled by clap's value parser
97-
pub fn validate(&mut self) -> Result<(), crate::error::ZervError> {
98-
// Use shared validation for input/output
99-
CommonValidation::validate_io(&self.input, &self.output)?;
100-
101-
// Validate flow-specific modules
102-
Validation::validate_flow_specific(&self.flow_specific)?;
103-
Validation::validate_overrides(&self.overrides)?;
104-
Validation::validate_branch_rules(&self.flow_specific.branch_rules)?;
105-
106-
Ok(())
107-
}
108-
109-
/// Get the dirty override state (None = use VCS, Some(bool) = override)
110-
pub fn dirty_override(&self) -> Option<bool> {
111-
self.overrides.dirty_override()
112-
}
113-
}

0 commit comments

Comments
 (0)