Skip to content

Commit

Permalink
Use CSharpier
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Aug 22, 2023
1 parent a4726fc commit 21b601d
Show file tree
Hide file tree
Showing 99 changed files with 975 additions and 1,163 deletions.
1 change: 1 addition & 0 deletions CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Basic.Reference.Assemblies.Net70" Version="1.4.2" />
<PackageReference Include="coverlet.collector" Version="6.0.0" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.25.0" PrivateAssets="all" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.2" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
Expand Down
14 changes: 5 additions & 9 deletions CliFx.Analyzers.Tests/CommandMustBeAnnotatedAnalyzerSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public void Analyzer_reports_an_error_if_a_command_is_not_annotated_with_the_com
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
public class MyCommand : ICommand
{
public ValueTask ExecuteAsync(IConsole console) => default;
Expand All @@ -30,8 +29,7 @@ public void Analyzer_does_not_report_an_error_if_a_command_is_annotated_with_the
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public abstract class MyCommand : ICommand
{
Expand All @@ -48,8 +46,7 @@ public void Analyzer_does_not_report_an_error_if_a_command_is_implemented_as_an_
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
public abstract class MyCommand : ICommand
{
public ValueTask ExecuteAsync(IConsole console) => default;
Expand All @@ -65,8 +62,7 @@ public void Analyzer_does_not_report_an_error_on_a_class_that_is_not_a_command()
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
public class Foo
{
public int Bar { get; init; } = 5;
Expand All @@ -76,4 +72,4 @@ public class Foo
// Act & assert
Analyzer.Should().NotProduceDiagnostics(code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests;

public class CommandMustImplementInterfaceAnalyzerSpecs
{
private static DiagnosticAnalyzer Analyzer { get; } = new CommandMustImplementInterfaceAnalyzer();
private static DiagnosticAnalyzer Analyzer { get; } =
new CommandMustImplementInterfaceAnalyzer();

[Fact]
public void Analyzer_reports_an_error_if_a_command_does_not_implement_ICommand_interface()
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand
{
Expand All @@ -31,8 +31,7 @@ public void Analyzer_does_not_report_an_error_if_a_command_implements_ICommand_i
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -49,8 +48,7 @@ public void Analyzer_does_not_report_an_error_on_a_class_that_is_not_a_command()
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
public class Foo
{
public int Bar { get; init; } = 5;
Expand All @@ -60,4 +58,4 @@ public class Foo
// Act & assert
Analyzer.Should().NotProduceDiagnostics(code);
}
}
}
7 changes: 3 additions & 4 deletions CliFx.Analyzers.Tests/GeneralSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ public class GeneralSpecs
public void All_analyzers_have_unique_diagnostic_IDs()
{
// Arrange
var analyzers = typeof(AnalyzerBase)
.Assembly
var analyzers = typeof(AnalyzerBase).Assembly
.GetTypes()
.Where(t => !t.IsAbstract && t.IsAssignableTo(typeof(DiagnosticAnalyzer)))
.Select(t => (DiagnosticAnalyzer) Activator.CreateInstance(t)!)
.Select(t => (DiagnosticAnalyzer)Activator.CreateInstance(t)!)
.ToArray();

// Act
Expand All @@ -27,4 +26,4 @@ public void All_analyzers_have_unique_diagnostic_IDs()
// Assert
diagnosticIds.Should().OnlyHaveUniqueItems();
}
}
}
14 changes: 5 additions & 9 deletions CliFx.Analyzers.Tests/OptionMustBeInsideCommandAnalyzerSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public void Analyzer_reports_an_error_if_an_option_is_inside_a_class_that_is_not
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
public class MyClass
{
[CommandOption("foo")]
Expand All @@ -31,8 +30,7 @@ public void Analyzer_does_not_report_an_error_if_an_option_is_inside_a_command()
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -52,8 +50,7 @@ public void Analyzer_does_not_report_an_error_if_an_option_is_inside_an_abstract
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
public abstract class MyCommand
{
[CommandOption("foo")]
Expand All @@ -70,8 +67,7 @@ public void Analyzer_does_not_report_an_error_on_a_property_that_is_not_an_optio
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -84,4 +80,4 @@ public class MyCommand : ICommand
// Act & assert
Analyzer.Should().NotProduceDiagnostics(code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests;

public class OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs
{
private static DiagnosticAnalyzer Analyzer { get; } = new OptionMustBeRequiredIfPropertyRequiredAnalyzer();
private static DiagnosticAnalyzer Analyzer { get; } =
new OptionMustBeRequiredIfPropertyRequiredAnalyzer();

[Fact]
public void Analyzer_reports_an_error_if_a_non_required_option_is_bound_to_a_required_property()
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -34,8 +34,7 @@ public void Analyzer_does_not_report_an_error_if_a_required_option_is_bound_to_a
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -55,8 +54,7 @@ public void Analyzer_does_not_report_an_error_if_a_non_required_option_is_bound_
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -76,8 +74,7 @@ public void Analyzer_does_not_report_an_error_if_a_required_option_is_bound_to_a
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -97,8 +94,7 @@ public void Analyzer_does_not_report_an_error_on_a_property_that_is_not_an_optio
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -111,4 +107,4 @@ public class MyCommand : ICommand
// Act & assert
Analyzer.Should().NotProduceDiagnostics(code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests;

public class OptionMustHaveNameOrShortNameAnalyzerSpecs
{
private static DiagnosticAnalyzer Analyzer { get; } = new OptionMustHaveNameOrShortNameAnalyzer();
private static DiagnosticAnalyzer Analyzer { get; } =
new OptionMustHaveNameOrShortNameAnalyzer();

[Fact]
public void Analyzer_reports_an_error_if_an_option_does_not_have_a_name_or_short_name()
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -34,8 +34,7 @@ public void Analyzer_does_not_report_an_error_if_an_option_has_a_name()
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -55,8 +54,7 @@ public void Analyzer_does_not_report_an_error_if_an_option_has_a_short_name()
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -76,8 +74,7 @@ public void Analyzer_does_not_report_an_error_on_a_property_that_is_not_an_optio
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -90,4 +87,4 @@ public class MyCommand : ICommand
// Act & assert
Analyzer.Should().NotProduceDiagnostics(code);
}
}
}
14 changes: 5 additions & 9 deletions CliFx.Analyzers.Tests/OptionMustHaveUniqueNameAnalyzerSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public void Analyzer_reports_an_error_if_an_option_has_the_same_name_as_another_
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -37,8 +36,7 @@ public void Analyzer_does_not_report_an_error_if_an_option_has_a_unique_name()
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -61,8 +59,7 @@ public void Analyzer_does_not_report_an_error_if_an_option_does_not_have_a_name(
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -82,8 +79,7 @@ public void Analyzer_does_not_report_an_error_on_a_property_that_is_not_an_optio
{
// Arrange
// lang=csharp
const string code =
"""
const string code = """
[Command]
public class MyCommand : ICommand
{
Expand All @@ -96,4 +92,4 @@ public class MyCommand : ICommand
// Act & assert
Analyzer.Should().NotProduceDiagnostics(code);
}
}
}
Loading

0 comments on commit 21b601d

Please sign in to comment.