Commit | Line | Data |
9cb983b3 |
1 | use strict; |
f8c2ca5e |
2 | use warnings; |
c939b4ac |
3 | use Test::More; |
9cb983b3 |
4 | use Test::Exception; |
c38ec663 |
5 | use Test::Warn; |
9cb983b3 |
6 | use lib qw(t/lib); |
7 | use make_dbictest_db; |
8 | |
9 | use File::Copy; |
10 | use File::Spec; |
11 | use File::Temp qw/ tempdir tempfile /; |
12 | |
13 | use DBIx::Class::Schema::Loader; |
c939b4ac |
14 | use DBIx::Class::Schema::Loader::Utils qw/ slurp_file /; |
9cb983b3 |
15 | |
16 | my $tempdir = tempdir( CLEANUP => 1 ); |
f22644d7 |
17 | my $foopm = File::Spec->catfile( $tempdir, |
18 | qw| DBICTest Schema Overwrite_modifications Result Foo.pm |); |
9cb983b3 |
19 | dump_schema(); |
20 | |
21 | # check that we dumped |
22 | ok( -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 |
37 | throws_ok { |
38 | dump_schema(); |
39 | } qr/mismatch/, 'throws error dumping without overwrite_modifications'; |
40 | |
41 | # and then dump with overwrite |
42 | lives_ok { |
43 | dump_schema( overwrite_modifications => 1 ); |
44 | } 'does not throw when dumping with overwrite_modifications'; |
45 | |
c939b4ac |
46 | |
47 | unlike slurp_file $foopm, qr/"somethingelse"/, "Modifications actually overwritten"; |
48 | |
9cb983b3 |
49 | sub 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 | |
66 | done_testing(); |