Use the actual md5sum of the old version when deciding whether to overwrite
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 40overwrite_modifications.t
CommitLineData
9cb983b3 1use strict;
c939b4ac 2use Test::More;
9cb983b3 3use Test::Exception;
c38ec663 4use Test::Warn;
9cb983b3 5use lib qw(t/lib);
6use make_dbictest_db;
7
8use File::Copy;
9use File::Spec;
10use File::Temp qw/ tempdir tempfile /;
11
12use DBIx::Class::Schema::Loader;
c939b4ac 13use DBIx::Class::Schema::Loader::Utils qw/ slurp_file /;
9cb983b3 14
15my $tempdir = tempdir( CLEANUP => 1 );
f22644d7 16my $foopm = File::Spec->catfile( $tempdir,
17 qw| DBICTest Schema Overwrite_modifications Result Foo.pm |);
9cb983b3 18dump_schema();
19
20# check that we dumped
21ok( -f $foopm, 'looks like it dumped' );
22
23# now modify one of the files
24{
25 open my $in, '<', $foopm or die "$! reading $foopm";
26 my ($tfh,$temp) = tempfile( UNLINK => 1);
27 while(<$in>) {
c38ec663 28 s/"bars"/"somethingelse"/;
29 print $tfh $_;
9cb983b3 30 }
31 close $tfh;
32 copy( $temp, $foopm );
33}
34
35# and dump again without overwrites
36throws_ok {
37 dump_schema();
38} qr/mismatch/, 'throws error dumping without overwrite_modifications';
39
40# and then dump with overwrite
41lives_ok {
42 dump_schema( overwrite_modifications => 1 );
43} 'does not throw when dumping with overwrite_modifications';
44
c939b4ac 45
46unlike slurp_file $foopm, qr/"somethingelse"/, "Modifications actually overwritten";
47
9cb983b3 48sub dump_schema {
49
50 # need to poke _loader_invoked in order to be able to rerun the
51 # loader multiple times.
52 DBICTest::Schema::Overwrite_modifications->_loader_invoked(0)
c38ec663 53 if @DBICTest::Schema::Overwrite_modifications::ISA;
54
55 my $args = \@_;
56
57 warnings_exist {
58 DBIx::Class::Schema::Loader::make_schema_at( 'DBICTest::Schema::Overwrite_modifications',
59 { dump_directory => $tempdir, @$args },
60 [ $make_dbictest_db::dsn ],
61 );
62 } [qr/^Dumping manual schema/, qr/^Schema dump completed/ ];
9cb983b3 63}
c939b4ac 64
65done_testing();