column_info POD generation improvements
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 23dumpmore.t
index 57bd206..1242d78 100644 (file)
@@ -4,6 +4,7 @@ use lib qw(t/lib);
 use File::Path;
 use IPC::Open3;
 use make_dbictest_db;
+use Data::Dumper::Concise;
 require DBIx::Class::Schema::Loader;
 
 my $DUMP_PATH = './t/_dump';
@@ -26,7 +27,7 @@ sub dump_directly {
     $schema_class->storage->disconnect if !$err && $schema_class->storage;
     undef *{$schema_class};
 
-    is($err, $tdata{error});
+    check_error($err, $tdata{error});
 
     return @warns;
 }
@@ -38,6 +39,7 @@ sub dump_dbicdump {
     my @cmd = ($^X, qw(./script/dbicdump));
 
     while (my ($opt, $val) = each(%{ $tdata{options} })) {
+        $val = Dumper($val) if ref $val;
         push @cmd, '-o', "$opt=$val";
     }
 
@@ -45,17 +47,40 @@ sub dump_dbicdump {
 
     # make sure our current @INC gets used by dbicdump
     use Config;
-    local $ENV{PERL5LIB} = join $Config{path_sep}, @INC, $ENV{PERL5LIB};
+    local $ENV{PERL5LIB} = join $Config{path_sep}, @INC, ($ENV{PERL5LIB} || '');
 
     my ($in, $out, $err);
     my $pid = open3($in, $out, $err, @cmd);
 
-    my @warns = <$out>;
+    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 check_error {
+    my ($got, $expected) = @_;
+
+    return unless $got && $expected;
+
+    if (ref $expected eq 'Regexp') {
+        like $got, $expected, 'error matches expected pattern';
+        return;
+    }
+
+    is $got, $expected, 'error matches';
+}
+
 sub do_dump_test {
     my %tdata = @_;
     
@@ -75,6 +100,7 @@ sub test_dumps {
     my $schema_class = $tdata{classname};
     my $check_warns = $tdata{warnings};
     is(@warns, @$check_warns, "$schema_class warning count");
+
     for(my $i = 0; $i <= $#$check_warns; $i++) {
         like($warns[$i], $check_warns->[$i], "$schema_class warning $i");
     }
@@ -163,7 +189,12 @@ rmtree($DUMP_PATH, 1, 1);
 
 do_dump_test(
     classname => 'DBICTest::DumpMore::1',
-    options => { },
+    options => {
+        custom_column_info => sub {
+            my ($table, $col, $info) = @_;
+            return +{ extra => { is_footext => 1 } } if $col eq 'footext';
+        }
+    },
     error => '',
     warnings => [
         qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
@@ -178,8 +209,8 @@ do_dump_test(
 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  default_value: undef\n  is_nullable: 1\n  size: undef\n\n/,
-qr/=head2 footext\n\n  data_type: TEXT\n  default_value: undef\n  is_nullable: 1\n  size: undef\n\n/,
+qr/=head2 fooid\n\n  data_type: 'INTEGER'\n  default_value: undef\n  is_nullable: 1\n  size: undef\n\n/,
+qr/=head2 footext\n\n  data_type: 'TEXT'\n  default_value: 'footext'\n  extra: {is_footext => 1}\n  is_nullable: 1\n  size: undef\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/,
@@ -189,8 +220,8 @@ qr/1;\n$/,
 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  default_value: undef\n  is_nullable: 1\n  size: undef\n\n/,
-qr/=head2 fooref\n\n  data_type: INTEGER\n  default_value: undef\n  is_foreign_key: 1\n  is_nullable: 1\n  size: undef\n\n/,
+qr/=head2 barid\n\n  data_type: 'INTEGER'\n  default_value: undef\n  is_nullable: 1\n  size: undef\n\n/,
+qr/=head2 fooref\n\n  data_type: 'INTEGER'\n  default_value: undef\n  is_foreign_key: 1\n  is_nullable: 1\n  size: undef\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/,
@@ -373,6 +404,15 @@ do_dump_test(
     },
 );
 
+do_dump_test(
+    classname => 'DBICTest::DumpMore::1',
+    options   => {
+        use_namespaces    => 1,
+        result_base_class => 'My::MissingResultBaseClass',
+    },
+    error => qr/My::MissingResultBaseClass.*is not installed/,
+);
+
 done_testing;
 
 END { rmtree($DUMP_PATH, 1, 1) unless $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP} }