File: 31finder-config.t

package info (click to toggle)
libcommandable-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 228 kB
  • sloc: perl: 1,530; makefile: 2
file content (82 lines) | stat: -rw-r--r-- 1,804 bytes parent folder | download
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use Commandable::Finder::Packages;

my $cmd_opts;
my $cmd_args;

package MyTest::Command::cmd {
   use constant COMMAND_NAME => "cmd";
   use constant COMMAND_DESC => "the cmd command";

   use constant COMMAND_ARGS => (
      { name => "args", description => "the argument", slurpy => 1 },
   );

   use constant COMMAND_OPTS => (
      { name => "opt", description => "the option", multi => 1 },
      { name => "verbose|v", description => "verbose", mode => "inc" },
   );

   sub run {
      $cmd_opts = shift;
      $cmd_args = [ @_ ];
   }
}

# don't require order
{
   my $finder = Commandable::Finder::Packages->new(
      base => "MyTest::Command",

      allow_multiple_commands => 1,
   );

   undef $cmd_opts;
   undef $cmd_args;
   $finder->find_and_invoke_list( qw( cmd --opt one arg --opt two more ) );

   is( $cmd_opts, { opt => [qw( one two) ] }, 'unordered options' );
   is( $cmd_args, [ [ qw( arg more ) ] ], 'unordered args' );

}

# require order
{
   my $finder = Commandable::Finder::Packages->new(
      base => "MyTest::Command",

      allow_multiple_commands => 1,
      require_order           => 1
   );

   undef $cmd_opts;
   undef $cmd_args;
   $finder->find_and_invoke_list( qw( cmd --opt one arg --opt two more ) );

   is( $cmd_opts, { opt => [qw( one ) ] }, 'ordered options' );
   is( $cmd_args, [ [ qw( arg --opt two more ) ] ], 'ordered args' );
}

# bundling
{
   my $finder = Commandable::Finder::Packages->new(
      base => "MyTest::Command",

      bundling => 1,
   );

   undef $cmd_opts;
   undef $cmd_args;
   $finder->find_and_invoke_list( qw( cmd -vvv arg ) );

   is( $cmd_opts, { verbose => 3 }, 'bundled options' );
   is( $cmd_args, [ [ qw( arg ) ] ], 'bundled args' );
}

done_testing();