Skip to content

Commit

Permalink
recognize autogenerated C# SpecFlow files, #753
Browse files Browse the repository at this point in the history
and ignore them with --no-autogen
  • Loading branch information
AlDanial committed Sep 15, 2023
1 parent 8040585 commit dd66c76
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,7 @@ sub exclude_autogenerated_files { # {{{1
print "-> exclude_autogenerated_files()\n" if $opt_v > 2;
my @file_list_minus_autogen = ();
foreach my $file (@{$ra_file_list}) {
if ($file !~ /\.go$/) {
if ($file !~ /\.go$/ && $file !~ /\.ʕ◔ϖ◔ʔ$/) {
# at the moment, only know Go autogenerated files
push @file_list_minus_autogen, $file;
next;
Expand Down Expand Up @@ -6289,8 +6289,13 @@ sub classify_file { # {{{1
if ($L eq 'C#') {
my $lines = first_line($full_file, 2, $rh_Err, $raa_errors);
$lines =~ s/\n//mg;
if ($lines =~ m[^//-{70,}.*?//\s+<auto-generated>]) {
if ($lines =~ m[//\s+<auto-generated>]) {
$L = "C# Generated";
if ($opt_no_autogen) {
$rh_ignored->{$full_file} =
'--no-autogen ignores this auto-generated C# file';
$L = "(unknown)"; # forces it to be ignored
}
}
}
return $L;
Expand Down Expand Up @@ -8318,6 +8323,7 @@ sub set_constants { # {{{1
'g4' => 'ANTLR Grammar' ,
'gleam' => 'Gleam' ,
'go' => 'Go' ,
'ʕ◔ϖ◔ʔ' => 'Go' ,
'gsp' => 'Grails' ,
'jenkinsfile' => 'Groovy' ,
'gvy' => 'Groovy' ,
Expand Down
14 changes: 14 additions & 0 deletions Unix/t/01_opts.t
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,20 @@ my @Tests = (
'ref' => '../tests/outputs/issues/722/results_1.yaml',
},

{
'name' => 'C# including autogenerated, #753',
'cd' => '../tests/inputs/issues/753',
'args' => '.',
'ref' => '../tests/outputs/issues/753/all.yaml',
},

{
'name' => 'C# with --no-autogen, #753',
'cd' => '../tests/inputs/issues/753',
'args' => '--no-autogen .',
'ref' => '../tests/outputs/issues/753/no_autogen.yaml',
},

);

# Special cases:
Expand Down
7 changes: 6 additions & 1 deletion cloc
Original file line number Diff line number Diff line change
Expand Up @@ -6304,8 +6304,13 @@ sub classify_file { # {{{1
if ($L eq 'C#') {
my $lines = first_line($full_file, 2, $rh_Err, $raa_errors);
$lines =~ s/\n//mg;
if ($lines =~ m[^//-{70,}.*?//\s+<auto-generated>]) {
if ($lines =~ m[//\s+<auto-generated>]) {
$L = "C# Generated";
if ($opt_no_autogen) {
$rh_ignored->{$full_file} =
'--no-autogen ignores this auto-generated C# file';
$L = "(unknown)"; # forces it to be ignored
}
}
}
return $L;
Expand Down
30 changes: 30 additions & 0 deletions tests/inputs/Application_Data_Test.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions tests/inputs/issues/753/Application_Data_Test.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/inputs/issues/753/assembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Reflection;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.

[assembly: AssemblyCompany("eventIS Interactive Solutions BV")]
[assembly: AssemblyProduct("Traxis")]
[assembly: AssemblyCopyright("Copyright <A9> 2006 - 2008 eventIS Interactive Solutions BV")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyTrademark("")]

// Values in this file will be overwritten by the build process

[assembly: AssemblyVersion("0.0.0.0")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0.0")]
58 changes: 58 additions & 0 deletions tests/inputs/issues/753/csharp-designer.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions tests/outputs/issues/753/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 1.99
elapsed_seconds : 0.00866103172302246
n_files : 3
n_lines : 105
files_per_second : 346.379056899827
lines_per_second : 12123.2669914939
report_file : /home/al/git-cloc/tests/outputs/issues/753/all.yaml
'C# Designer' :
nFiles: 1
blank: 8
comment: 22
code: 28
'C# Generated' :
nFiles: 1
blank: 2
comment: 11
code: 17
'C#' :
nFiles: 1
blank: 4
comment: 4
code: 9
SUM:
blank: 14
comment: 37
code: 54
nFiles: 3
26 changes: 26 additions & 0 deletions tests/outputs/issues/753/no_autogen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 1.99
elapsed_seconds : 0.00845623016357422
n_files : 2
n_lines : 75
files_per_second : 236.512010826661
lines_per_second : 8869.20040599977
report_file : /home/al/git-cloc/tests/outputs/issues/753/no_autogen.yaml
'C# Designer' :
nFiles: 1
blank: 8
comment: 22
code: 28
'C#' :
nFiles: 1
blank: 4
comment: 4
code: 9
SUM:
blank: 12
comment: 26
code: 37
nFiles: 2

0 comments on commit dd66c76

Please sign in to comment.