allow user to set qualify_objects to false
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 23dumpmore.t
index ea5fd6b..0ca9461 100644 (file)
 use strict;
+use warnings;
 use Test::More;
-use File::Path;
-use IPC::Open3;
-use Data::Dumper::Concise;
-use DBIx::Class::Schema::Loader ();
-use File::Temp 'tempfile';
+use DBIx::Class::Schema::Loader::Utils qw/slurp_file write_file/;
+use namespace::clean;
+use File::Temp ();
 use lib qw(t/lib);
+use dbixcsl_dumper_tests;
+my $t = 'dbixcsl_dumper_tests';
 
-my $DUMP_PATH = './t/_dump';
+$t->cleanup;
 
-my $TEST_DB_CLASS = 'make_dbictest_db';
-
-sub dump_directly {
-    my %tdata = @_;
-
-    my $schema_class = $tdata{classname};
-
-    no strict 'refs';
-    @{$schema_class . '::ISA'} = ('DBIx::Class::Schema::Loader');
-    $schema_class->loader_options(%{$tdata{options}});
-
-    my @warns;
-    eval {
-        local $SIG{__WARN__} = sub { push(@warns, @_) };
-        $schema_class->connect(get_dsn(\%tdata));
-    };
-    my $err = $@;
-    $schema_class->storage->disconnect if !$err && $schema_class->storage;
-    undef *{$schema_class};
-
-    check_error($err, $tdata{error});
-
-    return @warns;
-}
-
-sub dump_dbicdump {
-    my %tdata = @_;
-
-    # use $^X so we execute ./script/dbicdump with the same perl binary that the tests were executed with
-    my @cmd = ($^X, qw(./script/dbicdump));
-
-    while (my ($opt, $val) = each(%{ $tdata{options} })) {
-        $val = Dumper($val) if ref $val;
-        push @cmd, '-o', "$opt=$val";
-    }
-
-    push @cmd, $tdata{classname}, get_dsn(\%tdata);
-
-    # make sure our current @INC gets used by dbicdump
-    use Config;
-    local $ENV{PERL5LIB} = join $Config{path_sep}, @INC, ($ENV{PERL5LIB} || '');
-
-    my ($in, $out, $err);
-    my $pid = open3($in, $out, $err, @cmd);
-
-    my @out = <$out>;
-    waitpid($pid, 0);
-
-    my ($error, @warns);
-
-    if ($? >> 8 != 0) {
-        $error = $out[0];
-        check_error($error, $tdata{error});
-    }
-    else {
-        @warns = @out;
-    }
-
-    return @warns;
-}
-
-sub get_dsn {
-    my $opts = shift;
+# test loading external content
+$t->dump_test(
+  classname => 'DBICTest::Schema::_no_skip_load_external',
+  regexes => {
+    Foo => [
+      qr/package DBICTest::Schema::_no_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/
+    ],
+  },
+);
 
-    my $test_db_class = $opts->{test_db_class} || $TEST_DB_CLASS;
+# test skipping external content
+$t->dump_test(
+  classname => 'DBICTest::Schema::_skip_load_external',
+  options => {
+    skip_load_external => 1,
+  },
+  neg_regexes => {
+    Foo => [
+      qr/package DBICTest::Schema::_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/
+    ],
+  },
+);
 
-    eval "require $test_db_class;";
-    die $@ if $@;
+$t->cleanup;
+# test config_file
+{
+  my $config_file = File::Temp->new (UNLINK => 1);
 
-    my $dsn = do {
-        no strict 'refs';
-        ${$test_db_class . '::dsn'};
-    };
+  print $config_file "{ skip_relationships => 1 }\n";
+  close $config_file;
 
-    return $dsn;
+  $t->dump_test(
+    classname => 'DBICTest::Schema::_config_file',
+    options => { config_file => "$config_file" },
+    neg_regexes => {
+      Foo => [
+        qr/has_many/,
+      ],
+    },
+  );
 }
 
-sub check_error {
-    my ($got, $expected) = @_;
-
-    return unless $got && $expected;
+# proper exception
+$t->dump_test(
+  classname => 'DBICTest::Schema::_clashing_monikers',
+  test_db_class => 'make_dbictest_db_clashing_monikers',
+  error => qr/tables (?:"bar", "bars"|"bars", "bar") reduced to the same source moniker 'Bar'/,
+);
 
-    if (ref $expected eq 'Regexp') {
-        like $got, $expected, 'error matches expected pattern';
-        return;
-    }
 
-    is $got, $expected, 'error matches';
-}
+$t->cleanup;
 
-sub do_dump_test {
-    my %tdata = @_;
-    
-    $tdata{options}{dump_directory} = $DUMP_PATH;
-    $tdata{options}{use_namespaces} ||= 0;
-
-    for my $dumper (\&dump_directly, \&dump_dbicdump) {
-        test_dumps(\%tdata, $dumper->(%tdata));
+# test naming => { column_accessors => 'preserve' }
+# also test POD for unique constraint
+$t->dump_test(
+    classname => 'DBICTest::Schema::_preserve_column_accessors',
+    test_db_class => 'make_dbictest_db_with_unique',
+    options => { naming => { column_accessors => 'preserve' } },
+    neg_regexes => {
+        RouteChange => [
+            qr/\baccessor\b/,
+        ],
+    },
+    regexes => {
+        Baz => [
+            qr/\n\n=head1 UNIQUE CONSTRAINTS\n\n=head2 C<baz_num_unique>\n\n=over 4\n\n=item \* L<\/baz_num>\n\n=back\n\n=cut\n\n__PACKAGE__->add_unique_constraint\("baz_num_unique"\, \["baz_num"\]\);\n\n/,
+        ],
     }
-}
-
-sub test_dumps {
-    my ($tdata, @warns) = @_;
-
-    my %tdata = %{$tdata};
+);
 
-    my $schema_class = $tdata{classname};
-    my $check_warns = $tdata{warnings};
-    is(@warns, @$check_warns, "$schema_class warning count");
+$t->cleanup;
 
-    for(my $i = 0; $i <= $#$check_warns; $i++) {
-        like($warns[$i], $check_warns->[$i], "$schema_class warning $i");
+# test that rels are sorted
+$t->dump_test(
+    classname => 'DBICTest::Schema::_sorted_rels',
+    test_db_class => 'make_dbictest_db_with_unique',
+    regexes => {
+        Baz => [
+            qr/->might_have\(\n  "quux".*->belongs_to\(\n  "station_visited"/s,
+        ],
     }
+);
 
-    my $file_regexes = $tdata{regexes};
-    my $file_neg_regexes = $tdata{neg_regexes} || {};
-    my $schema_regexes = delete $file_regexes->{schema};
-    
-    my $schema_path = $DUMP_PATH . '/' . $schema_class;
-    $schema_path =~ s{::}{/}g;
-
-    dump_file_like($schema_path . '.pm', @$schema_regexes) if $schema_regexes;
-
-    foreach my $src (keys %$file_regexes) {
-        my $src_file = $schema_path . '/' . $src . '.pm';
-        dump_file_like($src_file, @{$file_regexes->{$src}});
-    }
-    foreach my $src (keys %$file_neg_regexes) {
-        my $src_file = $schema_path . '/' . $src . '.pm';
-        dump_file_not_like($src_file, @{$file_neg_regexes->{$src}});
-    }
-}
+$t->cleanup;
 
-sub dump_file_like {
-    my $path = shift;
-    open(my $dumpfh, '<', $path) or die "Failed to open '$path': $!";
-    my $contents = do { local $/; <$dumpfh>; };
-    close($dumpfh);
-    my $num = 1;
-    like($contents, $_, "like $path " . $num++) for @_;
-}
+$t->dump_test(
+    classname => 'DBICTest::Schema::_sorted_uniqs',
+    test_db_class => 'make_dbictest_db_multi_unique',
+    regexes => {
+        Bar => [
+            qr/->add_unique_constraint\("uniq1_unique".*->add_unique_constraint\("uniq2_unique"/s,
+        ],
+    },
+);
 
-sub dump_file_not_like {
-    my $path = shift;
-    open(my $dumpfh, '<', $path) or die "Failed to open '$path': $!";
-    my $contents = do { local $/; <$dumpfh>; };
-    close($dumpfh);
-    my $num = 1;
-    unlike($contents, $_, "unlike $path ". $num++) for @_;
-}
+$t->cleanup;
 
-sub append_to_class {
-    my ($class, $string) = @_;
-    $class =~ s{::}{/}g;
-    $class = $DUMP_PATH . '/' . $class . '.pm';
-    open(my $appendfh, '>>', $class) or die "Failed to open '$class' for append: $!";
-    print $appendfh $string;
-    close($appendfh);
-}
+# test naming => { monikers => 'plural' }
+$t->dump_test(
+    classname => 'DBICTest::Schema::_plural_monikers',
+    options => { naming => { monikers => 'plural' } },
+    regexes => {
+        Foos => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Foos\n\n=cut\n\n/,
+        ],
+        Bars => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Bars\n\n=cut\n\n/,
+        ],
+    },
+);
 
-rmtree($DUMP_PATH, 1, 1);
+$t->cleanup;
 
-# test loading external content
-do_dump_test(
-    classname => 'DBICTest::Schema::13',
-    warnings => [
-        qr/Dumping manual schema for DBICTest::Schema::13 to directory /,
-        qr/Schema dump completed/,
-    ],
+# test naming => { monikers => 'singular' }
+$t->dump_test(
+    classname => 'DBICTest::Schema::_singular_monikers',
+    test_db_class => 'make_dbictest_db_plural_tables',
+    options => { naming => { monikers => 'singular' } },
     regexes => {
         Foo => [
-qr/package DBICTest::Schema::13::Foo;\nour \$skip_me = "bad mojo";\n1;/
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Foo\n\n=cut\n\n/,
+        ],
+        Bar => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Bar\n\n=cut\n\n/,
         ],
     },
 );
 
-# test skipping external content
-do_dump_test(
-    classname => 'DBICTest::Schema::14',
-    options => { skip_load_external => 1 },
-    warnings => [
-        qr/Dumping manual schema for DBICTest::Schema::14 to directory /,
-        qr/Schema dump completed/,
-    ],
-    neg_regexes => {
-        Foo => [
-qr/package DBICTest::Schema::14::Foo;\nour \$skip_me = "bad mojo";\n1;/
+$t->cleanup;
+
+# test naming => { monikers => 'preserve' }
+$t->dump_test(
+    classname => 'DBICTest::Schema::_preserve_monikers',
+    test_db_class => 'make_dbictest_db_plural_tables',
+    options => { naming => { monikers => 'preserve' } },
+    regexes => {
+        Foos => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Foos\n\n=cut\n\n/,
+        ],
+        Bars => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Bars\n\n=cut\n\n/,
         ],
     },
 );
 
-rmtree($DUMP_PATH, 1, 1);
+$t->cleanup;
 
-# test config_file
+# test out the POD and "use utf8;"
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    custom_column_info => sub {
+      my ($table, $col, $info) = @_;
+      return +{ extra => { is_footext => 1 } } if $col eq 'footext';
+    },
+    result_base_class => 'My::ResultBaseClass',
+    additional_classes => 'TestAdditional',
+    additional_base_classes => 'TestAdditionalBase',
+    left_base_classes => 'TestLeftBase',
+    components => [ 'TestComponent', '+TestComponentFQN' ],
+  },
+  regexes => {
+    schema => [
+      qr/^use utf8;\n/,
+      qr/package DBICTest::DumpMore::1;/,
+      qr/->load_classes/,
+    ],
+    Foo => [
+      qr/^use utf8;\n/,
+      qr/package DBICTest::DumpMore::1::Foo;/,
+      qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Foo\n\n=cut\n\nuse strict;\nuse warnings;\n\n/,
+      qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\nuse base 'My::ResultBaseClass';\n\n/,
+      qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item \* L<TestAdditional>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item \* L<DBIx::Class::TestComponent>\n\n=item \* L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 TABLE: C<foo>\n\n=cut\n\n__PACKAGE__->table\("foo"\);\n\n/,
+      qr/\n=head1 ACCESSORS\n\n/,
+      qr/\n=head2 fooid\n\n  data_type: 'integer'\n  is_auto_increment: 1\n  is_nullable: 0\n\n/,
+      qr/\n=head2 footext\n\n  data_type: 'text'\n  default_value: 'footext'\n  extra: {is_footext => 1}\n  is_nullable: 1\n\n/,
+      qr/\n=head1 PRIMARY KEY\n\n=over 4\n\n=item \* L<\/fooid>\n\n=back\n\n=cut\n\n__PACKAGE__->set_primary_key\("fooid"\);\n/,
+      qr/\n=head1 RELATIONS\n\n/,
+      qr/\n=head2 bars\n\nType: has_many\n\nRelated object: L<DBICTest::DumpMore::1::Bar>\n\n=cut\n\n/,
+      qr/1;\n$/,
+    ],
+    Bar => [
+      qr/^use utf8;\n/,
+      qr/package DBICTest::DumpMore::1::Bar;/,
+      qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Bar\n\n=cut\n\nuse strict;\nuse warnings;\n\n/,
+      qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\nuse base 'My::ResultBaseClass';\n\n/,
+      qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item \* L<TestAdditional>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item \* L<DBIx::Class::TestComponent>\n\n=item \* L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 TABLE: C<bar>\n\n=cut\n\n__PACKAGE__->table\("bar"\);\n\n/,
+      qr/\n=head1 ACCESSORS\n\n/,
+      qr/\n=head2 barid\n\n  data_type: 'integer'\n  is_auto_increment: 1\n  is_nullable: 0\n\n/,
+      qr/\n=head2 fooref\n\n  data_type: 'integer'\n  is_foreign_key: 1\n  is_nullable: 1\n\n/,
+      qr/\n=head1 PRIMARY KEY\n\n=over 4\n\n=item \* L<\/barid>\n\n=back\n\n=cut\n\n__PACKAGE__->set_primary_key\("barid"\);\n/,
+      qr/\n=head1 RELATIONS\n\n/,
+      qr/\n=head2 fooref\n\nType: belongs_to\n\nRelated object: L<DBICTest::DumpMore::1::Foo>\n\n=cut\n\n/,
+      qr/\n1;\n$/,
+    ],
+  },
+);
 
-my ($fh, $config_file) = tempfile;
+$t->append_to_class('DBICTest::DumpMore::1::Foo',q{# XXX This is my custom content XXX});
 
-print $fh <<'EOF';
-{ skip_relationships => 1 }
-EOF
-close $fh;
 
-do_dump_test(
-    classname => 'DBICTest::Schema::14',
-    options => { config_file => $config_file },
-    warnings => [
-        qr/Dumping manual schema for DBICTest::Schema::14 to directory /,
-        qr/Schema dump completed/,
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  regexes => {
+    schema => [
+      qr/package DBICTest::DumpMore::1;/,
+      qr/->load_classes/,
     ],
-    neg_regexes => {
-        Foo => [
-            qr/has_many/,
-        ],
-    },
+    Foo => [
+      qr/package DBICTest::DumpMore::1::Foo;/,
+      qr/->set_primary_key/,
+      qr/1;\n# XXX This is my custom content XXX/,
+    ],
+    Bar => [
+      qr/package DBICTest::DumpMore::1::Bar;/,
+      qr/->set_primary_key/,
+      qr/1;\n$/,
+    ],
+  },
 );
 
-unlink $config_file;
-
-rmtree($DUMP_PATH, 1, 1);
 
-do_dump_test(
-    classname => 'DBICTest::Schema::14',
-    test_db_class => 'make_dbictest_db_clashing_monikers',
-    error => qr/tables 'bar', 'bars' reduced to the same source moniker 'Bar'/,
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    really_erase_my_files => 1 
+  },
+  regexes => {
+    schema => [
+      qr/package DBICTest::DumpMore::1;/,
+      qr/->load_classes/,
+    ],
+    Foo => [
+      qr/package DBICTest::DumpMore::1::Foo;/,
+      qr/->set_primary_key/,
+      qr/1;\n$/,
+    ],
+    Bar => [
+      qr/package DBICTest::DumpMore::1::Bar;/,
+      qr/->set_primary_key/,
+      qr/1;\n$/,
+    ],
+  },
+  neg_regexes => {
+    Foo => [
+      qr/# XXX This is my custom content XXX/,
+    ],
+  },
 );
 
-rmtree($DUMP_PATH, 1, 1);
 
-# test out the POD
+$t->cleanup;
 
-do_dump_test(
-    classname => 'DBICTest::DumpMore::1',
-    options => {
-        custom_column_info => sub {
-            my ($table, $col, $info) = @_;
-            return +{ extra => { is_footext => 1 } } if $col eq 'footext';
-        }
-    },
-    warnings => [
-        qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-        qr/Schema dump completed/,
+# test namespaces
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    use_namespaces => 1,
+    generate_pod => 0
+  },
+  neg_regexes => {
+    'Result/Foo' => [
+      qr/^=/m,
     ],
-    regexes => {
-        schema => [
-            qr/package DBICTest::DumpMore::1;/,
-            qr/->load_classes/,
-        ],
-        Foo => [
-qr/package DBICTest::DumpMore::1::Foo;/,
-qr/=head1 NAME\n\nDBICTest::DumpMore::1::Foo\n\n=cut\n\n/,
-qr/=head1 ACCESSORS\n\n/,
-qr/=head2 fooid\n\n  data_type: 'integer'\n  is_auto_increment: 1\n  is_nullable: 1\n\n/,
-qr/=head2 footext\n\n  data_type: 'text'\n  default_value: 'footext'\n  extra: {is_footext => 1}\n  is_nullable: 1\n\n/,
-qr/->set_primary_key/,
-qr/=head1 RELATIONS\n\n/,
-qr/=head2 bars\n\nType: has_many\n\nRelated object: L<DBICTest::DumpMore::1::Bar>\n\n=cut\n\n/,
-qr/1;\n$/,
-        ],
-        Bar => [
-qr/package DBICTest::DumpMore::1::Bar;/,
-qr/=head1 NAME\n\nDBICTest::DumpMore::1::Bar\n\n=cut\n\n/,
-qr/=head1 ACCESSORS\n\n/,
-qr/=head2 barid\n\n  data_type: 'integer'\n  is_auto_increment: 1\n  is_nullable: 1\n\n/,
-qr/=head2 fooref\n\n  data_type: 'integer'\n  is_foreign_key: 1\n  is_nullable: 1\n\n/,
-qr/->set_primary_key/,
-qr/=head1 RELATIONS\n\n/,
-qr/=head2 fooref\n\nType: belongs_to\n\nRelated object: L<DBICTest::DumpMore::1::Foo>\n\n=cut\n\n/,
-qr/1;\n$/,
-        ],
-    },
+  },
 );
 
-append_to_class('DBICTest::DumpMore::1::Foo',q{# XXX This is my custom content XXX});
 
-do_dump_test(
-    classname => 'DBICTest::DumpMore::1',
-    warnings => [
-        qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-        qr/Schema dump completed/,
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    db_schema => 'foo_schema',
+    qualify_objects => 1,
+    use_namespaces => 1
+  },
+  warnings => [
+    qr/^db_schema is not supported on SQLite/,
+  ],
+  regexes => {
+    'Result/Foo' => [
+      qr/^\Q__PACKAGE__->table("foo_schema.foo");\E/m,
+      # the has_many relname should not have the schema in it!
+      qr/^__PACKAGE__->has_many\(\n  "bars"/m,
     ],
-    regexes => {
-        schema => [
-            qr/package DBICTest::DumpMore::1;/,
-            qr/->load_classes/,
-        ],
-        Foo => [
-            qr/package DBICTest::DumpMore::1::Foo;/,
-            qr/->set_primary_key/,
-            qr/1;\n# XXX This is my custom content XXX/,
-        ],
-        Bar => [
-            qr/package DBICTest::DumpMore::1::Bar;/,
-            qr/->set_primary_key/,
-            qr/1;\n$/,
-        ],
-    },
+  },
 );
 
-do_dump_test(
-    classname => 'DBICTest::DumpMore::1',
-    options => { really_erase_my_files => 1 },
-    warnings => [
-        qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-        qr/Deleting existing file /,
-        qr/Deleting existing file /,
-        qr/Deleting existing file /,
-        qr/Schema dump completed/,
+# test qualify_objects
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    db_schema => [ 'foo_schema', 'bar_schema' ],
+    qualify_objects => 0,
+    use_namespaces => 1,
+  },
+  warnings => [
+    qr/^db_schema is not supported on SQLite/,
+  ],
+  regexes => {
+    'Result/Foo' => [
+      # the table name should not include the db schema
+      qr/^\Q__PACKAGE__->table("foo");\E/m,
     ],
-    regexes => {
-        schema => [
-            qr/package DBICTest::DumpMore::1;/,
-            qr/->load_classes/,
-        ],
-        Foo => [
-            qr/package DBICTest::DumpMore::1::Foo;/,
-            qr/->set_primary_key/,
-            qr/1;\n$/,
-        ],
-        Bar => [
-            qr/package DBICTest::DumpMore::1::Bar;/,
-            qr/->set_primary_key/,
-            qr/1;\n$/,
-        ],
-    },
-    neg_regexes => {
-        Foo => [
-            qr/# XXX This is my custom content XXX/,
-        ],
-    },
+    'Result/Bar' => [
+      # the table name should not include the db schema
+      qr/^\Q__PACKAGE__->table("bar");\E/m,
+    ],
+  },
 );
 
-rmtree($DUMP_PATH, 1, 1);
+# test moniker_parts
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    db_schema => 'my_schema',
+    moniker_parts => ['_schema', 'name'],
+    qualify_objects => 1,
+    use_namespaces => 1,
+  },
+  warnings => [
+    qr/^db_schema is not supported on SQLite/,
+  ],
+  regexes => {
+    'Result/MySchemaFoo' => [
+      qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m,
+      # the has_many relname should not have the schema in it!
+      qr/^__PACKAGE__->has_many\(\n  "bars"/m,
+    ],
+  },
+);
 
-do_dump_test(
-    classname => 'DBICTest::DumpMore::1',
-    options => { use_namespaces => 1, generate_pod => 0 },
-    warnings => [
-        qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-        qr/Schema dump completed/,
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    use_namespaces => 1
+  },
+  regexes => {
+    schema => [
+      qr/package DBICTest::DumpMore::1;/,
+      qr/->load_namespaces/,
     ],
-    neg_regexes => {
-        'Result/Foo' => [
-            qr/^=/m,
-        ],
-    },
+    'Result/Foo' => [
+      qr/package DBICTest::DumpMore::1::Result::Foo;/,
+      qr/->set_primary_key/,
+      qr/1;\n$/,
+    ],
+    'Result/Bar' => [
+      qr/package DBICTest::DumpMore::1::Result::Bar;/,
+      qr/->set_primary_key/,
+      qr/1;\n$/,
+    ],
+  },
 );
 
-rmtree($DUMP_PATH, 1, 1);
 
-do_dump_test(
-    classname => 'DBICTest::DumpMore::1',
-    options => { db_schema => 'foo_schema', qualify_objects => 1, use_namespaces => 1 },
-    warnings => [
-        qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-        qr/Schema dump completed/,
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    use_namespaces => 1,
+    result_namespace => 'Res',
+    resultset_namespace => 'RSet',
+    default_resultset_class => 'RSetBase',
+  },
+  regexes => {
+    schema => [
+      qr/package DBICTest::DumpMore::1;/,
+      qr/->load_namespaces/,
+      qr/result_namespace => "Res"/,
+      qr/resultset_namespace => "RSet"/,
+      qr/default_resultset_class => "RSetBase"/,
     ],
-    regexes => {
-        'Result/Foo' => [
-            qr/^\Q__PACKAGE__->table("foo_schema.foo");\E/m,
-            # the has_many relname should not have the schema in it!
-            qr/^__PACKAGE__->has_many\(\n  "bars"/m,
-        ],
-    },
+    'Res/Foo' => [
+      qr/package DBICTest::DumpMore::1::Res::Foo;/,
+      qr/->set_primary_key/,
+      qr/1;\n$/,
+    ],
+    'Res/Bar' => [
+      qr/package DBICTest::DumpMore::1::Res::Bar;/,
+      qr/->set_primary_key/,
+      qr/1;\n$/,
+    ],
+  },
 );
 
-rmtree($DUMP_PATH, 1, 1);
 
-do_dump_test(
-    classname => 'DBICTest::DumpMore::1',
-    options => { use_namespaces => 1 },
-    warnings => [
-        qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-        qr/Schema dump completed/,
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    use_namespaces => 1,
+    result_namespace => '+DBICTest::DumpMore::1::Res',
+    resultset_namespace => 'RSet',
+    default_resultset_class => 'RSetBase',
+    result_base_class => 'My::ResultBaseClass',
+    schema_base_class => 'My::SchemaBaseClass',
+  },
+  regexes => {
+    schema => [
+      qr/package DBICTest::DumpMore::1;/,
+      qr/->load_namespaces/,
+      qr/result_namespace => "\+DBICTest::DumpMore::1::Res"/,
+      qr/resultset_namespace => "RSet"/,
+      qr/default_resultset_class => "RSetBase"/,
+      qr/use base 'My::SchemaBaseClass'/,
     ],
-    regexes => {
-        schema => [
-            qr/package DBICTest::DumpMore::1;/,
-            qr/->load_namespaces/,
-        ],
-        'Result/Foo' => [
-            qr/package DBICTest::DumpMore::1::Result::Foo;/,
-            qr/->set_primary_key/,
-            qr/1;\n$/,
-        ],
-        'Result/Bar' => [
-            qr/package DBICTest::DumpMore::1::Result::Bar;/,
-            qr/->set_primary_key/,
-            qr/1;\n$/,
-        ],
-    },
+    'Res/Foo' => [
+      qr/package DBICTest::DumpMore::1::Res::Foo;/,
+      qr/use base 'My::ResultBaseClass'/,
+      qr/->set_primary_key/,
+      qr/1;\n$/,
+    ],
+    'Res/Bar' => [
+      qr/package DBICTest::DumpMore::1::Res::Bar;/,
+      qr/use base 'My::ResultBaseClass'/,
+      qr/->set_primary_key/,
+      qr/1;\n$/,
+    ],
+  },
 );
 
-rmtree($DUMP_PATH, 1, 1);
-
-do_dump_test(
-    classname => 'DBICTest::DumpMore::1',
-    options => { use_namespaces => 1,
-                 result_namespace => 'Res',
-                 resultset_namespace => 'RSet',
-                 default_resultset_class => 'RSetBase',
-             },
-    warnings => [
-        qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-        qr/Schema dump completed/,
-    ],
-    regexes => {
-        schema => [
-            qr/package DBICTest::DumpMore::1;/,
-            qr/->load_namespaces/,
-            qr/result_namespace => 'Res'/,
-            qr/resultset_namespace => 'RSet'/,
-            qr/default_resultset_class => 'RSetBase'/,
-        ],
-        'Res/Foo' => [
-            qr/package DBICTest::DumpMore::1::Res::Foo;/,
-            qr/->set_primary_key/,
-            qr/1;\n$/,
-        ],
-        'Res/Bar' => [
-            qr/package DBICTest::DumpMore::1::Res::Bar;/,
-            qr/->set_primary_key/,
-            qr/1;\n$/,
-        ],
-    },
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    use_namespaces    => 1,
+    result_base_class => 'My::MissingResultBaseClass',
+  },
+  error => qr/My::MissingResultBaseClass.*is not installed/,
 );
 
-rmtree($DUMP_PATH, 1, 1);
-
-do_dump_test(
-    classname => 'DBICTest::DumpMore::1',
-    options => { use_namespaces => 1,
-                 result_namespace => '+DBICTest::DumpMore::1::Res',
-                 resultset_namespace => 'RSet',
-                 default_resultset_class => 'RSetBase',
-                 result_base_class => 'My::ResultBaseClass',
-                 schema_base_class => 'My::SchemaBaseClass',
-             },
-    warnings => [
-        qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-        qr/Schema dump completed/,
-    ],
-    regexes => {
-        schema => [
-            qr/package DBICTest::DumpMore::1;/,
-            qr/->load_namespaces/,
-            qr/result_namespace => '\+DBICTest::DumpMore::1::Res'/,
-            qr/resultset_namespace => 'RSet'/,
-            qr/default_resultset_class => 'RSetBase'/,
-            qr/use base 'My::SchemaBaseClass'/,
-        ],
-        'Res/Foo' => [
-            qr/package DBICTest::DumpMore::1::Res::Foo;/,
-            qr/use base 'My::ResultBaseClass'/,
-            qr/->set_primary_key/,
-            qr/1;\n$/,
-        ],
-        'Res/Bar' => [
-            qr/package DBICTest::DumpMore::1::Res::Bar;/,
-            qr/use base 'My::ResultBaseClass'/,
-            qr/->set_primary_key/,
-            qr/1;\n$/,
-        ],
+# test quote_char in connect_info for dbicdump
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  extra_connect_info => [
+    '',
+    '',
+    { quote_char => '"' },
+  ],
+);
+
+# test fix for RT#70507 (end comment and 1; gets lost if left with actual
+# custom content)
+
+$t->dump_test(
+    classname => 'DBICTest::DumpMore::Upgrade',
+    options => {
+        use_namespaces => 0,
     },
 );
 
-rmtree($DUMP_PATH, 1, 1);
+my $file = $t->class_file('DBICTest::DumpMore::Upgrade::Foo');
+
+my $code = slurp_file $file;
+
+$code =~ s/(?=# You can replace)/sub custom_method { 'custom_method works' }\n0;\n\n/;
 
-do_dump_test(
-    classname => 'DBICTest::DumpMore::1',
-    options   => {
-        use_namespaces    => 1,
-        result_base_class => 'My::MissingResultBaseClass',
+write_file $file, $code;
+
+$t->dump_test(
+    classname => 'DBICTest::DumpMore::Upgrade',
+    options => {
+        use_namespaces => 1,
+    },
+    regexes => {
+        'Result/Foo' => [
+            qr/sub custom_method { 'custom_method works' }\n0;\n\n# You can replace.*\n1;\n\z/,
+        ],
     },
-    error => qr/My::MissingResultBaseClass.*is not installed/,
 );
 
 done_testing;
-
-END { rmtree($DUMP_PATH, 1, 1) unless $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP} }
 # vim:et sts=4 sw=4 tw=0: