use tagver::config::MajorMinor;
use tagver::{calculate_version_with_fallback, Config};
use tempfile::TempDir;
mod common;
#[tokio::test]
async fn test_minimum_major_minor_after_tag() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let path = temp_dir.path();
common::git::ensure_empty_repository(path)
.await
.expect("Failed to create repo");
let commands = vec![
("commit", vec!["commit", "--allow-empty", "-m", "."]),
("tag not-a-version", vec!["tag", "not-a-version"]),
("checkout foo", vec!["checkout", "-b", "foo"]),
("commit", vec!["commit", "--allow-empty", "-m", "."]),
("tag 1.0.0-foo.1", vec!["tag", "1.0.0-foo.1"]),
("checkout main", vec!["checkout", "main"]),
("merge foo", vec!["merge", "foo", "--no-edit", "--no-ff"]),
("checkout bar", vec!["checkout", "-b", "bar"]),
("commit", vec!["commit", "--allow-empty", "-m", "."]),
("checkout main", vec!["checkout", "main"]),
("checkout baz", vec!["checkout", "-b", "baz"]),
("commit", vec!["commit", "--allow-empty", "-m", "."]),
("checkout main", vec!["checkout", "main"]),
(
"merge bar baz",
vec![
"merge",
"bar",
"baz",
"--no-edit",
"--no-ff",
"--strategy=octopus",
],
),
];
for (name, args) in commands {
common::git::run_git_command(&args, path).unwrap_or_else(|_| panic!("Failed: {}", name));
if name.starts_with("commit") {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}
}
let config = Config {
minimum_major_minor: Some(MajorMinor::new(0, 0)),
..Default::default()
};
let result =
calculate_version_with_fallback(path, &config).expect("Failed to calculate version");
assert!(!result.to_string().is_empty());
}
#[tokio::test]
async fn test_minimum_major_minor_on_tag() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let path = temp_dir.path();
common::git::ensure_empty_repository(path)
.await
.expect("Failed to create repo");
let commands = vec![
("commit", vec!["commit", "--allow-empty", "-m", "."]),
("tag not-a-version", vec!["tag", "not-a-version"]),
("checkout foo", vec!["checkout", "-b", "foo"]),
("commit", vec!["commit", "--allow-empty", "-m", "."]),
("tag 1.0.0-foo.1", vec!["tag", "1.0.0-foo.1"]),
];
for (name, args) in commands {
common::git::run_git_command(&args, path).unwrap_or_else(|_| panic!("Failed: {}", name));
}
let config = Config {
minimum_major_minor: Some(MajorMinor::new(3, 0)),
..Default::default()
};
let result =
calculate_version_with_fallback(path, &config).expect("Failed to calculate version");
assert!(!result.to_string().is_empty());
}