|
1 | 1 | use Test2::V0 -target => 'App::Yath::Command'; |
2 | 2 |
|
3 | | -skip_all "write me"; |
| 3 | +subtest 'name() derives from package name' => sub { |
| 4 | + is(CLASS->name, 'App::Yath::Command', 'base class returns full package name when no prefix match'); |
| 5 | + |
| 6 | + { |
| 7 | + package App::Yath::Command::testcmd; |
| 8 | + use parent 'App::Yath::Command'; |
| 9 | + } |
| 10 | + is(App::Yath::Command::testcmd->name, 'testcmd', 'single-level subclass returns short name'); |
| 11 | + |
| 12 | + { |
| 13 | + package App::Yath::Command::foo::bar; |
| 14 | + use parent 'App::Yath::Command'; |
| 15 | + } |
| 16 | + is(App::Yath::Command::foo::bar->name, 'foo-bar', 'nested namespace uses hyphen separator'); |
| 17 | + |
| 18 | + my $obj = CLASS->new(); |
| 19 | + is($obj->name, 'App::Yath::Command', 'name() works on instance'); |
| 20 | +}; |
| 21 | + |
| 22 | +subtest 'group()' => sub { |
| 23 | + is(CLASS->group, 'Z-FIXME', 'base class returns Z-FIXME when no prefix'); |
| 24 | + |
| 25 | + { |
| 26 | + package App::Yath::Command::sub::cmd; |
| 27 | + use parent 'App::Yath::Command'; |
| 28 | + } |
| 29 | + is(App::Yath::Command::sub::cmd->group, undef, 'subcommand (contains hyphen in name) returns undef'); |
| 30 | +}; |
| 31 | + |
| 32 | +subtest 'default metadata' => sub { |
| 33 | + is(CLASS->summary, 'No Summary', 'default summary'); |
| 34 | + is(CLASS->description, 'No Description', 'default description'); |
| 35 | +}; |
| 36 | + |
| 37 | +subtest 'boolean flags default to 0' => sub { |
| 38 | + is(CLASS->accepts_dot_args, 0, 'accepts_dot_args defaults to 0'); |
| 39 | + is(CLASS->args_include_tests, 0, 'args_include_tests defaults to 0'); |
| 40 | + is(CLASS->internal_only, 0, 'internal_only defaults to 0'); |
| 41 | + is(CLASS->load_plugins, 0, 'load_plugins defaults to 0'); |
| 42 | + is(CLASS->load_resources, 0, 'load_resources defaults to 0'); |
| 43 | + is(CLASS->load_renderers, 0, 'load_renderers defaults to 0'); |
| 44 | +}; |
| 45 | + |
| 46 | +subtest 'cli_args and cli_dot return undef by default' => sub { |
| 47 | + is(CLASS->cli_args, undef, 'cli_args returns undef'); |
| 48 | + is(CLASS->cli_dot, undef, 'cli_dot returns undef'); |
| 49 | +}; |
| 50 | + |
| 51 | +subtest 'run() warns and returns 1' => sub { |
| 52 | + my $obj = CLASS->new(); |
| 53 | + my $warned = 0; |
| 54 | + local $SIG{__WARN__} = sub { $warned++ }; |
| 55 | + my $ret = $obj->run(); |
| 56 | + is($ret, 1, 'run() returns 1'); |
| 57 | + is($warned, 1, 'run() emits a warning'); |
| 58 | +}; |
| 59 | + |
| 60 | +subtest 'set_dot_args() croaks' => sub { |
| 61 | + my $obj = CLASS->new(); |
| 62 | + like( |
| 63 | + dies { $obj->set_dot_args() }, |
| 64 | + qr/set_dot_args is not implemented/, |
| 65 | + 'set_dot_args croaks with expected message', |
| 66 | + ); |
| 67 | +}; |
| 68 | + |
| 69 | +subtest 'constructor attributes' => sub { |
| 70 | + my $obj = CLASS->new( |
| 71 | + settings => { foo => 1 }, |
| 72 | + args => [qw/a b/], |
| 73 | + env_vars => { PATH => '/usr/bin' }, |
| 74 | + option_state => {}, |
| 75 | + plugins => [], |
| 76 | + ); |
| 77 | + is($obj->settings, { foo => 1 }, 'settings set via constructor'); |
| 78 | + is($obj->args, [qw/a b/], 'args set via constructor'); |
| 79 | + is($obj->env_vars, { PATH => '/usr/bin' }, 'env_vars set via constructor'); |
| 80 | + is($obj->option_state, {}, 'option_state set via constructor'); |
| 81 | + is($obj->plugins, [], 'plugins set via constructor'); |
| 82 | +}; |
4 | 83 |
|
5 | 84 | done_testing; |
0 commit comments