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