App-perlimports

 view release on metacpan or  search on metacpan

t/cli-args.t  view on Meta::CPAN

use strict;
use warnings;

use lib 'test-data/lib', 't/lib';

use App::perlimports::CLI ();
use Capture::Tiny         qw( capture );
use Path::Tiny            ();
use TestHelper            qw( logger );
use Test::Differences     qw( eq_or_diff );
use Test::More import => [qw( diag done_testing is like subtest )];
use Test::Needs qw( Perl::Critic::Utils );

subtest 'almost all of the args' => sub {
    my $expected = <<'EOF';
use strict;
use warnings;

use Perl::Critic::Utils qw($QUOTE);

my %foo = (
    $QUOTE => q{description},
);
EOF

    my $log_file = Path::Tiny->tempfile('perlimportsXXXXXXXX');

    local @ARGV = (
        '--ignore-modules'                  => 'CGI,Plack',
        '--ignore-modules-filename'         => 'test-data/ignore-modules.txt',
        '--ignore-modules-pattern'          => '^(Foo|Foo::Bar)',
        '--ignore-modules-pattern-filename' =>
            'test-data/ignore-modules-pattern.txt',
        '--indent'                        => 2,
        '--libs'                          => 'lib,t/lib',
        '--never-export-modules'          => 'Never::One,Never::Two',
        '--never-export-modules-filename' =>
            'test-data/never-export-modules.txt',
        '--log-filename' => "$log_file",
        '--log-level'    => 'info',
        '--no-cache',
        '--no-padding',
        '--no-preserve-duplicates',
        '--no-preserve-unused',
        '--no-tidy-whitespace',
        '--pad-brackets',
        'test-data/var-in-hash-key.pl',
    );
    my $cli = App::perlimports::CLI->new( logger => logger( [] ) );
    my ( $stdout, $stderr ) = capture {
        $cli->run;
    };
    is( $stdout, $expected, 'no exception on args' ) || diag $stderr;

    my $c = $cli->_config;

    is( $c->cache, 0, 'cache' );
    eq_or_diff(
        $c->ignore, [ 'CGI', 'Plack', 'Data::Printer', 'Git::Sub' ],
        'ignore'
    );
    eq_or_diff(
        $c->ignore_pattern, ['^(Foo|Foo::Bar)'],
        'ignore_pattern'
    );
    eq_or_diff( $c->libs, [ 'lib', 't/lib' ], 'libs' );
    like( $c->log_filename, qr{perlimports}, 'log_filename' );
    is( $c->log_level, 'info', 'log_level' );
    eq_or_diff(
        $c->never_export,



( run in 0.903 second using v1.01-cache-2.11-cpan-6aa56a78535 )