line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mason::Tidy::t::CLI; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
464
|
$Mason::Tidy::t::CLI::VERSION = '2.57'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
873
|
use Capture::Tiny qw(capture capture_merged); |
|
1
|
|
|
|
|
34623
|
|
|
1
|
|
|
|
|
97
|
|
6
|
1
|
|
|
1
|
|
1122
|
use File::Slurp; |
|
1
|
|
|
|
|
16219
|
|
|
1
|
|
|
|
|
80
|
|
7
|
1
|
|
|
1
|
|
11
|
use File::Temp qw(tempdir); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
8
|
1
|
|
|
1
|
|
652
|
use Mason::Tidy; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
9
|
1
|
|
|
1
|
|
654
|
use Mason::Tidy::App; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
10
|
1
|
|
|
1
|
|
1059
|
use IPC::System::Simple qw(capturex); |
|
1
|
|
|
|
|
9475
|
|
|
1
|
|
|
|
|
97
|
|
11
|
1
|
|
|
1
|
|
997
|
use Test::Class::Most parent => 'Test::Class'; |
|
1
|
|
|
|
|
38807
|
|
|
1
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
local $ENV{MASONTIDY_OPT}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @std_argv = ( "--perltidy-argv='--noprofile'", "-m=2" ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub test_cli : Tests { |
18
|
1
|
|
|
1
|
0
|
1180
|
my ( $out, $err ); |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
8
|
my $tempdir = tempdir( 'name-XXXX', TMPDIR => 1, CLEANUP => 1 ); |
21
|
1
|
|
|
|
|
732
|
write_file( "$tempdir/comp1.mc", "<%2+2%>" ); |
22
|
1
|
|
|
|
|
243
|
write_file( "$tempdir/comp2.mc", "<%4+4%>" ); |
23
|
1
|
|
|
|
|
169
|
write_file( "$tempdir/comp3.mc", "%if (foo){\n%bar\n%}\n" ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $cli = sub { |
26
|
9
|
|
|
9
|
|
44
|
local @ARGV = @_; |
27
|
|
|
|
|
|
|
( $out, $err ) = capture { |
28
|
9
|
|
|
|
|
11297
|
Mason::Tidy::App->run(); |
29
|
9
|
|
|
|
|
307
|
}; |
30
|
4
|
|
|
|
|
4425
|
is( $err, "", "err empty" ); |
31
|
1
|
|
|
|
|
162
|
}; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
6
|
$cli->( "-r", "$tempdir/comp1.mc", "$tempdir/comp2.mc", @std_argv ); |
34
|
1
|
|
|
|
|
805
|
is( $out, "$tempdir/comp1.mc\n$tempdir/comp2.mc\n", "out empty" ); |
35
|
1
|
|
|
|
|
1219
|
is( read_file("$tempdir/comp1.mc"), "<% 2 + 2 %>", "comp1" ); |
36
|
1
|
|
|
|
|
857
|
is( read_file("$tempdir/comp2.mc"), "<% 4 + 4 %>", "comp2" ); |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
860
|
write_file( "$tempdir/comp1.mc", "<%2+2%>" ); |
39
|
1
|
|
|
|
|
202
|
$cli->( "$tempdir/comp1.mc", @std_argv ); |
40
|
1
|
|
|
|
|
777
|
is( $out, "<% 2 + 2 %>", "single file - out" ); |
41
|
1
|
|
|
|
|
438
|
is( read_file("$tempdir/comp1.mc"), "<%2+2%>", "comp1" ); |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
439
|
$cli->( "$tempdir/comp3.mc", @std_argv ); |
44
|
1
|
|
|
|
|
913
|
is( $out, "% if (foo) {\n% bar\n% }\n", "no options" ); |
45
|
1
|
|
|
|
|
577
|
$cli->( '--perltidy-line-argv="-i=2"', "$tempdir/comp3.mc", @std_argv ); |
46
|
1
|
|
|
|
|
664
|
is( $out, "% if (foo) {\n% bar\n% }\n", "no options" ); |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
|
354
|
throws_ok { $cli->("$tempdir/comp1.mc") } qr/mason-version required/; |
|
1
|
|
|
|
|
58
|
|
49
|
1
|
|
|
1
|
|
1407
|
throws_ok { $cli->( "-m", "3", "$tempdir/comp1.mc" ) } qr/must be 1 or 2/; |
|
1
|
|
|
|
|
45
|
|
50
|
1
|
|
|
1
|
|
1516
|
throws_ok { $cli->( "-p", "$tempdir/comp1.mc", @std_argv ) } qr/pipe not compatible/; |
|
1
|
|
|
|
|
37
|
|
51
|
1
|
|
|
1
|
|
1443
|
throws_ok { $cli->(@std_argv) } qr/must pass either/; |
|
1
|
|
|
|
|
38
|
|
52
|
1
|
|
|
1
|
|
44
|
throws_ok { $cli->( "$tempdir/comp1.mc", "$tempdir/comp2.mc", @std_argv ) } |
53
|
1
|
|
|
|
|
1411
|
qr/must pass .* with multiple filenames/; |
54
|
1
|
|
|
1
|
|
66084
|
} |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub test_pipe : Tests { |
57
|
1
|
50
|
|
1
|
0
|
1700
|
return "author only" unless ( $ENV{AUTHOR_TESTING} ); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
require IPC::Run3; |
60
|
0
|
|
|
|
|
0
|
local $ENV{MASONTIDY_OPT} = "-p"; |
61
|
0
|
|
|
|
|
0
|
my $in = "<%2+2%>\n<%4+4%>\n"; |
62
|
0
|
|
|
|
|
0
|
my ( $out, $err ); |
63
|
0
|
|
|
|
|
0
|
IPC::Run3::run3( [ $^X, "bin/masontidy", @std_argv ], \$in, \$out, \$err ); |
64
|
0
|
|
|
|
|
0
|
is( $err, "", "pipe - no error" ); |
65
|
0
|
|
|
|
|
0
|
is( $out, "<% 2 + 2 %>\n<% 4 + 4 %>\n", "pipe - output" ); |
66
|
1
|
|
|
1
|
|
467
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub test_usage : Tests { |
69
|
1
|
|
|
1
|
0
|
143
|
my $out; |
70
|
|
|
|
|
|
|
|
71
|
1
|
50
|
|
|
|
9
|
return "author only" unless ( $ENV{AUTHOR_TESTING} ); |
72
|
0
|
|
|
0
|
|
|
$out = capture_merged { system( $^X, "bin/masontidy", "-h" ) }; |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
like( $out, qr/Usage: masontidy/ ); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
|
|
$out = capture_merged { system( $^X, "bin/masontidy", "--version" ) }; |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
like( $out, qr/masontidy .* on perl/ ); |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
1
|
|
382
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |