File: testmxcmd.pm

package info (click to toggle)
libmoox-configfromfile-perl 0.009-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 292 kB
  • sloc: perl: 879; sh: 6; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 2,451 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
use MooX::Cmd::Tester;

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

use MooXCmdTest;

my @tests = (
    [[], "MooXCmdTest", "MooXCmdTest", {complicated_setting => {say => "Hello!"}}],
    [
        [qw(test)],
        "MooXCmdTest",
        "MooXCmdTest::Cmd::Test",
        {
            unintialized_attribute => sub { time - $_[0] < 1 }
        }
    ],
    [
        [qw(tested)],
        "MooXCmdTest",
        "MooXCmdTest::Cmd::Tested",
        {confidential_setting => 42}
    ],
    [
        [qw(test this)],
        "MooXCmdTest",
        "MooXCmdTest::Cmd::Test::Cmd::This",
        {dedicated_setting => 4711}
    ],
    [
        [qw(test this hashmerged)],
        "MooXCmdTest",
        "MooXCmdTest::Cmd::Test::Cmd::This::Cmd::HashMerged",
        {
            dedicated_setting => 4711,
            merged_frame      => {
                kept_value          => "sane",
                "overwritten_value" => "dammed"
            }
        }
    ],
    [
        [qw(test shortcut)],
        "MooXCmdTest",
        "MooXCmdTest::Cmd::Test::Cmd::Shortcut",
        {complex_attribute => [4711]}
    ],
    [
        [qw(test shortcut hashmerged)],
        "MooXCmdTest",
        "MooXCmdTest::Cmd::Test::Cmd::Shortcut::Cmd::HashMerged",
        {complex_attribute => [501, 4711]}
    ],
);

for (@tests)
{
  SKIP:
    {
        my ($args, $class, $cmd_class, $attrs) = @{$_};
        ref $args or $args = [split(' ', $args)];
        my $rv = test_cmd($class => $args);
        #diag(explain($rv));

        my $test_ident = "$class => " . join(" ", "[", @$args, "]");
        ok($rv->cmd, "got cmd for $test_ident") or diag(explain($rv));
        isa_ok($rv->cmd, $class) or skip("Cannot do attribute testing without command", 2);
        isa_ok($rv->cmd->command_chain_end, $cmd_class)
          or skip("Cannot do attribute testing without specific command", 1)
          if scalar @$args;
        my $cmd = scalar @$args ? $rv->cmd->command_chain_end : $rv->cmd;
        foreach my $k (keys %$attrs)
        {
            my $cmd_attr = $cmd->$k;
            ref $attrs->{$k} or is($attrs->{$k}, $cmd_attr, "Attribute $k for $test_ident");
            "CODE" eq ref $attrs->{$k} and ok($attrs->{$k}->($cmd_attr), "Attribute $k ok for $test_ident");
            ref $attrs->{$k}
              and "CODE" ne ref $attrs->{$k}
              and is_deeply($attrs->{$k}, $cmd_attr, "Attribute $k for $test_ident");
        }
    }
}

1;