Mojolicious

 view release on metacpan or  search on metacpan

t/mojo/util.t  view on Meta::CPAN

  is $charset, 'UTF-8', 'right string';
  my $array = ['-t', 'test', '-h', '--whatever', 'Whatever!', 'stuff'];
  getopt $array, ['pass_through'], 't|test=s' => \my $test;
  is $test, 'test', 'right string';
  is_deeply $array, ['-h', '--whatever', 'Whatever!', 'stuff'], 'right structure';
  getopt $array, 'h' => \my $flag, 'w|whatever=s' => \my $whatever;
  ok $flag, 'flag has been set';
  is $whatever, 'Whatever!', 'right string';
  is_deeply $array, ['stuff'], 'right structure';
  {
    local @ARGV = ('--charset', 'UTF-16', 'test');
    getopt 'c|charset=s' => \my @charset;
    is_deeply \@charset, ['UTF-16'], 'right structure';
    is_deeply \@ARGV,    ['test'],   'right structure';
  }
};

subtest 'getopt (return value)' => sub {
  local $SIG{__WARN__} = sub { };

  my $return = getopt ['--lang', 'de'], 'l|lang=s' => \my $lang;

t/mojolicious/commands.t  view on Meta::CPAN

package Mojolicious::Command::my_test_command;
use Mojo::Base 'Mojolicious::Command';

has description => 'See, it works';

package main;

# Make sure @ARGV is not changed
{
  local $ENV{MOJO_MODE};
  local @ARGV = qw(-m production -x whatever);
  require Mojolicious::Commands;
  is $ENV{MOJO_MODE}, 'production', 'right mode';
  is_deeply \@ARGV, [qw(-m production -x whatever)], 'unchanged';
}

# Environment detection
my $commands = Mojolicious::Commands->new;
{
  local $ENV{PLACK_ENV} = 'production';
  is $commands->detect, 'psgi', 'right environment';

t/mojolicious/commands.t  view on Meta::CPAN

subtest 'Commands starting with a dash are not allowed' => sub {
  local $ENV{HARNESS_ACTIVE} = 0;
  eval { $app->start('-test2-command') };
  like $@, qr/Invalid command "-test2-command"\./, 'not allowed';
};

# Do not pick up options for detected environments
{
  local $ENV{MOJO_MODE};
  local $ENV{PLACK_ENV} = 'testing';
  local @ARGV = qw(psgi -m production);
  is ref Mojolicious::Commands->start_app('MojoliciousTest'), 'CODE', 'right reference';
  is $ENV{MOJO_MODE},                                         undef,  'no mode';
}

# mojo
is_deeply $commands->namespaces, ['Mojolicious::Command::Author', 'Mojolicious::Command'], 'right namespaces';
ok $commands->description, 'has a description';
like $commands->message, qr/COMMAND/, 'has a message';
like $commands->hint,    qr/help/,    'has a hint';
$buffer = '';



( run in 0.716 second using v1.01-cache-2.11-cpan-49f99fa48dc )