From: Dagfinn Ilmari Mannsåker Date: Mon, 6 Jan 2014 15:33:20 +0000 (+0000) Subject: Fix generated_classes with dry_run => 1 X-Git-Tag: 0.07039~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f56e3f73f213ed706a7ac0377268ed525fbfb758;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Fix generated_classes with dry_run => 1 --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index c7f9bd7..3f3ddb4 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -1773,7 +1773,7 @@ sub _load_tables { # Reload without unloading first to preserve any symbols from external # packages. - $self->_reload_classes(\@tables, { unload => 0 }) unless $self->dry_run; + $self->_reload_classes(\@tables, { unload => 0 }); # Drop temporary cache delete $self->{_cache}; @@ -1796,6 +1796,8 @@ sub _reload_classes { unshift @INC, $self->dump_directory; + return if $self->dry_run; + my @to_register; my %have_source = map { $_ => $self->schema->source($_) } $self->schema->sources; diff --git a/t/23dumpmore.t b/t/23dumpmore.t index f94cc3f..47364f5 100644 --- a/t/23dumpmore.t +++ b/t/23dumpmore.t @@ -387,6 +387,7 @@ $t->dump_test( constraint => [ [ qr/my_schema/ => qr/foo|bar/ ] ], exclude => [ [ qr/my_schema/ => qr/bar/ ] ], }, + generated_results => [qw(MySchema::Floop)], warnings => [ qr/^db_schema is not supported on SQLite/, ], @@ -576,6 +577,7 @@ $t->dump_test( options => { use_namespaces => 1, }, + generated_results => [qw(Foo Bar)], regexes => { 'Result/Foo' => [ qr/sub custom_method { 'custom_method works' }\n0;\n\n# You can replace.*\n1;\n\z/, @@ -589,6 +591,7 @@ $t->dump_test( options => { dry_run => 1, }, + generated_results => [qw(Foo Bar)], ); my $schema_file = $t->class_file('DBICTest::DumpMore::DryRun'); diff --git a/t/lib/dbixcsl_dumper_tests.pm b/t/lib/dbixcsl_dumper_tests.pm index d37900c..cc25509 100644 --- a/t/lib/dbixcsl_dumper_tests.pm +++ b/t/lib/dbixcsl_dumper_tests.pm @@ -75,11 +75,13 @@ sub _dump_directly { }; my $err = $@; + my $classes = !$err && $schema_class->loader->generated_classes; + Class::Unload->unload($schema_class); _check_error($err, $tdata{error}); - return @warns; + return \@warns, $classes; } sub _dump_dbicdump { @@ -128,7 +130,7 @@ sub _dump_dbicdump { _check_error($exception, $tdata{error}); } - return @warnings; + return \@warnings; } sub _get_connect_info { @@ -166,18 +168,27 @@ sub _check_error { } sub _test_dumps { - my ($tdata, @warns) = @_; + my ($tdata, $warns, $classes) = @_; my %tdata = %{$tdata}; my $schema_class = $tdata{classname}; my $check_warns = $tdata{warnings}; - is(@warns, @$check_warns, "$schema_class warning count") - or diag @warns; + is(@$warns, @$check_warns, "$schema_class warning count") + or diag @$warns; for(my $i = 0; $i <= $#$check_warns; $i++) { - like(($warns[$i] || ''), $check_warns->[$i], "$schema_class warning $i"); + like(($warns->[$i] || ''), $check_warns->[$i], "$schema_class warning $i"); + } + + if ($classes && (my $results = $tdata{generated_results})) { + my $ns = $tdata{options}{use_namespaces} ? ("::".($tdata{result_namespace} || "Result")) : ""; + is_deeply( + [ sort grep { $_ ne $schema_class } @$classes ], + [ sort map { "${schema_class}${ns}::$_" } @$results ], + "$schema_class generated_classes set correctly", + ); } my $file_regexes = $tdata{regexes};