use File::Path;
use IPC::Open3;
use make_dbictest_db;
+use Data::Dumper::Concise;
require DBIx::Class::Schema::Loader;
my $DUMP_PATH = './t/_dump';
$schema_class->storage->disconnect if !$err && $schema_class->storage;
undef *{$schema_class};
- is($err, $tdata{error});
+ check_error($err, $tdata{error});
return @warns;
}
my @cmd = ($^X, qw(./script/dbicdump));
while (my ($opt, $val) = each(%{ $tdata{options} })) {
+ $val = Dumper($val) if ref $val;
push @cmd, '-o', "$opt=$val";
}
# 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 = @_;
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");
}
rmtree($DUMP_PATH, 1, 1);
+# test loading external content
+do_dump_test(
+ classname => 'DBICTest::Schema::13',
+ options => { },
+ error => '',
+ warnings => [
+ qr/Dumping manual schema for DBICTest::Schema::13 to directory /,
+ qr/Schema dump completed/,
+ ],
+ regexes => {
+ Foo => [
+qr/package DBICTest::Schema::13::Foo;\nour \$skip_me = "bad mojo";\n1;/
+ ],
+ },
+);
+
+# test skipping external content
+do_dump_test(
+ classname => 'DBICTest::Schema::14',
+ options => { skip_load_external => 1 },
+ error => '',
+ 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;/
+ ],
+ },
+);
+
+rmtree($DUMP_PATH, 1, 1);
+
# test out the POD
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 /,
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/,
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/,
},
);
+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} }