From: Dagfinn Ilmari Mannsåker Date: Tue, 29 Jul 2014 00:43:17 +0000 (+0100) Subject: Use Test::Differences to check lack of file rewrite X-Git-Tag: 0.07041~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a2e5cee345b8e159f081ee9b4d17add56b6217b5;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Use Test::Differences to check lack of file rewrite --- diff --git a/Makefile.PL b/Makefile.PL index a2f0f10..f6e85f7 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -35,6 +35,7 @@ test_requires 'DBD::SQLite' => '1.29'; test_requires 'Test::Exception' => '0.31'; test_requires 'Test::More' => '0.94'; test_requires 'Test::Warn' => '0.21'; +test_requires 'Test::Differences' => '0.60'; requires 'Carp::Clan' => 0; requires 'Class::Accessor::Grouped' => '0.10008'; diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 71f73fe..d9f3485 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -5,11 +5,11 @@ use warnings; use Test::More; use Test::Exception; +use Test::Differences; use DBIx::Class::Schema::Loader; use Class::Unload; use File::Path 'rmtree'; use DBI; -use Digest::MD5; use File::Find 'find'; use Class::Unload (); use DBIx::Class::Schema::Loader::Utils qw/dumper_squashed slurp_file sigwarn_silencer/; @@ -1178,8 +1178,8 @@ EOF q{ INSERT INTO loader_test30 (id,loader_test2) VALUES(321, 2) }, ); - # get md5 - my $digest = Digest::MD5->new; + # get contents + my %contents; my $find_cb = sub { return if -d; @@ -1187,18 +1187,18 @@ EOF open my $fh, '<', $_ or die "Could not open $_ for reading: $!"; binmode $fh; - $digest->addfile($fh); + local $/; + $contents{$File::Find::name} = <$fh>; }; find $find_cb, DUMP_DIR; + my %contents_before = %contents; # system "rm -rf /tmp/before_rescan /tmp/after_rescan"; # system "mkdir /tmp/before_rescan"; # system "mkdir /tmp/after_rescan"; # system "cp -a @{[DUMP_DIR]} /tmp/before_rescan"; - my $before_digest = $digest->b64digest; - $conn->storage->disconnect; # needed for Firebird and Informix my $dbh = $self->dbconnect(1); $dbh->do($_) for @statements_rescan; @@ -1212,12 +1212,21 @@ EOF # system "cp -a @{[DUMP_DIR]} /tmp/after_rescan"; - $digest = Digest::MD5->new; + undef %contents; find $find_cb, DUMP_DIR; - my $after_digest = $digest->b64digest; - - is $before_digest, $after_digest, - 'dumped files are not rewritten when there is no modification'; + my %contents_after = %contents; + + subtest 'dumped files are not rewritten when there is no modification' => sub { + plan tests => 1 + scalar keys %contents_before; + is_deeply + [sort keys %contents_before], + [sort keys %contents_after], + 'same files dumped'; + for my $file (sort keys %contents_before) { + eq_or_diff $contents_before{$file}, $contents_after{$file}, + "$file not rewritten"; + } + }; my $rsobj30 = $conn->resultset('LoaderTest30'); isa_ok($rsobj30, 'DBIx::Class::ResultSet');