use inlined module hiding in tests
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_script_create.t
CommitLineData
0a33c6d3 1use strict;
2use warnings;
3use Test::More;
2a56ace9 4use Test::Fatal;
0a33c6d3 5
6use FindBin qw/$Bin/;
7use lib "$Bin/../lib";
8
9{
10 package TestCreateScript;
11 use Moose;
12 extends 'Catalyst::Script::Create';
13 our $help;
8ba29999 14 sub print_usage_text { $help++ }
0a33c6d3 15}
16
17{
18 package TestHelperClass;
19 use Moose;
71e29488 20
0a33c6d3 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;
2a56ace9 43 is exception {
0a33c6d3 44 TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass')->run;
2a56ace9 45 }, undef, "no argv";
0a33c6d3 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;
2a56ace9 53 is exception {
0a33c6d3 54 TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass')->run;
2a56ace9 55 }, undef, "with argv";
0a33c6d3 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;
2a56ace9 66 is exception {
0a33c6d3 67 TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass::False')->run;
2a56ace9 68 }, undef, "with argv";
0a33c6d3 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
74done_testing;