convert all uses of Test::Exception to Test::Fatal
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_script_create.t
CommitLineData
0a33c6d3 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
2a56ace9 5use Test::Fatal;
0a33c6d3 6
7use FindBin qw/$Bin/;
8use lib "$Bin/../lib";
9
10{
11 package TestCreateScript;
12 use Moose;
13 extends 'Catalyst::Script::Create';
14 our $help;
8ba29999 15 sub print_usage_text { $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;
2a56ace9 44 is exception {
0a33c6d3 45 TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass')->run;
2a56ace9 46 }, undef, "no argv";
0a33c6d3 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;
2a56ace9 54 is exception {
0a33c6d3 55 TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass')->run;
2a56ace9 56 }, undef, "with argv";
0a33c6d3 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;
2a56ace9 67 is exception {
0a33c6d3 68 TestCreateScript->new_with_options(application_name => 'TestAppToTestScripts', helper_class => 'TestHelperClass::False')->run;
2a56ace9 69 }, undef, "with argv";
0a33c6d3 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
75done_testing;