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