ShipIt/Step/ChangeRPMVersion.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 40 CC 4 SCAR 25.1
CC
4
Cov
0%
run
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.3
1 package ShipIt::Step::ChangeRPMVersion;
2 use strict;
3 use base 'ShipIt::Step';
4 use ShipIt::Util qw(slurp write_file);
5  
6 sub run {
7 my ($self, $state) = @_;
8  
9 my $version = $state->version;
10  
11 my @specfiles = glob("*.spec");
12  
13 die "Unable to find specfile to update RPM version.\n"
14 unless @specfiles;
15  
16 die "Expected exactly one specfile, instead found: " . join(', ', @specfiles) . ".\n"
17 if (@specfiles > 1);
18  
19 my $file = shift @specfiles;
20  
21 my $contents = slurp($file);
22 $contents =~ s/^(\s*version:\s*)[\d.]+\s*$/${1}$version/m
23 or die "Couldn't modify RPM specfile version number.\n";
24  
25 $contents =~ s/^(\s*release:\s*)\d+\s*$/${1}1/m
26 or die "Couldn't modify RPM specfile release number.\n";
27  
28 if ($state->dry_run) {
29 warn "Dry-run option has stopped us from upgrading RPM specfile '$file'.\n";
30 return 1;
31 }
32  
33 write_file($file, $contents);
34 return 1;
35 }
36  
37 1;