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