preserve $self->{name} in mk_app if defined
[catagits/Catalyst-Devel.git] / t / generated_app.t
index 4ecfda3..a923f69 100644 (file)
@@ -8,6 +8,7 @@ use FindBin qw/$Bin/;
 use Catalyst::Devel;
 use Catalyst::Helper;
 use Test::More;
+use Config;
 
 eval "use IPC::Run3";
 plan skip_all => 'These tests require IPC::Run3' if $@;
@@ -36,7 +37,7 @@ chdir $dir or die "Cannot chdir to $dir: $!";
         }
     );
 
-    $helper->mk_app('TestApp');
+    $helper->mk_app;
 }
 
 my $app_dir = File::Spec->catdir($dir, 'TestApp');
@@ -78,12 +79,14 @@ create_ok($_, 'My' . $_) for qw/Model View Controller/;
 
 command_ok( [ $^X, 'Makefile.PL' ] );
 ok -e "Makefile", "Makefile generated";
-command_ok( [ 'make' ] );
+#NOTE: do not assume that 'make' is always 'make' as e.g. Win32/strawberry perl uses 'dmake'
+command_ok( [ ($Config{make} || 'make') ] );
 
 run_generated_component_tests();
 
+my $server_script_file = File::Spec->catdir(qw/script testapp_server.pl/);
 my $server_script = do {
-    open(my $fh, '<', File::Spec->catdir(qw/script testapp_server.pl/)) or fail $!;
+    open(my $fh, '<', $server_script_file) or fail $!;
     local $/;
     <$fh>;
 };
@@ -93,6 +96,28 @@ 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';
 
+{
+    open(my $fh, '>', $server_script_file) or fail $!;
+    print $fh "MOO\n";
+}
+my $helper = Catalyst::Helper->new(
+    {
+        '.newfiles' => 0,
+        'makefile'  => 0,
+        'scripts'   => 1,
+        name => '.',
+    }
+);
+$helper->mk_app( '.' ) or fail;
+
+my $server_script_new = do {
+    open(my $fh, '<', $server_script_file) or fail $!;
+    local $/;
+    <$fh>;
+};
+
+is $server_script, $server_script_new;
+
 chdir('/');
 done_testing;
 
@@ -122,7 +147,10 @@ sub test_fn {
     my $fn = shift;
     ok -r $fn, "Have $fn in generated app";
     if ($fn =~ /script/) {
-        ok -x $fn, "$fn is executable";
+        SKIP: {
+            skip 'Executable file flag test does not make sense on Win32', 1 if ($^O eq 'MSWin32');
+            ok -x $fn, "$fn is executable";
+       }
     }
     if ($fn =~ /\.p[ml]$/) {
         runperl( '-c', $fn, "$fn compiles" );
@@ -137,7 +165,7 @@ sub run_generated_component_tests {
     local $ENV{CATALYST_DEBUG} = 0;
     foreach my $fn (@generated_component_tests) {
         subtest "Generated app test: $fn", sub {
-            require $fn;
+            do $fn;
         };
     }
 }