Skip to content

Commit

Permalink
--match-d, --not-match-d with trailing / in pattern, #833
Browse files Browse the repository at this point in the history
  • Loading branch information
AlDanial committed May 31, 2024
1 parent 8e3c7bd commit ba6c1aa
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,18 @@ if (!$opt_config_file) {
$opt_config_file = $other_loc if $other_loc;
}

# --match-d and --not-match-d: if end with a trailing slash, update the
# regex to be either slash or end of line since File::Find::find() will
# not see the trailing slash in leaf directories (#732, #833).
if ($opt_match_d and $opt_match_d =~ m{/$}) {
$opt_match_d =~ s{/$}{(/|\$)};
}
foreach my $nmd (@opt_not_match_d) {
if ($nmd =~ m{/$}) {
$nmd =~ s{/$}{(/|\$)};
}
}

die $brief_usage unless defined $opt_version or
defined $opt_show_lang or
defined $opt_show_ext or
Expand Down
8 changes: 8 additions & 0 deletions Unix/t/01_opts.t
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,14 @@ my @Tests = (
'args' => '--vcs git --fullpath --not-match-d "a/b" issues/822',
'ref' => '../tests/outputs/issues/822/T8.yaml',
},

{
'name' => '--not-match-d with trailing slash (github issue #833)',
'cd' => '../tests/inputs/issues/833',
'args' => '. --not-match-d="/foo/"',
'ref' => '../tests/outputs/issues/833/results.yaml',
},

);

# Special cases:
Expand Down
12 changes: 12 additions & 0 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,18 @@ if (!$opt_config_file) {
$opt_config_file = $other_loc if $other_loc;
}

# --match-d and --not-match-d: if end with a trailing slash, update the
# regex to be either slash or end of line since File::Find::find() will
# not see the trailing slash in leaf directories (#732, #833).
if ($opt_match_d and $opt_match_d =~ m{/$}) {
$opt_match_d =~ s{/$}{(/|\$)};
}
foreach my $nmd (@opt_not_match_d) {
if ($nmd =~ m{/$}) {
$nmd =~ s{/$}{(/|\$)};
}
}

die $brief_usage unless defined $opt_version or
defined $opt_show_lang or
defined $opt_show_ext or
Expand Down
1 change: 1 addition & 0 deletions tests/inputs/issues/833/Developer/abc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
struct bar { }
2 changes: 2 additions & 0 deletions tests/inputs/issues/833/Developer/clocTest/foo/foo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
struct foo {
}
21 changes: 21 additions & 0 deletions tests/outputs/issues/833/results.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 2.01
elapsed_seconds : 0.00325608253479004
n_files : 1
n_lines : 1
files_per_second : 307.117522149813
lines_per_second : 307.117522149813
report_file : ../../../outputs/issues/833/results.yaml
'Text' :
nFiles: 1
blank: 0
comment: 0
code: 1
SUM:
blank: 0
comment: 0
code: 1
nFiles: 1

0 comments on commit ba6c1aa

Please sign in to comment.