App-Easer

 view release on metacpan or  search on metacpan

t/V1/04-multilevel-jsons.t  view on Meta::CPAN

               environment => 'GALOOK_FOO',
            },
            {
               getopt      => 'bar|b=s',
               environment => 'GALOOK_BAR',
               default     => 'buzz',
            },
            {
               getopt => 'config|c=s',
            },
         ],
         'default-child' => 'bar',
         children        => [qw< foo bar >],
      },
      foo => {
         help        => 'sub-command foo',
         description => 'first-level sub-command foo',
         supports    => ['foo', 'Foo'],
         options     => [
            {
               getopt => 'hey|h=s',
            },
         ],
         children        => ['baz'],
         'default-child' => 'baz',
      },
      bar => {
         help        => 'sub-command bar',
         description => 'first-level sub-command bar',
         options     => [],
         execute     => sub ($main, $conf, $args) {
            LocalTester::command_execute(bar => $main, $conf, $args);
            print {*STDOUT} 'bar on out';
            print {*STDERR} 'bar on err';
            return 'Bar';
         },
      },
      baz => {
         help        => 'sub-sub-command baz',
         description => 'second-level sub-command baz',
         options     => [
            {
               getopt => 'last|l=i',
            },
         ],
         execute => sub ($main, $conf, $args) {
            LocalTester::command_execute(baz => $main, $conf, $args);
            print {*STDOUT} 'baz on out';
            print {*STDERR} 'baz on err';
            return 'BAZ';
         },
      },
   },
};

subtest 'foo baz' => sub {
   test_run($app, [qw< --foo foo --hey you baz --last 12 FP >], {}, 'baz')
     ->no_exceptions->result_is('BAZ')
     ->conf_is({foo => 1, bar => 'buzz', hey => 'you', last => 12})
     ->args_are(['FP'])->stdout_like(qr{baz on out})
     ->stderr_like(qr{baz on err});
};

subtest 'foo baz, with config file' => sub {
   test_run(
      $app,
      [
         qw< --foo --config >,
         tpath('example.json'),
         qw< foo --hey you baz --last 12 FP >
      ],
      {},
      'baz'
   )->no_exceptions->result_is('BAZ')->conf_is(
      {
         foo    => 1,
         bar    => 'buzz',
         hey    => 'you',
         last   => 12,
         what   => 'ever',
         config => tpath('example.json')
      }
   )->args_are(['FP'])->stdout_like(qr{baz on out})
     ->stderr_like(qr{baz on err});
};

$app->{commands}{MAIN}{'config-files'} =
  [qw< /etcxn/not/existent >, tpath('example.json')];

subtest 'foo baz, with config file' => sub {
   test_run($app, [qw< --foo foo --hey you baz --last 12 FP >], {}, 'baz')
     ->no_exceptions->result_is('BAZ')->conf_is(
      {
         foo  => 1,
         bar  => 'buzz',
         hey  => 'you',
         last => 12,
         what => 'ever',
      }
   )->args_are(['FP'])->stdout_like(qr{baz on out})
     ->stderr_like(qr{baz on err});
};

done_testing();



( run in 1.340 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )