Skip to content

Commit

Permalink
Merge pull request #857 from JoeRobich/generated-code-comment
Browse files Browse the repository at this point in the history
Add test to ensure code containing <auto-generated> comment is treated as generated.
  • Loading branch information
JoeRobich committed Nov 9, 2020
2 parents 4715b0a + 72e5742 commit 3569925
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
30 changes: 15 additions & 15 deletions tests/CodeFormatterTests.cs
Expand Up @@ -86,7 +86,7 @@ public async Task FilesFormattedInUnformattedProject()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 2,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand All @@ -101,7 +101,7 @@ public async Task NoFilesFormattedInUnformattedProjectWhenFixingCodeStyle()
codeStyleSeverity: DiagnosticSeverity.Error,
expectedExitCode: 0,
expectedFilesFormatted: 0,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand All @@ -113,8 +113,8 @@ public async Task GeneratedFilesFormattedInUnformattedProject()
exclude: EmptyFilesList,
includeGenerated: true,
expectedExitCode: 0,
expectedFilesFormatted: 4,
expectedFileCount: 5);
expectedFilesFormatted: 5,
expectedFileCount: 6);

var logLines = log.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
Assert.Contains(logLines, line => line.Contains("unformatted_project.AssemblyInfo.cs"));
Expand All @@ -131,7 +131,7 @@ public async Task FilesFormattedInUnformattedSolution()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 2,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand All @@ -145,7 +145,7 @@ public async Task FilesFormattedInUnformattedProjectFolder()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 2,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand Down Expand Up @@ -193,7 +193,7 @@ public async Task OnlyFormatPathsFromList()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 2,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand All @@ -208,7 +208,7 @@ public async Task OnlyFormatFilesFromList()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 1,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand All @@ -223,7 +223,7 @@ public async Task NoFilesFormattedWhenNotInList()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 0,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand All @@ -238,7 +238,7 @@ public async Task OnlyLogFormattedFiles()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 1,
expectedFileCount: 5);
expectedFileCount: 6);

var pattern = string.Format(Resources.Formatted_code_file_0, @"(.*)");
var match = new Regex(pattern, RegexOptions.Multiline).Match(log);
Expand All @@ -257,7 +257,7 @@ public async Task FormatLocationsLoggedInUnformattedProject()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 2,
expectedFileCount: 5);
expectedFileCount: 6);

var formatLocations = log.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)
.Where(line => FindFormattingLogLine.Match(line).Success)
Expand Down Expand Up @@ -328,7 +328,7 @@ public async Task LogFilesThatDontMatchExclude()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 1,
expectedFileCount: 5);
expectedFileCount: 6);

var pattern = string.Format(Resources.Formatted_code_file_0, @"(.*)");
var match = new Regex(pattern, RegexOptions.Multiline).Match(log);
Expand All @@ -349,7 +349,7 @@ public async Task IgnoreFileWhenListedInExcludeList()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 0,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand All @@ -365,7 +365,7 @@ public async Task IgnoreFileWhenContainingFolderListedInExcludeList()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 0,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand All @@ -381,7 +381,7 @@ public async Task IgnoreAllFileWhenExcludingAllFiles()
includeGenerated: false,
expectedExitCode: 0,
expectedFilesFormatted: 0,
expectedFileCount: 5);
expectedFileCount: 6);
}

[Fact]
Expand Down
Expand Up @@ -2,7 +2,7 @@
root = true

# C# files
[{Program.cs,other_items/*.cs,obj/**/*.cs}]
[{Program.cs,GeneratedTest.cs,other_items/*.cs,obj/**/*.cs}]

#### Core EditorConfig Options ####

Expand Down
@@ -0,0 +1,17 @@

// This is a file that should be ignored.
//
// <auto-generated />

using System;

namespace for_code_formatter
{
class GeneratedTest
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

0 comments on commit 3569925

Please sign in to comment.