| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use Getopt::Long qw(:config no_ignore_case bundling); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use Eshu; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | my $fix = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | my $diff = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | my $check = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | my $lang; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | my $tabs = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | my $spaces; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | my $indent_pp = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | my $no_indent_pp = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | my $range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | my @exclude; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | my @include; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | my $verbose = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 'fix' => \$fix, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 'diff' => \$diff, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 'check' => \$check, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 'lang=s' => \$lang, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 'tabs' => \$tabs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 'spaces=i' => \$spaces, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 'indent-pp' => \$indent_pp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 'no-indent-pp' => \$no_indent_pp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'range=s' => \$range, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'exclude=s' => \@exclude, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'include=s' => \@include, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'verbose|v' => \$verbose, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ) or usage(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | print STDERR <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | Usage: eshu [OPTIONS] [FILE|DIR ...] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | Options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | --fix Edit file(s) in-place | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | --diff Show unified diff of changes (no write) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | --check Exit 1 if file(s) would change (for CI) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | --lang <LANG> Override language detection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | --tabs Use tabs for indentation (default) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | --spaces <N> Use N spaces per indent level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | --indent-pp Indent C preprocessor directives | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | --no-indent-pp Leave preprocessor at column 0 (default) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | --range START,END Only reindent lines START through END (1-based) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | --exclude <PATTERN> Skip files matching regex pattern (repeatable) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | --include <PATTERN> Only process files matching regex pattern (repeatable) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | --verbose, -v Print each file processed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | If no FILE is given, reads from stdin and writes to stdout. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | If a directory is given, processes all recognised files recursively. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | exit 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 10 | my %opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | ▶ | if (defined $spaces) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $opts{indent_char} = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | $opts{indent_width} = $spaces; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } elsif ($tabs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | $opts{indent_char} = "\t"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | $opts{indent_width} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 10 | ▶ | $opts{indent_pp} = 1 if $indent_pp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 10 | ▶ | $opts{indent_pp} = 0 if $no_indent_pp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 10 | ▶ | if (defined $range) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($range =~ /^(\d+),(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $opts{range_start} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $opts{range_end} = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | die "eshu: --range must be START,END (e.g. --range 10,25)\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 10 | my $exit_code = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 10 | ▶ | if (@ARGV) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 7 | for my $arg (@ARGV) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 7 | ▶ | if (-d $arg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | process_dir($arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | process_file($arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | process_stdin(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 10 | exit $exit_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub process_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_dir: not called CC=35 SCAR=71.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my ($dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my %dir_opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $dir_opts{lang} = $lang if defined $lang; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $dir_opts{fix} = 1 if $fix; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $dir_opts{diff} = 1 if $diff; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (defined $spaces) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $dir_opts{indent_char} = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $dir_opts{indent_width} = $spaces; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } elsif ($tabs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $dir_opts{indent_char} = "\t"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $dir_opts{indent_width} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $dir_opts{indent_pp} = 1 if $indent_pp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $dir_opts{indent_pp} = 0 if $no_indent_pp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if (@exclude) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $dir_opts{exclude} = [ map { qr/$_/ } @exclude ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if (@include) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $dir_opts{include} = [ map { qr/$_/ } @include ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $report = Eshu->indent_dir($dir, %dir_opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($check) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | for my $c (@{$report->{changes}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ($c->{status} eq 'needs_fixing') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | print STDERR "$c->{file}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $exit_code = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } elsif ($diff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | for my $c (@{$report->{changes}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ($c->{diff}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | print $c->{diff}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ($verbose || (!$check && !$diff && !$fix)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$verbose or not $check || $diff || $fix
$check || $diff || $fix
$check or $diff
MC/DC0%0/4
$verbose or not $check || $diff || $fix
$verbose
$check
$diff
$fix
Truth table0%0/5
A or not(B or C || D)
A= $verboseB= $checkC= $diffD= $fix
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | for my $c (@{$report->{changes}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $lang_str = $c->{lang} ? "[$c->{lang}]" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($c->{status} eq 'skipped') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | printf "%s: skipped (%s)\n", $c->{file}, $c->{reason} || '?' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$c->{'reason'} || '?'
MC/DC0%0/1
$c->{'reason'} || '?'
$c->{'reason'}
Truth table0%0/2
A
A= $c->{'reason'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | if $verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } elsif ($c->{status} eq 'error') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | printf "%s: error (%s)\n", $c->{file}, $c->{error} || '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$c->{'error'} || '?'
MC/DC0%0/1
$c->{'error'} || '?'
$c->{'error'}
Truth table0%0/2
A
A= $c->{'error'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } elsif ($c->{status} eq 'changed') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | printf "%s: %s fixed\n", $c->{file}, $lang_str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } elsif ($c->{status} eq 'needs_fixing') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | printf "%s: %s needs fixing\n", $c->{file}, $lang_str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } elsif ($c->{status} eq 'unchanged') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | printf "%s: %s ok\n", $c->{file}, $lang_str if $verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | printf "---\n%d files checked, %d changed, %d skipped, %d errors\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | $report->{files_checked}, $report->{files_changed}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | $report->{files_skipped}, $report->{files_errored} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if $verbose || (!$check && !$diff && !$fix); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$verbose or not $check || $diff || $fix
$check || $diff || $fix
$check or $diff
MC/DC0%0/4
$verbose or not $check || $diff || $fix
$verbose
$check
$diff
$fix
Truth table0%0/5
A or not(B or C || D)
A= $verboseB= $checkC= $diffD= $fix
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 7 | ▶ | sub process_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_file: called CC=11 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 7 | my ($file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | ▶ | open my $fh, '<', $file or die "eshu: cannot open '$file': $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 7 | my $src = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 7 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | ▶ | my $detected = $lang || Eshu->detect_lang($file) || 'c'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$lang || 'Eshu'->detect_lang($file) || 'c'
$lang or "Eshu"->detect_lang($file)
MC/DC0%0/2
$lang || 'Eshu'->detect_lang($file) || 'c'
$lang
"Eshu"->detect_lang($file)
Truth table33%1/3
A or B
A= $langB= "Eshu"->detect_lang($file)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 7 | my $result = Eshu->indent_string($src, lang => $detected, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 7 | ▶ | if ($check) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | ▶ | if ($result ne $src) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | print STDERR "$file\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | $exit_code = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | ▶ | if ($diff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | ▶ | if ($result ne $src) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | print_diff($file, $src, $result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | ▶ | if ($fix) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | ▶ | if ($result ne $src) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | open my $out, '>', $file or die "eshu: cannot write '$file': $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | print $out $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | close $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # Default: write to stdout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | print $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | ▶ | sub process_stdin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_stdin: called CC=6 SCAR=23.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 3 | ▶ | my $detected = $lang || 'c'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$lang || 'c'
MC/DC0%0/1
$lang || 'c'
$lang
Truth table50%1/2
A
A= $lang
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | my $src = do { local $/; <STDIN> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 3 | my $result = Eshu->indent_string($src, lang => $detected, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 3 | ▶ | if ($check) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $exit_code = 1 if $result ne $src; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | ▶ | if ($diff) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | print_diff('stdin', $src, $result) if $result ne $src; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 3 | print $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | ▶ | sub print_diff { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_diff: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | my ($label, $old, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | my @old_lines = split /^/m, $old; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | my @new_lines = split /^/m, $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | print "--- a/$label\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | print "+++ b/$label\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # Simple line-by-line diff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | ▶ | my $max = @old_lines > @new_lines ? scalar @old_lines : scalar @new_lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | my $hunk_start = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | my @hunk_old; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | my @hunk_new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | ▶ | for (my $i = 0; $i <= $max; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | ▶ | my $ol = $i < @old_lines ? $old_lines[$i] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | ▶ | my $nl = $i < @new_lines ? $new_lines[$i] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | ▶ | my $same = defined $ol && defined $nl && $ol eq $nl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
defined $ol && defined $nl && $ol eq $nl
defined $ol and defined $nl
MC/DC66%2/3
defined $ol && defined $nl && $ol eq $nl
defined $ol
defined $nl
$ol eq $nl
Truth table75%3/4
A and B && C
A= defined $olB= defined $nlC= $ol eq $nl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 4 | ▶ | if (!$same && $hunk_start < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $same and $hunk_start < 0
MC/DC50%1/2
not $same and $hunk_start < 0
not $same
$hunk_start < 0
Truth table66%2/3
not(A) and B
A= not $sameB= $hunk_start < 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | $hunk_start = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | @hunk_old = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | @hunk_new = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | ▶ | if ($hunk_start >= 0 && !$same) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$hunk_start >= 0 and not $same
MC/DC100%2/2
$hunk_start >= 0 and not $same
$hunk_start >= 0
not $same
Truth table100%3/3
A and not(B)
A= $hunk_start >= 0B= not $same
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | ▶ | push @hunk_old, $ol if defined $ol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | ▶ | push @hunk_new, $nl if defined $nl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | if ($same || $i == $max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$same or $i == $max
MC/DC100%2/2
$same or $i == $max
$same
$i == $max
Truth table100%3/3
A or B
A= $sameB= $i == $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 3 | ▶ | if ($hunk_start >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | my $old_count = scalar @hunk_old; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | my $new_count = scalar @hunk_new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | printf "@@ -%d,%d +%d,%d @@\n", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | $hunk_start + 1, $old_count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | $hunk_start + 1, $new_count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | for my $l (@hunk_old) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | ▶ | $l = "$l\n" unless $l =~ /\n$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | print "-$l"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | for my $l (@hunk_new) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | ▶ | $l = "$l\n" unless $l =~ /\n$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | print "+$l"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | $hunk_start = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||