X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fgenerated_app.t;h=2a46078c2b62a64b2d63fa69efec89047f528196;hb=41cebeb1e1e47c8fbab0b112342baaeaea232061;hp=96f038bf6aaeecafcf575f1276d5eb2acc49e19d;hpb=15f460a5b954eb86dbcda1beacff0aecc1b012c5;p=catagits%2FCatalyst-Devel.git diff --git a/t/generated_app.t b/t/generated_app.t index 96f038b..2a46078 100644 --- a/t/generated_app.t +++ b/t/generated_app.t @@ -3,6 +3,7 @@ use warnings; use lib (); use File::Temp qw/ tempdir tmpnam /; use File::Spec; +use FindBin qw/$Bin/; use Catalyst::Devel; my $dir = tempdir(CLEANUP => 1); @@ -54,29 +55,16 @@ my @files = qw| script/testapp_create.pl |; -foreach my $fn (@files) { - ok -r $fn, "Have $fn in generated app"; - if ($fn =~ /script/) { - ok -x $fn, "$fn is executable"; - } - if ($fn =~ /\.p[ml]/) { - is system($^X, '-c', $fn), 0, "$fn compiles"; - } +foreach my $fn (map { File::Spec->catdir(@$_) } map { [ split /\// ] } @files) { + test_fn($fn); } +create_ok($_, 'My' . $_) for qw/Model View Controller/; is system($^X, 'Makefile.PL'), 0, 'Ran Makefile.PL'; ok -e "Makefile", "Makefile generated"; is system("make"), 0, 'Run make'; -{ - local $ENV{TEST_POD} = 1; - local $ENV{CATALYST_DEBUG} = 0; - foreach my $test (grep { m|^t/| } @files) { - subtest "Generated app test: $test", sub { - require $test; - } - } -} +run_generated_component_tests(); my $server_script = do { open(my $fh, '<', File::Spec->catdir(qw/script testapp_server.pl/)) or fail $!; @@ -91,3 +79,42 @@ is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct'; chdir('/'); done_testing; + +sub runperl { + my $comment = pop @_; + is system($^X, '-I', File::Spec->catdir($Bin, '..', 'lib'), @_), 0, $comment; +} + +my @generated_component_tests; + +sub test_fn { + local $ENV{TEST_POD} = 1; + local $ENV{CATALYST_DEBUG} = 0; + + my $fn = shift; + ok -r $fn, "Have $fn in generated app"; + if ($fn =~ /script/) { + ok -x $fn, "$fn is executable"; + } + if ($fn =~ /\.p[ml]$/) { + runperl( '-c', $fn, "$fn compiles" ); + } + # Save these till later as Catalyst::Test will only be loaded once :-/ + push @generated_component_tests, $fn + if $fn =~ /\.t$/; +} + +sub run_generated_component_tests { + foreach my $fn (@generated_component_tests) { + subtest "Generated app test: $fn", sub { + require $fn; + }; + } +} + +sub create_ok { + my ($type, $name) = @_; + runperl( File::Spec->catdir('script', 'testapp_create.pl'), $type, $name, + "'script/testapp_create.pl $type $name' ok"); + test_fn(File::Spec->catdir('t', sprintf("%s_%s.t", $type, $name))); +}