[Catalyst-commits] r11996 - in
Catalyst-Runtime/5.80/branches/better_scripts:
lib/Catalyst/Script t/aggregate
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Tue Nov 24 00:15:45 GMT 2009
Author: t0m
Date: 2009-11-24 00:15:45 +0000 (Tue, 24 Nov 2009)
New Revision: 11996
Added:
Catalyst-Runtime/5.80/branches/better_scripts/t/aggregate/unit_core_script_create.t
Modified:
Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Create.pm
Log:
Add tests for the create script and fix the bugs that this shows up
Modified: Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Create.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Create.pm 2009-11-23 23:56:49 UTC (rev 11995)
+++ Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/Script/Create.pm 2009-11-24 00:15:45 UTC (rev 11996)
@@ -1,6 +1,5 @@
package Catalyst::Script::Create;
use Moose;
-use Catalyst::Helper;
use MooseX::Types::Moose qw/Bool/;
use namespace::autoclean;
@@ -32,14 +31,18 @@
documentation => 'use WWW::Mechanize',
);
+has helper_class => ( isa => 'Str', is => 'ro', default => 'Catalyst::Helper' );
+
sub run {
my ($self) = @_;
$self->_exit_with_usage if !$ARGV[0];
- my $helper = Catalyst::Helper->new( { '.newfiles' => !$self->force, mech => $self->mech } );
+ my $helper_class = $self->helper_class;
+ Class::MOP::load_class($helper_class);
+ my $helper = $helper_class->new( { '.newfiles' => !$self->force, mech => $self->mechanize } );
- $self->_display_help unless $helper->mk_component( $self->app, @ARGV );
+ $self->_exit_with_usage unless $helper->mk_component( $self->application_name, @ARGV );
}
Added: Catalyst-Runtime/5.80/branches/better_scripts/t/aggregate/unit_core_script_create.t
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/t/aggregate/unit_core_script_create.t (rev 0)
+++ Catalyst-Runtime/5.80/branches/better_scripts/t/aggregate/unit_core_script_create.t 2009-11-24 00:15:45 UTC (rev 11996)
@@ -0,0 +1,75 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+use FindBin qw/$Bin/;
+use lib "$Bin/../lib";
+
+{
+ package TestCreateScript;
+ use Moose;
+ extends 'Catalyst::Script::Create';
+ our $help;
+ sub _exit_with_usage { $help++ }
+}
+
+{
+ package TestHelperClass;
+ use Moose;
+
+ has 'newfiles' => ( is => 'ro', init_arg => '.newfiles' );
+ has 'mech' => ( is => 'ro' );
+ our @ARGS;
+ our %p;
+ sub mk_component {
+ my $self = shift;
+ @ARGS = @_;
+ %p = ( '.newfiles' => $self->newfiles, mech => $self->mech);
+ return $self->_mk_component_return;
+ }
+ sub _mk_component_return { 1 }
+}
+{
+ package TestHelperClass::False;
+ use Moose;
+ extends 'TestHelperClass';
+ sub _mk_component_return { 0 }
+}
+
+{
+ local $TestCreateScript::help;
+ local @ARGV;
+ lives_ok {
+ TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass')->run;
+ } "no argv";
+ ok $TestCreateScript::help, 'Exited with usage info';
+}
+{
+ local $TestCreateScript::help;
+ local @ARGV = 'foo';
+ local @TestHelperClass::ARGS;
+ local %TestHelperClass::p;
+ lives_ok {
+ TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass')->run;
+ } "with argv";
+ ok !$TestCreateScript::help, 'Did not exit with usage into';
+ is_deeply \@TestHelperClass::ARGS, ['TestAppToTestScripts', 'foo'], 'Args correct';
+ is_deeply \%TestHelperClass::p, { '.newfiles' => 1, mech => undef }, 'Params correct';
+}
+
+{
+ local $TestCreateScript::help;
+ local @ARGV = 'foo';
+ local @TestHelperClass::ARGS;
+ local %TestHelperClass::p;
+ lives_ok {
+ TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass::False')->run;
+ } "with argv";
+ ok $TestCreateScript::help, 'Did exit with usage into as mk_component returned false';
+ is_deeply \@TestHelperClass::ARGS, ['TestAppToTestScripts', 'foo'], 'Args correct';
+ is_deeply \%TestHelperClass::p, { '.newfiles' => 1, mech => undef }, 'Params correct';
+}
+
+done_testing;
More information about the Catalyst-commits
mailing list