add another failing real-life example to test
[gitmo/MooseX-Runnable.git] / t / arg-parser.t
1 use strict;
2 use warnings;
3
4 use MooseX::Runnable::Util::ArgParser;
5
6 use Test::TableDriven (
7     class_name => {
8         'Foo' => 'Foo',
9         '-Ilib Foo' => 'Foo' ,
10         '-I/foo/bar/lib -Ilib -IFoo module with lots of args' => 'module' ,
11         '-- Foo' => 'Foo',
12         '-Ilib -- Foo' => 'Foo',
13         '-Ilib -MFoo::Bar -- Foo::Baz' => 'Foo::Baz',
14         '-MFoo Bar' => 'Bar',
15         '+Plugin1 --args --go --here -- Foo' => 'Foo',
16         '+P --args --arehere +Q --more --args -- Foo' => 'Foo',
17         '-Ilib +P --args --arehere +Q --more --args -Ilib -- Foo' => 'Foo',
18         '+P --args -- Foo -- Bar' => 'Foo',
19         '-Ilib +Debug -- PlanFinder' => 'PlanFinder',
20         '-Ilib -Iexample +Debug --prefix 42 -- MyApp' => 'MyApp',
21     },
22
23     modules => {
24         'Foo' => [],
25         'Foo -MFoo' => [],
26         '-MFoo' => ['Foo'],
27         '-MFoo Foo' => ['Foo'],
28         '-MFoo Foo' => ['Foo'],
29         '-MFoo -MFoo Foo' => ['Foo', 'Foo'],
30         '-MFoo -MBar -MBaz::Quux -Ilib OH::HAI' => ['Foo','Bar','Baz::Quux'],
31         '+End -MFoo -MBar -- OH::HAI' => [],
32         '-Ilib +End -MFoo -- OH::HAI' => [],
33         '-Ilib -MFoo OH::HAI' => ['Foo'],
34         '-Ilib -MFoo +End -MBar -- OH::HAI' => ['Foo'],
35         '-Ilib +Debug -- PlanFinder' => [],
36         '-Ilib -Iexample +Debug --prefix 42 -- MyApp' => [],
37     },
38
39     include_paths => {
40         'Foo' => [],
41         'Foo -Ilib' => [],
42         '-Ilib Foo' => ['lib'],
43         '-MFoo Foo' => [],
44         '-MFoo -MBar -MBaz::Quux -Ilib OH::HAI' => ['lib'],
45         '+End -MFoo -MBar -- OH::HAI' => [],
46         '-Ilib +End -MFoo -- OH::HAI' => ['lib'],
47         '-Ilib -MFoo OH::HAI' => ['lib'],
48         '-Ilib -MFoo +End -IBar -- OH::HAI' => ['lib'],
49         '-Ilib -MFoo -I../../../../lib +End -IBar -- OH::HAI' =>
50               ['lib', '../../../../lib'],
51         '-Ilib +Debug -- PlanFinder' => ['lib'],
52         '-Ilib -Iexample +Debug --prefix 42 -- MyApp' => ['lib', 'example'],
53     },
54
55     plugins => {
56         'Foo' => {},
57         '-Ilib Foo' => {},
58         '-Ilib -MFoo -- Bar' => {},
59         '+One --arg +Two --arg2 -- End' => { One => ['--arg'], Two => ['--arg2'] },
60         '+Debug +PAR +Foo::Bar -- Baz' => { Debug => [], PAR => [], 'Foo::Bar' => [] },
61         '-Ilib +Debug -- PlanFinder' => { Debug => [] },
62         '++Foo -- Bar' => { '+Foo' => [] },
63         '-Ilib -Iexample +Debug --prefix 42 -- MyApp' => { Debug => [ '--prefix', '42' ] },
64     },
65
66     is_help => {
67         '--help' => 1,
68         '-h' => 1,
69         '-?' => 1,
70         '--?' => 0,
71         '--h' => 0,
72         '+Foo --help' => 0,
73         'Foo' => 0,
74         '-Ilib -MFoo --help' => 1,
75         '-- Foo --help' => 0,
76         'Foo --help' => 0,
77         'Foo -?' => 0,
78         'Foo -h' => 0,
79         '-Ilib +Debug -- PlanFinder' => 0,
80         '-Ilib -Iexample +Debug --prefix 42 -- MyApp' => 0,
81     },
82
83     app_args => {
84         'Foo' => [],
85         '-Ilib Foo' => [],
86         '-Ilib -MFoo Bar' => [],
87         'Foo Bar' => ['Bar'],
88         'Foo Bar Baz' => ['Bar', 'Baz'],
89         '-- Foo Bar Baz' => ['Bar', 'Baz'],
90         '-Ilib Foo -Ilib' => ['-Ilib'],
91         '-MFoo Foo -MFoo' => ['-MFoo'],
92         '-MFoo -MFoo Foo -MFoo' => ['-MFoo'],
93         '-- Foo --help' => ['--help'],
94         '-Ilib +Debug -- PlanFinder' => [],
95         '-Ilib -Iexample +Debug --prefix 42 -- MyApp' => [],
96     },
97 );
98
99 sub class_name {
100     my ($argv) = @_;
101     my $p = MooseX::Runnable::Util::ArgParser->new( argv => [split / /, $argv] );
102     return $p->class_name;
103 }
104
105 sub modules {
106     my ($argv) = @_;
107     my $p = MooseX::Runnable::Util::ArgParser->new( argv => [split / /, $argv] );
108     return $p->modules;
109 }
110
111 sub include_paths {
112     my ($argv) = @_;
113     my $p = MooseX::Runnable::Util::ArgParser->new( argv => [split / /, $argv] );
114     return [ map { $_->stringify } $p->include_paths ];
115 }
116
117 sub plugins {
118     my ($argv) = @_;
119     my $p = MooseX::Runnable::Util::ArgParser->new( argv => [split / /, $argv] );
120     return $p->plugins;
121 }
122
123 sub is_help {
124     my ($argv) = @_;
125     my $p = MooseX::Runnable::Util::ArgParser->new( argv => [split / /, $argv] );
126     return $p->is_help ? 1 : 0;
127 }
128
129 sub app_args {
130     my ($argv) = @_;
131     my $p = MooseX::Runnable::Util::ArgParser->new( argv => [split / /, $argv] );
132     return $p->app_args;
133 }
134
135 runtests;