merged conflicts
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_script_create.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use Test::Fatal;
5
6 use FindBin qw/$Bin/;
7 use lib "$Bin/../lib";
8
9 {
10     package TestCreateScript;
11     use Moose;
12     extends 'Catalyst::Script::Create';
13     our $help;
14     sub print_usage_text { $help++ }
15 }
16
17 {
18     package TestHelperClass;
19     use Moose;
20
21     has 'newfiles' => ( is => 'ro', init_arg => '.newfiles' );
22     has 'mech' => ( is => 'ro' );
23     our @ARGS;
24     our %p;
25     sub mk_component {
26         my $self = shift;
27         @ARGS = @_;
28         %p = ( '.newfiles' => $self->newfiles, mech => $self->mech);
29         return $self->_mk_component_return;
30     }
31     sub _mk_component_return { 1 }
32 }
33 {
34     package TestHelperClass::False;
35     use Moose;
36     extends 'TestHelperClass';
37     sub _mk_component_return { 0 }
38 }
39
40 {
41     local $TestCreateScript::help;
42     local @ARGV;
43     is exception {
44         TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass')->run;
45     }, undef, "no argv";
46     ok $TestCreateScript::help, 'Exited with usage info';
47 }
48 {
49     local $TestCreateScript::help;
50     local @ARGV = 'foo';
51     local @TestHelperClass::ARGS;
52     local %TestHelperClass::p;
53     is exception {
54         TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass')->run;
55     }, undef, "with argv";
56     ok !$TestCreateScript::help, 'Did not exit with usage into';
57     is_deeply \@TestHelperClass::ARGS, ['TestAppToTestScripts', 'foo'], 'Args correct';
58     is_deeply \%TestHelperClass::p, { '.newfiles' => 1, mech => undef }, 'Params correct';
59 }
60
61 {
62     local $TestCreateScript::help;
63     local @ARGV = 'foo';
64     local @TestHelperClass::ARGS;
65     local %TestHelperClass::p;
66     is exception {
67         TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass::False')->run;
68     }, undef, "with argv";
69     ok $TestCreateScript::help, 'Did exit with usage into as mk_component returned false';
70     is_deeply \@TestHelperClass::ARGS, ['TestAppToTestScripts', 'foo'], 'Args correct';
71     is_deeply \%TestHelperClass::p, { '.newfiles' => 1, mech => undef }, 'Params correct';
72 }
73
74 done_testing;