Skip to content

Commit

Permalink
fix improper handling of --not-match-d, #731
Browse files Browse the repository at this point in the history
and correct legacy test results that were wrong
  • Loading branch information
AlDanial committed Nov 26, 2023
1 parent a4d7a6a commit 18062b5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 52 deletions.
42 changes: 21 additions & 21 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,12 @@ Usage: $script [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <repo
the directory where cloc is invoked.
See also --list-file, --config.
--fullpath Modifies the behavior of --match-f, --not-match-f,
and --not-match-d to include the file's path
in the regex, not just the file's basename.
(This does not expand each file to include its
absolute path, instead it uses as much of
the path as is passed in to cloc.)
Note: --match-d always looks at the full
path and therefore is unaffected by --fullpath.
and --not-match-d to include the file's path--
relative to the directory from which cloc is
invoked--in the regex, not just the file's basename.
(This does not expand each filename to include its
fully qualified absolute path; instead, it uses as
much of the path as is passed in to cloc.)
--include-ext=<ext1>[,ext2[...]]
Count only languages having the given comma
separated file extensions. Use --show-ext to
Expand All @@ -548,18 +547,17 @@ Usage: $script [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <repo
only counts files in directories containing
/src/ or /include/. Unlike --not-match-d,
--match-f, and --not-match-f, --match-d always
compares the fully qualified path against the
regex.
anchors the regex to the directory from which
cloc is invoked.
--not-match-d=<regex> Count all files except those in directories
matching the Perl regex. Only the trailing
directory name is compared, for example, when
counting in /usr/local/lib, only 'lib' is
compared to the regex.
Add --fullpath to compare parent directories to
the regex.
Do not include file path separators at the
beginning or end of the regex.
This option may be repeated.
Add --fullpath to compare parent directories, beginning
from the directory where cloc is invoked, to the regex.
Do not include file path separators at the beginning
or end of the regex. This option may be repeated.
--match-f=<regex> Only count files whose basenames match the Perl
regex. For example
--match-f='^[Ww]idget'
Expand Down Expand Up @@ -5816,21 +5814,25 @@ sub invoke_generator { # {{{1
return @post_filter;
} # 1}}}
sub any_match { # {{{1
my ($string, $entire, $rs_matched_pattern, @patterns) = @_;
foreach my $pattern (@patterns) {
my ($string, $entire, $rs_matched_pattern, @patterns) = @_;
print "-> any_match($string, $entire)\n" if $opt_v > 2;
foreach my $pattern (@patterns) {
if ($entire) {
if ($string =~ m{^${pattern}$}) {
${$rs_matched_pattern} = $pattern;
print "<- any_match(1)\n" if $opt_v > 2;
return 1;
}
} else {
if ($string =~ m{$pattern}) {
${$rs_matched_pattern} = $pattern;
print "<- any_match(1)\n" if $opt_v > 2;
return 1;
}
}
}
return 0;
print "<- any_match(0)\n" if $opt_v > 2;
return 0;
}
# }}}
sub remove_duplicate_files { # {{{1
Expand Down Expand Up @@ -5969,8 +5971,6 @@ sub find_preprocessor { # {{{1
print "-> find_preprocessor(", cwd(), ")\n" if $opt_v > 2;
my @ok = ();

#printf "TOP find_preprocessor\n";

foreach my $F_or_D (@_) { # pure file or directory name, no separators
next if $F_or_D =~ /^\.{1,2}$/; # skip . and ..
if ($Exclude_Dir{$F_or_D}) {
Expand All @@ -5986,7 +5986,7 @@ sub find_preprocessor { # {{{1
push @ok, $F_or_D;
}
} elsif (!is_dir($F_or_D) and
any_match(basename($File::Find::name), 0, \$rule,
any_match($File::Find::name, 0, \$rule,
@opt_not_match_d)) {
$Ignored{$File::Find::name} = "--not-match-d (basename) =$rule";
} else {
Expand Down Expand Up @@ -8369,7 +8369,7 @@ sub set_constants { # {{{1
'g4' => 'ANTLR Grammar' ,
'gleam' => 'Gleam' ,
'go' => 'Go' ,
'ʕ◔ϖ◔ʔ' => 'Go' ,
'ʕ◔ϖ◔ʔ' => 'Go' ,
'gsp' => 'Grails' ,
'jenkinsfile' => 'Groovy' ,
'gvy' => 'Groovy' ,
Expand Down
25 changes: 10 additions & 15 deletions tests/outputs/issues/114/T2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 1.70
elapsed_seconds : 0.0168919563293457
n_files : 2
n_lines : 2
files_per_second : 118.399548341567
lines_per_second : 118.399548341567
report_file : outputs/issues/114/T2.yaml
issues/114/foo/under_foo.js :
blank: 0
comment: 0
code: 1
language: JavaScript
issues/114/bar/bee/inner_most.js :
cloc_version : 1.99
elapsed_seconds : 0.00754880905151367
n_files : 1
n_lines : 1
files_per_second : 132.471227338766
lines_per_second : 132.471227338766
report_file : ../outputs/issues/114/T2.yaml
'issues/114/foo/under_foo.js' :
blank: 0
comment: 0
code: 1
language: JavaScript
SUM:
blank: 0
comment: 0
code: 2
nFiles: 2
code: 1
nFiles: 1
27 changes: 11 additions & 16 deletions tests/outputs/issues/114/T4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 1.70
elapsed_seconds : 0.0164718627929688
n_files : 3
n_lines : 3
files_per_second : 182.12876331635
lines_per_second : 182.12876331635
report_file : outputs/issues/114/T4.yaml
issues/114/foo/under_foo.js :
cloc_version : 1.99
elapsed_seconds : 0.00816798210144043
n_files : 2
n_lines : 2
files_per_second : 244.858518929332
lines_per_second : 244.858518929332
report_file : ../outputs/issues/114/T4.yaml
'issues/114/bar/under_Bar.js' :
blank: 0
comment: 0
code: 1
language: JavaScript
issues/114/bar/bee/inner_most.js :
blank: 0
comment: 0
code: 1
language: JavaScript
issues/114/bar/under_Bar.js :
'issues/114/foo/under_foo.js' :
blank: 0
comment: 0
code: 1
language: JavaScript
SUM:
blank: 0
comment: 0
code: 3
nFiles: 3
code: 2
nFiles: 2

0 comments on commit 18062b5

Please sign in to comment.