App-Git-Workflow

 view release on metacpan or  search on metacpan

t/workflow.t  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;
use Test::More;
use Test::Warnings;
use Data::Dumper qw/Dumper/;
use lib 't/lib';
use App::Git::Workflow;
use Mock::App::Git::Workflow::Repository;

my $pom = App::Git::Workflow->new();
my $git = Mock::App::Git::Workflow::Repository->git;
$pom->{git} = $git;

test_branches();
test_tags();
test_config();
test_current();
test_match_commits();
test_release();
test_releases();
test_runner();
test_commit_details();
test_files_from_sha();
test_slurp();
test_spew();
test_settings();
test_save_settings();
test_url_encode();
done_testing();

sub test_branches {
    ok !eval{ $pom->branches('bad') } && $@, 'Bad branch type throws error';

    $git->mock_add({ branch => [map {"  $_"} qw{master abc_123} ]});
    is_deeply [$pom->branches()], [$pom->branches], "Two calls to branches uses cache";

}

sub test_tags {
    my @data = (
        [
            { tag => [qw /
                1.0
                10.0
                0.1
                v0.1
            /]},
            [qw /
                0.1
                1.0
                10.0
                v0.1
            /],
        ]
    );

    for my $data (@data) {
        $git->mock_add($data->[0]);
        is_deeply [$pom->tags()], $data->[1], "Get the sorted tags"
            or diag Dumper [$pom->tags()], $data->[1];
    }
}

sub test_config {
}

sub test_current {
    my @data = (
        [
            'git-simple',
            [qw'branch master'],
        ],
        [
            'git-tag',
            [qw'sha 55d0295a1227f591afc683dd12e43823cd2e404d'],
        ],
        [
            'git-branch',
            [qw'branch origin/master'],
        ],
    );

    for my $data (@data) {
        $git->mock_reset();
        $git->mock_add({ 'rev-parse' => 't/data' });
        $pom->{branches} = {};
        $pom->{tags}     = [];
        $pom->{GIT_DIR}  = $data->[0];
        my $ans = [$pom->current()];
        is_deeply $ans, $data->[1], "Get the current $data->[0]"
            or diag Dumper $ans, $data->[1];
    }



( run in 0.660 second using v1.01-cache-2.11-cpan-39bf76dae61 )