File: commit-message.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 (245 lines) | stat: -rw-r--r-- 5,003 bytes parent folder | download | duplicates (5)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Test the get_commit_message method in Git::Commit

use 5.008;
use strict;
use warnings;

use Test::More 0.88;            # want done_testing

plan tests => 20;

use Dist::Zilla::File::InMemory ();
use Dist::Zilla::Plugin::Git::Commit ();
use Log::Dispatchouli ();

#=====================================================================
{
  package
      Mock_Zilla;

  use Moose;

  has version => qw(is ro);
  has files   => qw(is ro), default => sub { [] };

  sub isa { 1 }                 # just cheat and claim we're anything

  __PACKAGE__->meta->make_immutable;
};

#=====================================================================
# Utility functions
#---------------------------------------------------------------------
sub is_log
{
  my ($plugin, $expected) = @_;

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

  is_deeply([ map {; $_->{message} } @{ $plugin->logger->events } ],
            $expected);
} # end is_log

#---------------------------------------------------------------------
my $zilla;       # must be global, because $plugin->zilla is a weakref

sub new_plugin
{
  my $version = shift;
  my $changes = pop @_;

  $zilla  = Mock_Zilla->new(version => $version);

  if (defined $changes) {
    push @{ $zilla->files }, Dist::Zilla::File::InMemory->new(
      name => 'Changes',
      content => $changes,
    );
  }

  Dist::Zilla::Plugin::Git::Commit->new(
    plugin_name => 'Git::Commit',
    zilla       => $zilla,
    logger      => Log::Dispatchouli->new_tester,
    @_
  );
} # end new_plugin

#=====================================================================
{
  my $plugin = new_plugin('1.00');

  is($plugin->get_commit_message, "v1.00\n\n", '1.00 without Changes file');

  is_log($plugin, ['WARNING: Unable to find Changes']);
}

#---------------------------------------------------------------------
{
  my $plugin = new_plugin('1.00', <<'EOT');
This is the changelog for Foobar

1.00  2012-12-01

  Some unspecified changes
EOT

  is($plugin->get_commit_message, <<'EOM', '1.00 with blank line');
v1.00

  Some unspecified changes
EOM

  is_log($plugin, []);
}

#---------------------------------------------------------------------
{
  my $plugin = new_plugin('1.00', <<'EOT');
This is the changelog for Foobar

1.00  2012-12-01
  Some unspecified changes
EOT

  is($plugin->get_commit_message, <<'EOM', '1.00 without blank line');
v1.00

  Some unspecified changes
EOM

  is_log($plugin, []);
}

#---------------------------------------------------------------------
{
  my $plugin = new_plugin('1.01', <<'EOT');
This is the changelog for Foobar

1.01  2012-12-01

  Some unspecified changes

1.00  2012-11-30

  Some previous changes
EOT

  is($plugin->get_commit_message, <<'EOM', '1.01 with changes');
v1.01

  Some unspecified changes
EOM

  is_log($plugin, []);
}

#---------------------------------------------------------------------
{
  my $plugin = new_plugin('1.01', <<'EOT');
This is the changelog for Foobar

1.00  2012-12-01

  Some unspecified changes
EOT

  is($plugin->get_commit_message, "v1.01\n\n", '1.01 not in Changes');
  is_log($plugin, ['WARNING: Unable to find 1.01 in Changes']);
}

#---------------------------------------------------------------------
{
  my $plugin = new_plugin('1.00', <<'EOT');
This is the changelog for Foobar

1.00-TRIAL  2012-12-01
  Some unspecified changes
EOT

  is($plugin->get_commit_message, <<'EOM', '1.00-TRIAL');
v1.00

  Some unspecified changes
EOM

  is_log($plugin, []);
}

#---------------------------------------------------------------------
{
  my $plugin = new_plugin('1.00', <<'EOT');
This is the changelog for Foobar

1.00_TRIAL  2012-12-01
  Some unspecified changes
EOT

  is($plugin->get_commit_message, <<'EOM', '1.00_TRIAL');
v1.00

  Some unspecified changes
EOM

  is_log($plugin, []);
}

#---------------------------------------------------------------------
{
  my $plugin = new_plugin('1.01', <<'EOT');
This is the changelog for Foobar

1.01  2012-12-01

1.00  2012-11-30

  Some previous changes
EOT

  is($plugin->get_commit_message, "v1.01\n\n", '1.01 with no changes');
  is_log($plugin, ['WARNING: No changes listed under 1.01 in Changes']);
}

#---------------------------------------------------------------------
{
  my $plugin = new_plugin('1.01', <<'EOT');
This is the changelog for Foobar

1.01  2012-12-01

  Some unspecified changes with extra blank line


1.00  2012-11-30

  Some previous changes
EOT

  is($plugin->get_commit_message, <<'EOM', '1.01 with extra blank line');
v1.01

  Some unspecified changes with extra blank line
EOM

  is_log($plugin, []);
}

#---------------------------------------------------------------------
{
  my $plugin = new_plugin('1.00', <<'EOT');
1.00  2012-11-30

  Some unspecified changes
EOT

  is($plugin->get_commit_message, <<'EOM', '1.00 at BOF');
v1.00

  Some unspecified changes
EOM

  is_log($plugin, []);
}

#---------------------------------------------------------------------
done_testing;