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