X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fgenerated_app.t;h=2b50377f456465e3e80491ae2a2d9f48631067a5;hb=3f9e067ca892ae2b896de150dd22973de622dd1e;hp=68d65c94722e108728987bd316e1d67fb44f1edc;hpb=e62ab07578a0433bdd4be9dd55a5cd6221973a70;p=catagits%2FCatalyst-Devel.git diff --git a/t/generated_app.t b/t/generated_app.t index 68d65c9..2b50377 100644 --- a/t/generated_app.t +++ b/t/generated_app.t @@ -2,16 +2,15 @@ use strict; use warnings; use lib (); use Cwd qw( abs_path ); -use File::Temp qw/ tempdir /; -use File::Spec; -use FindBin qw/$Bin/; -use Catalyst::Devel; +use File::Spec::Functions qw( devnull catdir catfile updir rel2abs ); +use File::Temp qw( tempdir ); +use File::Basename qw( dirname ); use Catalyst::Helper; use Test::More; use Config; +use IPC::Open3 qw( open3 ); -eval "use IPC::Run3"; -plan skip_all => 'These tests require IPC::Run3' if $@; +my $helper_lib = abs_path(catdir(dirname($INC{'Catalyst/Helper.pm'}), updir)); my $share_dir = abs_path('share'); plan skip_all => "No share dir at $share_dir!" @@ -20,17 +19,25 @@ plan skip_all => "No share dir at $share_dir!" $ENV{CATALYST_DEVEL_SHAREDIR} = $share_dir; my $instdir = tempdir(CLEANUP => 1); -$ENV{PERL_MM_OPT} = "INSTALL_BASE=$instdir"; -$ENV{INSTALL_BASE} = $instdir; +my $MAKE = $Config{make} || 'make'; + +my $escaped_path = $instdir; +$escaped_path =~ s/\\/\\\\/g; +if ($escaped_path =~ s/ /\\ /g) { + $escaped_path = qq{"$escaped_path"}; +} + +$ENV{PERL_MM_OPT} = "INSTALL_BASE=$escaped_path"; + if ($ENV{MAKEFLAGS}) { $ENV{MAKEFLAGS} =~ s/PREFIX=[^\s]+//; $ENV{MAKEFLAGS} =~ s/INSTALL_BASE=[^\s]+//; } my $dir = tempdir(CLEANUP => 1); -my $devnull = File::Spec->devnull; +my $devnull = devnull; -diag "Generated app is in $dir"; +note "Generated app is in $dir"; chdir $dir or die "Cannot chdir to $dir: $!"; @@ -48,9 +55,9 @@ chdir $dir or die "Cannot chdir to $dir: $!"; $helper->mk_app('TestApp'); } -my $app_dir = File::Spec->catdir($dir, 'TestApp'); +my $app_dir = catdir($dir, 'TestApp'); chdir($app_dir) or die "Cannot chdir to $app_dir: $!"; -lib->import(File::Spec->catdir($dir, 'TestApp', 'lib')); +lib->import(catdir($dir, 'TestApp', 'lib')); my @files = qw| Makefile.PL @@ -81,19 +88,18 @@ my @files = qw| script/testapp_create.pl |; -foreach my $fn (map { File::Spec->catdir(@$_) } map { [ File::Spec::Unix->splitdir($_) ] } @files) { +foreach my $fn (map { catdir(@$_) } map { [ split qr{/}, $_ ] } @files) { test_fn($fn); } create_ok($_, 'My' . $_) for qw/Model View Controller/; command_ok( [ $^X, 'Makefile.PL' ] ); ok -e "Makefile", "Makefile generated"; -#NOTE: do not assume that 'make' is always 'make' as e.g. Win32/strawberry perl uses 'dmake' -command_ok( [ ($Config{make} || 'make') ] ); +command_ok( [ $MAKE ] ); run_generated_component_tests(); -my $server_script_file = File::Spec->catdir(qw/script testapp_server.pl/); +my $server_script_file = catdir(qw/script testapp_server.pl/); my $server_script = do { open(my $fh, '<', $server_script_file) or fail $!; local $/; @@ -127,12 +133,12 @@ my $server_script_new = do { is $server_script, $server_script_new; -diag "Installed app is in $instdir"; -command_ok( [ ($Config{make} || 'make', 'install') ] ); +note "Installed app is in $instdir"; +command_ok( [ $MAKE, 'install' ] ); -my $inst_app_dir = File::Spec->catdir($instdir); +my $inst_app_dir = catdir($instdir); chdir($inst_app_dir) or die "Cannot chdir to $inst_app_dir: $!"; -lib->import(File::Spec->catdir($instdir, 'lib', 'perl5')); +lib->import(catdir($instdir, 'lib', 'perl5')); my @installed_files = qw| lib/perl5/TestApp.pm @@ -155,8 +161,8 @@ my @installed_files = qw| bin/testapp_create.pl |; -foreach my $fn (map { File::Spec->catdir(@$_) } map { [ File::Spec::Unix->splitdir($_) ] } @installed_files) { - my $ffn = File::Spec->catfile($inst_app_dir, $fn); +foreach my $fn (map { catdir(@$_) } map { [ split qr{/}, $_ ] } @installed_files) { + my $ffn = catfile($inst_app_dir, $fn); ok -r $ffn, "'$fn' installed in correct location"; } @@ -165,22 +171,26 @@ done_testing; sub command_ok { my $cmd = shift; - my $desc = shift; + my $desc = shift || "Exit status ok for '@{$cmd}'"; - my $stdout; - my $stderr; - run3( $cmd, \undef, \$stdout, \$stderr ); + open my $stdin, '<', $devnull + or die "Cannot read $devnull: $!"; - $desc ||= "Exit status ok for '@{$cmd}'"; - unless ( is $? >> 8, 0, $desc ) { - diag "STDOUT:\n$stdout" if defined $stdout; - diag "STDERR:\n$stderr" if defined $stderr; - } + my $pid = open3( $stdin, my $stdout, undef, @$cmd ); + my $output = do { local $/; <$stdout> }; + waitpid $pid, 0; + + my $result = is $?, 0, $desc; + + diag "output:\n$output" + if !$result; + + return $result; } sub runperl { my $comment = pop @_; - command_ok( [ $^X, '-I', File::Spec->catdir($Bin, '..', 'lib'), @_ ], $comment ); + command_ok( [ $^X, '-I', $helper_lib, @_ ], $comment ); } my @generated_component_tests; @@ -206,15 +216,16 @@ sub run_generated_component_tests { local $ENV{TEST_POD} = 1; local $ENV{CATALYST_DEBUG} = 0; foreach my $fn (@generated_component_tests) { + my $full_name = rel2abs($fn); subtest "Generated app test: $fn", sub { - do $fn; + do $full_name; }; } } sub create_ok { my ($type, $name) = @_; - runperl( File::Spec->catdir('script', 'testapp_create.pl'), $type, $name, + runperl( catdir('script', 'testapp_create.pl'), $type, $name, "'script/testapp_create.pl $type $name' ok"); - test_fn(File::Spec->catdir('t', sprintf("%s_%s.t", lc $type, $name))); + test_fn( catdir('t', sprintf("%s_%s.t", lc $type, $name))); }