File: 03-params.t

package info (click to toggle)
libmoox-cmd-perl 0.017-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 320 kB
  • sloc: perl: 1,110; sh: 6; makefile: 2
file content (112 lines) | stat: -rw-r--r-- 3,565 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;

use MooX::Cmd::Tester;

use FindBin qw($Bin);
use lib "$Bin/lib";

use FirstTestApp;
use SecondTestApp;
use ThirdTestApp;

{
    local @ARGV;
    my $cmd = SecondTestApp->new_with_cmd(command_execute_method_name => "run");
    my $rv = test_cmd_ok($cmd, []);
    my @execute_return = @{$rv->execute_rv};
    is_deeply(\@execute_return, [$cmd], 'Checking result of "SecondTestApp(command_base => "SecondTestApp::Cmd") => []"');
}

{
    local @ARGV;
    my $cmd = SecondTestApp->new_with_cmd(command_base => "SecondTestApp::Cmd");
    my $rv = test_cmd_ok($cmd, []);
    my @execute_return = @{$rv->execute_rv};
    is_deeply(\@execute_return, [$cmd], 'Checking result of "SecondTestApp(command_base => "SecondTestApp::Cmd") => []"');
}

{
    local @ARGV;
    my $cmd = SecondTestApp->new_with_cmd(command_creation_chain_methods => "new");
    my $rv = test_cmd_ok($cmd, []);
    my @execute_return = @{$rv->execute_rv};
    is_deeply(\@execute_return, [$cmd], 'Checking result of "SecondTestApp(command_creation_chain_methods => "new") => []"');
}

{
    local @ARGV;
    my $cmd = SecondTestApp->new_with_cmd(
        command_commands => {
            ifc => "SecondTestApp::Cmd::ifc",
            cwo => "SecondTestApp::Cmd::cwo"
        }
    );
    my $rv = test_cmd_ok($cmd, []);
    my @execute_return = @{$rv->execute_rv};
    is_deeply(\@execute_return, [$cmd],
        'Checking result of "SecondTestApp(command_commands => {ifc => "SecondTestApp::Cmd::ifc", cwo => "SecondTestApp::Cmd::cwo"}) => []"'
    );
}

{
    local @ARGV;
    my $cmd = SecondTestApp->new_with_cmd(
        command_base                   => "SecondTestApp::Cmd",
        command_creation_chain_methods => "new"
    );
    my $rv = test_cmd_ok($cmd, []);
    my @execute_return = @{$rv->execute_rv};
    is_deeply(\@execute_return, [$cmd], 'Checking result of "SecondTestApp(command_base => "SecondTestApp::Cmd") => []"');
}

{
    local @ARGV = qw(foo);
    my $cmd = ThirdTestApp->new_with_cmd(command_execute_from_new => undef);
    my $rv = test_cmd_ok($cmd, [qw(foo)]);
    is($rv->execute_rv, undef, 'Checking result of "ThirdTestApp(command_execute_from_new => undef) => []"');
}

{
    local @ARGV = qw(foo);
    my $cmd = ThirdTestApp->new_with_cmd(command_execute_from_new => 0);
    my $rv = test_cmd_ok($cmd, [qw(foo)]);
    is_deeply($rv->execute_rv, undef, 'Checking result of "ThirdTestApp(command_execute_from_new => 0) => []"');
}

{
    local @ARGV;
    my $cmd = SecondTestApp->new_with_cmd(command_execute_return_method_name => "was_haste");
    my $rv = test_cmd_ok($cmd, []);
    my @execute_return = @{$rv->execute_rv};
    is_deeply(\@execute_return, [$cmd],
        'Checking result of "SecondTestApp(command_execute_return_method_name => "was_haste") => []"');
}

{
    local @ARGV;
    eval { my $cmd = SecondTestApp->new_with_cmd(command_creation_chain_methods => "search_me"); };
    like(
        $@,
        qr/Can't find a creation method on/,
        'Load fails for SecondTestApp(command_creation_chain_methods => "search_me") => []'
    );
}

SKIP:
{
    eval "use MooX::Options 4.100; use OptionTestApp";
    $@ and skip("MooX::Options required 4.100 $@", 1);
    local @ARGV = qw(oops);
    my $cmd = eval { OptionTestApp->new_with_cmd(command_creation_chain_methods => "new_with_options"); };
    like(
        $@,
        qr/Can't find a creation method on/,
        'Load fails for OptionTestApp(command_creation_chain_methods => "new_with_options") => []'
    );
}

done_testing;