[go: up one dir, main page]

tagver 0.1.1

Core library for minimalistic versioning using Git tags
Documentation
//! Log messages tests - ported from MinVerTests.Lib/LogMessages.cs

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();

    // Create empty repository
    common::git::ensure_empty_repository(path)
        .await
        .expect("Failed to create repo");

    // Execute commands to create complex history
    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));

        // Add delay between commits for determinism
        if name.starts_with("commit") {
            tokio::time::sleep(std::time::Duration::from_millis(100)).await;
        }
    }

    // Configure version calculation with minimum major.minor
    let config = Config {
        minimum_major_minor: Some(MajorMinor::new(0, 0)),
        ..Default::default()
    };

    // Calculate version
    let result =
        calculate_version_with_fallback(path, &config).expect("Failed to calculate version");

    // Verify the version is calculated (actual logging validation would require full tracing setup)
    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();

    // Create empty repository
    common::git::ensure_empty_repository(path)
        .await
        .expect("Failed to create repo");

    // Execute commands to create simple history
    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));
    }

    // Configure version calculation with minimum major.minor
    let config = Config {
        minimum_major_minor: Some(MajorMinor::new(3, 0)),
        ..Default::default()
    };

    // Calculate version
    let result =
        calculate_version_with_fallback(path, &config).expect("Failed to calculate version");

    // Verify the version is calculated (actual logging validation would require full tracing setup)
    assert!(!result.to_string().is_empty());
}