Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test fixes for Windows #1804

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 19 additions & 7 deletions tests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -86,21 +87,26 @@ void M()

int count = 5;


count = 6;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Why was this added?


}

}
";

var expectedCode = @"
// Hack for Windows: StyleCop uses the Environment NewLine for its replacement,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tagging @sharwell to comment on this.

// so we have take care of it
var expectedCode = @$"
class C
{
{{
void M()
{
{{
object obj = new object();

int count = 5;
}
}
{Environment.NewLine} int count = 5;
{Environment.NewLine} count = 6;
}}
}}
";

var editorConfig = new Dictionary<string, string>()
Expand Down Expand Up @@ -163,6 +169,9 @@ void M()

// Prefer using. IDISP017
["dotnet_diagnostic.IDISP017.severity"] = "error",

// We expect new line as end_of_line in this test
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption("\n"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Why was this added?

};

await AssertCodeChangedAsync(testCode, expectedCode, editorConfig, fixCategory: FixCategory.Analyzers, analyzerReferences: analyzerReferences);
Expand Down Expand Up @@ -210,6 +219,9 @@ void M()

// Prefer using. IDISP017
["dotnet_diagnostic.IDISP017.severity"] = "error",

// We expect new line as end_of_line in this test
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption("\n"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Why was this added? This test has expectedCode that relies on the environment newline, and the default end_of_line value would be the same. This test wouldn't have been failing before this change, provided the user on Windows checked out the code with the required core.autocrlf=true configuration.

};

await AssertCodeChangedAsync(testCode, expectedCode, editorConfig, fixCategory: FixCategory.Analyzers, analyzerReferences: analyzerReferences);
Expand Down
12 changes: 8 additions & 4 deletions tests/CodeFormatterTests.cs
Expand Up @@ -587,9 +587,13 @@ public async Task GeneratorSolution_NoDiagnosticsReported_WhenNotIncludingGenera
[MSBuildFact]
public async Task GeneratorSolution_AdditionalDocumentsUpdated_WhenIncludingGenerated()
{
const string ExpectedPublicApi = @"Greeter
Greeter.Greet() -> void
Greeter.Greeter() -> void";
var sb = new System.Text.StringBuilder();
sb.Append("Greeter");
sb.Append(Environment.NewLine);
sb.Append("Greeter.Greet() -> void");
sb.Append(Environment.NewLine);
sb.Append("Greeter.Greeter() -> void");
var expectedPublicApi = sb.ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Why was this changed?


// Copy solution to temp folder so we can write changes to disk.
var solutionPath = CopyToTempFolder(s_generatorSolutionPath);
Expand Down Expand Up @@ -617,7 +621,7 @@ public async Task GeneratorSolution_AdditionalDocumentsUpdated_WhenIncludingGene

// Verify that changes were persisted to disk.
var unshippedPublicApi = File.ReadAllText(Path.Combine(solutionPath, "console_app", "PublicAPI.Unshipped.txt"));
Assert.Equal(ExpectedPublicApi, unshippedPublicApi);
Assert.Equal(expectedPublicApi, unshippedPublicApi);
}
finally
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Formatters/OrganizeImportsFormatterTests.cs
Expand Up @@ -41,7 +41,7 @@ class C

var editorConfig = new Dictionary<string, string>()
{
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption(Environment.NewLine),
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption("\n"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Why was this changed? Applies to all instances of this in the file.

["dotnet_sort_system_directives_first"] = "false",
["dotnet_separate_import_directive_groups"] = "false"
};
Expand Down Expand Up @@ -72,7 +72,7 @@ class C

var editorConfig = new Dictionary<string, string>()
{
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption(Environment.NewLine),
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption("\n"),
["dotnet_sort_system_directives_first"] = "true",
["dotnet_separate_import_directive_groups"] = "false"
};
Expand Down Expand Up @@ -104,7 +104,7 @@ class C

var editorConfig = new Dictionary<string, string>()
{
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption(Environment.NewLine),
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption("\n"),
["dotnet_sort_system_directives_first"] = "false",
["dotnet_separate_import_directive_groups"] = "true"
};
Expand Down Expand Up @@ -136,7 +136,7 @@ class C

var editorConfig = new Dictionary<string, string>()
{
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption(Environment.NewLine),
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption("\n"),
["dotnet_sort_system_directives_first"] = "true",
["dotnet_separate_import_directive_groups"] = "true"
};
Expand All @@ -158,7 +158,7 @@ class C

var editorConfig = new Dictionary<string, string>()
{
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption(Environment.NewLine)
["end_of_line"] = EndOfLineFormatter.GetEndOfLineOption("\n")
};

await AssertCodeUnchangedAsync(code, editorConfig);
Expand Down