diff --git a/Unix/cloc b/Unix/cloc index 2c124400..385aec8c 100755 --- a/Unix/cloc +++ b/Unix/cloc @@ -5833,19 +5833,30 @@ sub make_file_list { # {{{1 next; } if ($opt_no_recurse) { + my @candidate_file_list = (); if ($ON_WINDOWS and $HAVE_Win32_Long_Path) { my $d = Win32::LongPath->new(); $d->opendirL($dir); foreach my $entry ($d->readdirL()) { my $F = "$dir/$entry"; - push @file_list, $F if is_file($F); + push @candidate_file_list, $F if is_file($F); } $d->closedirL(); } else { opendir(DIR, $dir); - push @file_list, grep(is_file($_), readdir(DIR)); + push @candidate_file_list, grep(is_file("$dir/$_"), readdir(DIR)); closedir(DIR); } + foreach my $F (@candidate_file_list) { + # pretend to be File::Find's wanted() routine, namely subroutine files(), + # to apply all file filter rules + $File::Find::dir = $dir; + $File::Find::name = $F; + $_ = "$dir/$F"; + files(); # side effect: populates @file_list + } + # ... then prepend the directory name to each file + @file_list = map { "$dir/$_" } @file_list; } else { find({wanted => \&files , preprocess => \&find_preprocessor, diff --git a/Unix/t/01_opts.t b/Unix/t/01_opts.t index 44950b9d..1b668abe 100755 --- a/Unix/t/01_opts.t +++ b/Unix/t/01_opts.t @@ -858,6 +858,13 @@ my @Tests = ( 'ref' => '../tests/outputs/issues/833/results.yaml', }, + { + 'name' => '--match-f with --no-recurse (github issue #851)', + 'cd' => '../tests/inputs/issues/851', + 'args' => "--match-f '.lua\$' --no-recurse level_1", + 'ref' => '../tests/outputs/issues/851/results.yaml', + }, + ); # Special cases: diff --git a/cloc b/cloc index 5304b4e3..19ae467f 100755 --- a/cloc +++ b/cloc @@ -5848,19 +5848,30 @@ sub make_file_list { # {{{1 next; } if ($opt_no_recurse) { + my @candidate_file_list = (); if ($ON_WINDOWS and $HAVE_Win32_Long_Path) { my $d = Win32::LongPath->new(); $d->opendirL($dir); foreach my $entry ($d->readdirL()) { my $F = "$dir/$entry"; - push @file_list, $F if is_file($F); + push @candidate_file_list, $F if is_file($F); } $d->closedirL(); } else { opendir(DIR, $dir); - push @file_list, grep(is_file($_), readdir(DIR)); + push @candidate_file_list, grep(is_file("$dir/$_"), readdir(DIR)); closedir(DIR); } + foreach my $F (@candidate_file_list) { + # pretend to be File::Find's wanted() routine, namely subroutine files(), + # to apply all file filter rules + $File::Find::dir = $dir; + $File::Find::name = $F; + $_ = "$dir/$F"; + files(); # side effect: populates @file_list + } + # ... then prepend the directory name to each file + @file_list = map { "$dir/$_" } @file_list; } else { find({wanted => \&files , preprocess => \&find_preprocessor, diff --git a/tests/inputs/issues/851/level_1/flatbuffers.fbs b/tests/inputs/issues/851/level_1/flatbuffers.fbs new file mode 100644 index 00000000..d6f509d8 --- /dev/null +++ b/tests/inputs/issues/851/level_1/flatbuffers.fbs @@ -0,0 +1,6 @@ + +/* Comment 1 */ +table TestTable { + // Comment 2 + Item: int32; +} \ No newline at end of file diff --git a/tests/inputs/issues/851/level_1/hello.lua b/tests/inputs/issues/851/level_1/hello.lua new file mode 100644 index 00000000..eaa1bab8 --- /dev/null +++ b/tests/inputs/issues/851/level_1/hello.lua @@ -0,0 +1,14 @@ +-- single line comment + +--[[ +multi +line +comment +]] + +--[[ +also a comment +--]] + +print("hello, world") +print([[not a comment]]) diff --git a/tests/inputs/issues/851/level_1/level_2/hello_2.lua b/tests/inputs/issues/851/level_1/level_2/hello_2.lua new file mode 100644 index 00000000..63db07d1 --- /dev/null +++ b/tests/inputs/issues/851/level_1/level_2/hello_2.lua @@ -0,0 +1,15 @@ +-- another instance +-- single line comment + +--[[ +multi +line +comment +]] + +--[[ +also a comment +--]] + +print("hello 2, world") +print([[not a comment]]) diff --git a/tests/outputs/issues/851/results.yaml b/tests/outputs/issues/851/results.yaml new file mode 100644 index 00000000..82c2c01b --- /dev/null +++ b/tests/outputs/issues/851/results.yaml @@ -0,0 +1,21 @@ +--- +# github.com/AlDanial/cloc +header : + cloc_url : github.com/AlDanial/cloc + cloc_version : 2.02 + elapsed_seconds : 0.00290799140930176 + n_files : 1 + n_lines : 14 + files_per_second : 343.879970484545 + lines_per_second : 4814.31958678364 + report_file : /home/al/git-cloc/tests/outputs/issues/851/results.yaml +'Lua' : + nFiles: 1 + blank: 3 + comment: 9 + code: 2 +SUM: + blank: 3 + comment: 9 + code: 2 + nFiles: 1