Permalink
Browse files

Replace only files updated

  • Loading branch information...
1 parent acca335 commit a8225896c7f1c566f4dc5fd610dc8d935c81d989 @gfx committed Oct 9, 2009
Showing with 47 additions and 41 deletions.
  1. +13 −2 lib/ShipIt/Step/ChangeAllVersions.pm
  2. +34 −39 t/01_basic.t
@@ -24,12 +24,15 @@ sub run {
open my $in, '<', $module;
open my $out, '>', "$module.tmp";
+ my $need_replace = 0;
+
while (<$in>) {
# update $VERSION variable
if (s/(\$VERSION .+) \b $current_version \b/$1$new_version/xms) {
$self->{changed_version_variable}{$module}++;
$self->log("Update \$VERSION in $module.");
+ $need_replace++;
}
# update the VERSION section whic say,
@@ -39,6 +42,7 @@ sub run {
if (s/(version \s+) $current_version/$1$new_version/xms) {
$self->{changed_version_section}{$module}++;
$self->log("Update the VERSION section in $module.");
+ $need_replace++;
}
}
@@ -48,8 +52,15 @@ sub run {
close $in;
close $out;
- rename $module => "$module~";
- rename "$module.tmp" => $module;
+ if($need_replace){
+ rename $module => "$module~";
+ rename "$module.tmp" => $module;
+
+ unlink "$module~";
+ }
+ else{
+ unlink "$module.tmp";
+ }
}
return 1;
View
@@ -1,14 +1,14 @@
#!perl -w
use strict;
-use Test::More tests => 16;
+use Test::More tests => 22;
-use constant new_version => '0.001_01';
+my $new_version;
BEGIN{ # Fake Term::ReadLine, which is hard coded in ShipIt::Util
package Term::ReadLine;
sub new{ bless {}, shift }
- sub readline{ ::new_version() };
+ sub readline{ $new_version };
$INC{'Term/ReadLine.pm'} = __FILE__;
}
@@ -28,52 +28,47 @@ chdir 't/test' or die "Cannot chdir: $!";
*ShipIt::VC::new = \&ShipIt::VC::Dummy::new;
}
-my $conf = ShipIt::Conf->parse('.shipit');
-my $state = ShipIt::State->new($conf);
-
close STDOUT;
-my $stdout = '';
-open STDOUT, '>', \$stdout;
-foreach my $step( $conf->steps ){
- ok $step->run($state), $step;
+for(
+ {new_version => '0.001_01', current_version => '0.001' },
+ {new_version => '0.001', current_version => '0.001_01' },
+) {
+ my $stdout = '';
+ open STDOUT, '>', \$stdout;
- if($step->isa('ShipIt::Step::ChangeAllVersions')){
- is $step->changed_version_variable->{'Foo.pm'}, 1, 'VERSION variable in Foo.pm';
- is $step->changed_version_variable->{'Bar.pm'}, 1, 'VERSION variable in Bar.pm';
+ $new_version = $_->{new_version};
- is $step->changed_version_section->{'Foo.pm'}, 1, 'VERSION section in Foo.pm';
- is $step->changed_version_section->{'Bar.pm'}, 1, 'VERSION section in Bar.pm';
- is $step->changed_version_section->{'Baz.pod'}, 1, 'VERSION section in Baz.pod';
- }
-}
+ my $conf = ShipIt::Conf->parse('.shipit');
+ my $state = ShipIt::State->new($conf);
-like $stdout, qr/^Update \s+ \$VERSION/xms;
-like $stdout, qr/^Update \s+ the \s+ VERSION \s+ section/xms;
+ foreach my $step( $conf->steps ){
+ ok $step->run($state), $step;
-require './Foo.pm';
-require './Bar.pm';
-
-{
- no warnings 'once';
+ if($step->isa('ShipIt::Step::ChangeAllVersions')){
+ is $step->changed_version_variable->{'Foo.pm'}, 1, 'VERSION variable in Foo.pm';
+ is $step->changed_version_variable->{'Bar.pm'}, 1, 'VERSION variable in Bar.pm';
- is $Foo::VERSION, new_version, '$Foo::VERSION has been updated';
- is $Bar::VERSION, new_version, '$Bar::VERSION has been updated';
+ is $step->changed_version_section->{'Foo.pm'}, 1, 'VERSION section in Foo.pm';
+ is $step->changed_version_section->{'Bar.pm'}, 1, 'VERSION section in Bar.pm';
+ is $step->changed_version_section->{'Baz.pod'}, 1, 'VERSION section in Baz.pod';
+ }
+ }
- isnt $Bar::version, new_version, '$version is not touched';
- isnt $Bar::Version, new_version, '$Version is not touched';
-}
+ like $stdout, qr/^Update \s+ \$VERSION/xms;
+ like $stdout, qr/^Update \s+ the \s+ VERSION \s+ section/xms;
-# revert chnages for the next test :)
+ require './Foo.pm';
+ require './Bar.pm';
-if($ENV{DONT_REMOVE_CHANGED_FILES}){
- rename 'Foo.pm' => 'Foo.pm.bak';
- rename 'Bar.pm' => 'Bar.pm.bak';
- rename 'Baz.pod' => 'Baz.pod.bak';
-}
+ if($new_version eq '0.001_01'){ # on the first step
+ no warnings 'once';
-ok rename 'Foo.pm~' => 'Foo.pm';
-ok rename 'Bar.pm~' => 'Bar.pm';
-ok rename 'Baz.pod~' => 'Baz.pod';
+ is $Foo::VERSION, $new_version, '$Foo::VERSION has been updated';
+ is $Bar::VERSION, $new_version, '$Bar::VERSION has been updated';
+ isnt $Bar::version, $new_version, '$version is not touched';
+ isnt $Bar::Version, $new_version, '$Version is not touched';
+ }
+}

0 comments on commit a822589

Please sign in to comment.