Rip out all the refactoring as it doesn't really go anywhere and things are still...
[catagits/Catalyst-Devel.git] / t / generated_app.t
index 73bb7f6..46e708c 100644 (file)
@@ -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);
@@ -10,7 +11,7 @@ my $devnull = File::Spec->devnull;
 
 use Test::More;
 
-diag "In $dir";
+diag "Generated app is in $dir";
 
 {
     my $exit;
@@ -54,39 +55,56 @@ 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";
-    }
+foreach my $fn (map { File::Spec->catdir(@$_) } map { [ split /\// ] } @files) {
+    test_fn($fn);
 }
+create_ok($_, 'My' . $_) for qw/Model View Controller/;
 
-## Makefile stuff
-my $makefile_status = `$^X Makefile.PL`;
-ok $makefile_status, "Makefile ran okay";
-ok -e "Makefile", "Makefile exists";
-
+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;
-        }
-    }
-}
-
 my $server_script = do {
-    open(my $fh, '<', 'script/testapp_server.pl') or die $!;
+    open(my $fh, '<', File::Spec->catdir(qw/script testapp_server.pl/)) or fail $!;
     local $/;
     <$fh>;
 };
 
+ok $server_script;
 ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
     'SCRIPT_GEN found in generated output';
 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;
+}
+
+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" );
+    }
+    if ($fn =~ /\.t$/) {
+        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)));
+}