File: tidy-and-critic.t

package info (click to toggle)
libcode-tidyall-perl 0.55~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 876 kB
  • ctags: 259
  • sloc: perl: 3,882; lisp: 47; makefile: 25
file content (60 lines) | stat: -rw-r--r-- 1,808 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl
use lib 't/lib';
use Code::TidyAll::Util qw(tempdir_simple);
use Code::TidyAll;
use Path::Tiny qw(path);
use Test::More;
use Capture::Tiny qw(capture_merged);

my $root_dir = tempdir_simple('Code-TidyAll-XXXX');

sub make {
    my ( $file, $content ) = @_;
    $file = $root_dir->child($file);
    $file->parent->mkpath( { mode => 0755 } );
    $file->spew($content);
}

make(
    "lib/Foo.pm",
    'package Foo;
  use strict;
1;
'
);
make( "bin/bar.pl",    "#!/usr/bin/perl\n  \$d = 5;" );
make( "lib/Foo.pod",   "=over\n\n=item a\n\n" . scalar( "Blah " x 25 ) . "\n\n=back\n" );
make( "data/baz.txt",  "    34" );
make( ".perlcriticrc", "include = RequireUseStrict" );

my $ct = Code::TidyAll->new(
    root_dir => $root_dir,
    plugins  => {
        PerlTidy   => { select => '**/*.{pl,pm}' },
        PerlCritic => { select => '**/*.{pl,pm}', argv => "--profile $root_dir/.perlcriticrc" },
        PodTidy    => { select => '**/*.pod' },
    }
);
my $output;
$output = capture_merged { $ct->process_all() };
like( $output, qr/Code before strictures are enabled./ );
is( $root_dir->child(qw(lib Foo.pm))->slurp, "package Foo;\nuse strict;\n1;\n" );
is(
    $root_dir->child(qw(lib Foo.pod))->slurp,
    "=over\n\n=item a\n\n"
        . join( " ", ("Blah") x 16 ) . "\n"
        . join( " ", ("Blah") x 9 )
        . "\n\n=back\n"
);
is( $root_dir->child(qw(data baz.txt))->slurp, "    34" );

$output = capture_merged { $ct->process_all() };
like( $output, qr/Code before strictures are enabled./ );
unlike( $output, qr/Foo\.pm/ );

make( "bin/bar.pl", "#!/usr/bin/perl\nuse strict;\n  \$d = 5;" );
$output = capture_merged { $ct->process_all() };
like( $output, qr/.*bar\.pl/ );
is( $root_dir->child(qw(bin bar.pl))->slurp, "#!/usr/bin/perl\nuse strict;\n\$d = 5;\n" );

done_testing();