File: version-by-branch.t

package info (click to toggle)
libdist-zilla-plugin-git-perl 2.051-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 712 kB
  • sloc: perl: 1,306; makefile: 11
file content (179 lines) | stat: -rw-r--r-- 4,653 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use strict;
use warnings;

use Test::DZil qw(dist_ini);

use Path::Tiny qw(path);
use Test::More 0.88;            # done_testing
use Test::Fatal;

use lib 't/lib';
use Util qw(:DEFAULT zilla_version);

skip_unless_git_version('1.6.1'); # need --simplify-by-decoration

plan tests => 31;

init_test(
  add_files => {
    Changes => "Just getting started\n",
    'dist.ini' => dist_ini(
      {qw(
        name              Foo
        author            foobar
        license           Perl_5
        abstract          Test-Library
        copyright_holder  foobar
        copyright_year    2009
      )},
      [ 'Git::NextVersion', { version_by_branch => 1 } ],
      'FakeRelease',
    ),
  }, # end add_files
);

#---------------------------------------------------------------------
## shortcut for new tester object

my $cache = '.gitnxtver_cache';

sub _new_zilla {
  my ($rev, $tag) = @_;

  my %test_config;

  if ($rev) {
    my ($sha) = $git->rev_parse($rev);
    $test_config{add_files}{"source/$cache"} = "$sha $tag\n";
  }

  new_zilla_from_repo(\%test_config);
}

sub _zilla_version {
  _new_zilla(@_);
  zilla_version;
}

# Check the contents (or absence) of .gitnxtver_cache:
sub head_last_ver
{
  my ($last_ver) = @_;

  local $Test::Builder::Level = $Test::Builder::Level + 1;

  if (defined $last_ver) {
    my ($head) = $git->rev_parse('HEAD');

    is(slurp_text_file("source/$cache"), "$head $last_ver\n",
       "cache file contains $last_ver");
  } else {
    ok( !-f path($zilla->root)->child($cache), "no cache file created");
  }
} # end head_last_ver

# with no tags and no initialization, should get default
is( _zilla_version, "0.001", "works with no commits" );
head_last_ver(undef);

$git->add(".");
$git->commit({ message => 'import' });

# with no tags and no initialization, should get default
is( _zilla_version, "0.001", "default is 0.001" );
head_last_ver(undef);

# initialize it using V=
{
    local $ENV{V} = "1.23";
    is( _zilla_version, "1.23", "initialized with \$ENV{V}" );
    head_last_ver(undef);
}

# add a tag that doesn't match the regex
$git->tag("revert-me-later");
ok( (grep { /revert-me-later/ } $git->tag), "wrote revert-me-later tag" );

is( _zilla_version, "0.001", "default is 0.001" );
head_last_ver(undef);

# tag 1.2.3
append_and_add(Changes => "1.2.3 now\n");
$git->commit({ message => 'committing 1.2.3'});
$git->tag("v1.2.3");
ok( (grep { /v1\.2\.3/ } $git->tag), "wrote v1.2.3 tag" );

is( _zilla_version, "1.2.4", "next version of 1.2.4 determined from last tag" );
head_last_ver("1.2.3");

# make a dev branch
$git->checkout(qw(-b dev));

# tag first dev release 1.3.0
append_and_add(Changes => "1.3.0 dev release\n");
$git->commit({ message => 'committing 1.3.0'});
$git->tag("v1.3.0");
ok( (grep { /v1\.3\.0/ } $git->tag), "wrote v1.3.0 tag" );

is( _zilla_version, "1.3.1", "next version of 1.3.1 determined from 1.3.0 tag on dev" );
head_last_ver("1.3.0");

# go back to master branch
$git->checkout(qw(master));

is( _zilla_version, "1.2.4", "next version of 1.2.4 determined from 1.2.3 tag on master" );
head_last_ver("1.2.3");

# tag stable 1.2.4
append_and_add(Changes => "1.2.4 stable release\n");
$git->commit({ message => 'committing 1.2.4 on master'});
$git->tag("v1.2.4");
ok( (grep { /v1\.2\.4/ } $git->tag), "wrote v1.2.4 tag" );

is( _zilla_version, "1.2.5", "next version of 1.2.5 determined from 1.2.4 tag on master" );
head_last_ver("1.2.4");

# go back to dev branch
$git->checkout(qw(dev));

append_and_add(Changes => "1.3.1 in progress\n");
$git->commit({ message => 'committing 1.3.1 change'});

is( _zilla_version, "1.3.1", "next version of 1.3.1 determined from 1.3.0 tag on dev" );
head_last_ver("1.3.0");

# go back to master branch
$git->checkout(qw(master));

append_and_add(Changes => "1.2.5 still in progress\n");
$git->commit({ message => 'committing 1.2.5 change to master'});

is( _zilla_version, "1.2.5", "next version of 1.2.5 determined from 1.2.4 tag on master" );
head_last_ver("1.2.4");

# see if it reads the cache
is( _zilla_version(qw(HEAD 1.2.6)), "1.2.7", "using (fake) cached 1.2.6 tag" );
head_last_ver("1.2.6");

# see if it ignores a stale cache
is( _zilla_version(qw(HEAD~1 1.2.6)), "1.2.5",
    "ignoring stale cached 1.2.6 tag" );
head_last_ver("1.2.4");

# see if it catches a duplicate version
_new_zilla(qw(HEAD 1.2.3));
is(
    exception { $zilla->build },
    undef,
    "builds with duplicate version",
);
is( $zilla->version, "1.2.4", "version is duplicate" );
like(
    exception { $zilla->release },
    qr/version 1\.2\.4 has already been tagged/,
    "don't release duplicate version",
);

#keep_tempdir;

done_testing;