X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Funit_core_component_loading.t;h=5b6a4a7873b47297650ecd0c173505c73261a3a9;hb=f04fdedae056296d0fa97fbdcaa85b9811ca6a5b;hp=ffd20a5b35c6abde3902b677f5716b69e71ea51f;hpb=18de900e2fecac0ce4e6d3056d4e31bb6e71d81d;p=catagits%2FCatalyst-Runtime.git diff --git a/t/unit_core_component_loading.t b/t/unit_core_component_loading.t index ffd20a5..5b6a4a7 100644 --- a/t/unit_core_component_loading.t +++ b/t/unit_core_component_loading.t @@ -1,7 +1,7 @@ # 2 initial tests, and 6 per component in the loop below # (do not forget to update the number of components in test 3 as well) -# 4 extra tests for the loading options -use Test::More tests => 2 + 6 * 24 + 4; +# 5 extra tests for the loading options +use Test::More tests => 2 + 6 * 24 + 5; use strict; use warnings; @@ -40,6 +40,18 @@ my @components = ( { type => 'View', prefix => 'View', name => 'Foo' }, ); +sub write_component_file { + my ($dir_list, $module_name, $content) = @_; + + my $dir = File::Spec->catdir(@$dir_list); + my $file = File::Spec->catfile($dir, $module_name . '.pm'); + + mkpath(join(q{/}, @$dir_list) ); + open(my $fh, '>', $file) or die "Could not open file $file for writing: $!"; + print $fh $content; + close $fh; +} + sub make_component_file { my ($type, $prefix, $name) = @_; @@ -48,13 +60,8 @@ sub make_component_file { my @namedirs = split(/::/, $name); my $name_final = pop(@namedirs); my @dir_list = ($libdir, $appclass, $prefix, @namedirs); - my $dir_ux = join(q{/}, @dir_list); - my $dir = File::Spec->catdir(@dir_list); - my $file = File::Spec->catfile($dir, $name_final . '.pm'); - mkpath($dir_ux); # mkpath wants unix '/' seperators :p - open(my $fh, '>', $file) or die "Could not open file $file for writing: $!"; - print $fh <components; is(scalar keys %$complist, 24+1, "Correct number of components loaded"); -my $seen_foo_controller = 0; -my $seen_extra = 0; -foreach (keys %$complist) { - $seen_foo_controller++ if $_ eq "${appclass}::Controller::Foo"; - $seen_extra++ if $_ eq "${appclass}::Extra::Foo"; +ok( !exists $complist->{ "${appclass}::Controller::Foo" }, 'Controller::Foo was skipped' ); +ok( exists $complist->{ "${appclass}::Extra::Foo" }, 'Extra::Foo was loaded' ); + +rmtree($libdir); + +$appclass = "ComponentOnce"; + +write_component_file([$libdir, $appclass, 'Model'], 'TopLevel', <NEXT::COMPONENT(\@_); + no strict 'refs'; + *{\__PACKAGE__ . "::whoami"} = sub { return \__PACKAGE__; }; + \$self; } -is( $seen_foo_controller, 0, 'Controller::Foo was skipped' ); -is( $seen_extra, 1, 'Extra::Foo was loaded' ); +package ${appclass}::Model::TopLevel::Nested; -rmtree($libdir); \ No newline at end of file +sub COMPONENT { die "COMPONENT called in the wrong order!"; } + +1; + +EOF + +write_component_file([$libdir, $appclass, 'Model', 'TopLevel'], 'Nested', <NEXT::COMPONENT(\@_); } +1; + +EOF + +eval "package $appclass; use Catalyst; __PACKAGE__->setup"; + +is($@, '', "Didn't load component twice"); + +rmtree($libdir);