Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fe0786d
Proof of concept update to library-style testing
sharwell Aug 9, 2018
d01a67c
Move EmptyDiagnosticResults to the verifier helpers
sharwell Aug 10, 2018
bd82367
Introduce helpers VerifyCSharpDiagnosticAsync and VerifyCSharpFixAsync
sharwell Aug 10, 2018
2b565d4
Convert remaining SpacingRules tests to the new test helpers
sharwell Aug 10, 2018
42bf8da
Improve the ability of GenericAnalyzerTest to report misconfigured tests
sharwell Aug 10, 2018
03f41c5
Implement TestEmptySourceAsync and TestHelpLink independently of Diag…
sharwell Aug 10, 2018
a85eedf
Use lists for analyzer test transforms
sharwell Aug 10, 2018
5751ad4
Use standard properties for indentation settings
sharwell Aug 10, 2018
9c0e99b
Convert special rules tests to the new helpers
sharwell Aug 10, 2018
54eea38
Convert readability rules tests to the new helpers
sharwell Aug 11, 2018
4981654
Convert ordering rules tests to the new helpers
sharwell Aug 11, 2018
07a6f35
Convert naming rules to the new helpers
sharwell Aug 11, 2018
6c0f6d9
Convert layout rules to the new test helpers
sharwell Aug 13, 2018
45a4680
Update code fix iteration check to test absence of code actions
sharwell Aug 13, 2018
604cfb5
Convert documentation rules to the new test helpers
sharwell Aug 13, 2018
3206848
Convert maintainability rules to the new test helpers
sharwell Aug 13, 2018
02205f6
Convert remaining ordering rules to the new test helpers
sharwell Aug 13, 2018
f74a693
Convert AnalyzerExtensionsTests and ExclusionTests to the new test he…
sharwell Aug 14, 2018
25d4560
Add support for Additional Files to GenericAnalyzerTest
sharwell Aug 22, 2018
04788cb
Use automatically generated binding redirects
sharwell Aug 22, 2018
2166a2a
Convert the remaining documentation tests to the new test helpers
sharwell Aug 23, 2018
e0fa070
Convert the remaining maintainability tests to the new test helpers
sharwell Aug 23, 2018
c89bc23
Convert SA1412 (Store Files as UTF-8) to the new test helpers
sharwell Aug 23, 2018
a76a0b1
Convert SettingsFileCodeFixProviderUnitTests to the new test helpers
sharwell Aug 23, 2018
d766801
Remove the old test helpers
sharwell Aug 23, 2018
a77c8b6
Use SourceText as the content representation of both sources and addi…
sharwell Aug 23, 2018
af6fa6e
Merge branch 'master' into testing-library
sharwell Sep 3, 2018
3c3d7dc
Use helpers from Microsoft.CodeAnalysis.Testing
sharwell Sep 3, 2018
a45080c
Use DiagnosticResult.CompilerError where appropriate
sharwell Sep 3, 2018
9471fd5
Merge remote-tracking branch 'DotNetAnalyzers/master' into testing-li…
sharwell Sep 4, 2018
b455370
Disable RS1022 because it keeps crashing
sharwell Sep 4, 2018
e390b13
Use DiagnosticResult.EmptyDiagnosticResults where appropriate
sharwell Sep 3, 2018
49b26d0
Use Microsoft.CodeAnalysis.Testing for core test functionality
sharwell Sep 3, 2018
63b3b59
Merge remote-tracking branch 'DotNetAnalyzers/master' into testing-li…
sharwell Sep 6, 2018
7781c99
Merge remote-tracking branch 'DotNetAnalyzers/master' into testing-li…
sharwell Sep 10, 2018
5086cc0
Update to Microsoft.CodeAnalysis.Testing 1.0.0-beta1-63310-01
sharwell Sep 10, 2018
e43fa91
Make sure test fixtures are public types
sharwell Sep 11, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<configuration>
<packageSources>
<add key="roslyn" value="https://dotnet.myget.org/F/roslyn/api/v3/index.json" />
<add key="roslyn-analyzers" value="https://dotnet.myget.org/F/roslyn-analyzers/api/v3/index.json" />
<add key="symreader-converter" value="https://dotnet.myget.org/F/symreader-converter/api/v3/index.json" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion StyleCop.Analyzers/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<PropertyGroup>
<LangVersion>7</LangVersion>
<LangVersion>7.2</LangVersion>
<Features>strict</Features>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class SA1119CodeFixProvider : CodeFixProvider
{
/// <inheritdoc/>
public override ImmutableArray<string> FixableDiagnosticIds { get; } =
ImmutableArray.Create(SA1119StatementMustNotUseUnnecessaryParenthesis.DiagnosticId);
ImmutableArray.Create(SA1119StatementMustNotUseUnnecessaryParenthesis.DiagnosticId, SA1119StatementMustNotUseUnnecessaryParenthesis.ParenthesesDiagnosticId);

/// <inheritdoc/>
public override FixAllProvider GetFixAllProvider()
Expand All @@ -42,6 +42,11 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)

foreach (var diagnostic in context.Diagnostics)
{
if (diagnostic.Id != SA1119StatementMustNotUseUnnecessaryParenthesis.DiagnosticId)
{
continue;
}

SyntaxNode node = root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true, findInsideTrivia: true);
if (node.IsMissing)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace StyleCop.Analyzers.Test.CSharp7
{
public class AnalyzerConfigurationTestsCSharp7 : AnalyzerConfigurationTests
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
namespace StyleCop.Analyzers.Test.CSharp7.DocumentationRules
{
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Test.DocumentationRules;
using Xunit;

public class SA1600CSharp7UnitTests : SA1600UnitTests
{
private string currentTestSettings;
protected override LanguageVersion LanguageVersion => LanguageVersion.CSharp7_2;

[Fact]
public async Task TestPrivateProtectedDelegateWithoutDocumentationAsync()
Expand Down Expand Up @@ -52,10 +51,10 @@ public async Task TestPrivateProtectedConstructorWithDocumentationAsync()
[Fact]
public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
{
await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync(testSettings: null, "private protected", true, false).ConfigureAwait(false);

// Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
this.currentTestSettings = @"
var testSettings = @"
{
""settings"": {
""documentationRules"": {
Expand All @@ -65,10 +64,10 @@ public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
}
";

await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", true, false).ConfigureAwait(false);

// Re-test with the 'documentInternalElements' setting disabled (does impact fields)
this.currentTestSettings = @"
testSettings = @"
{
""settings"": {
""documentationRules"": {
Expand All @@ -78,10 +77,10 @@ public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
}
";

await this.TestFieldDeclarationDocumentationAsync("private protected", false, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", false, false).ConfigureAwait(false);

// Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
this.currentTestSettings = @"
testSettings = @"
{
""settings"": {
""documentationRules"": {
Expand All @@ -91,16 +90,16 @@ public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
}
";

await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", true, false).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedFieldWithDocumentationAsync()
{
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync(testSettings: null, "private protected", false, true).ConfigureAwait(false);

// Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
this.currentTestSettings = @"
var testSettings = @"
{
""settings"": {
""documentationRules"": {
Expand All @@ -110,10 +109,10 @@ public async Task TestPrivateProtectedFieldWithDocumentationAsync()
}
";

await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", false, true).ConfigureAwait(false);

// Re-test with the 'documentInternalElements' setting disabled (does impact fields)
this.currentTestSettings = @"
testSettings = @"
{
""settings"": {
""documentationRules"": {
Expand All @@ -123,10 +122,10 @@ public async Task TestPrivateProtectedFieldWithDocumentationAsync()
}
";

await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", false, true).ConfigureAwait(false);

// Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
this.currentTestSettings = @"
testSettings = @"
{
""settings"": {
""documentationRules"": {
Expand All @@ -136,7 +135,7 @@ public async Task TestPrivateProtectedFieldWithDocumentationAsync()
}
";

await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", false, true).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -187,18 +186,6 @@ public async Task TestPrivateProtectedEventFieldWithDocumentationAsync()
await this.TestEventFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
}

protected override string GetSettings()
{
return this.currentTestSettings ?? base.GetSettings();
}

protected override Project CreateProjectImpl(string[] sources, string language, string[] filenames)
{
var project = base.CreateProjectImpl(sources, language, filenames);
var parseOptions = (CSharpParseOptions)project.ParseOptions;
return project.WithParseOptions(parseOptions.WithLanguageVersion(LanguageVersion.CSharp7_2));
}

protected override async Task TestTypeWithoutDocumentationAsync(string type, bool isInterface)
{
await base.TestTypeWithoutDocumentationAsync(type, isInterface).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace StyleCop.Analyzers.Test.CSharp7.DocumentationRules
using StyleCop.Analyzers.DocumentationRules;
using StyleCop.Analyzers.Test.DocumentationRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.DocumentationRules.PropertySummaryDocumentationAnalyzer,
StyleCop.Analyzers.DocumentationRules.PropertySummaryDocumentationCodeFixProvider>;

public class SA1623CSharp7UnitTests : SA1623UnitTests
{
Expand Down Expand Up @@ -71,11 +74,8 @@ public class TestClass
}}
";

var expected = this.CSharpDiagnostic(PropertySummaryDocumentationAnalyzer.SA1623Descriptor).WithLocation(9, 7 + accessibility.Length + type.Length).WithArguments(expectedArgument);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
var expected = Diagnostic(PropertySummaryDocumentationAnalyzer.SA1623Descriptor).WithLocation(9, 7 + accessibility.Length + type.Length).WithArguments(expectedArgument);
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace StyleCop.Analyzers.Test.CSharp7.DocumentationRules
using StyleCop.Analyzers.DocumentationRules;
using StyleCop.Analyzers.Test.DocumentationRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.DocumentationRules.PropertySummaryDocumentationAnalyzer,
StyleCop.Analyzers.DocumentationRules.PropertySummaryDocumentationCodeFixProvider>;

public class SA1624CSharp7UnitTests : SA1624UnitTests
{
Expand Down Expand Up @@ -69,11 +72,8 @@ public class TestClass
}}
";

var expected = this.CSharpDiagnostic(PropertySummaryDocumentationAnalyzer.SA1624Descriptor).WithLocation(9, 7 + accessibility.Length + type.Length).WithArguments(expectedArgument1, expectedArgument2);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
var expected = Diagnostic(PropertySummaryDocumentationAnalyzer.SA1624Descriptor).WithLocation(9, 7 + accessibility.Length + type.Length).WithArguments(expectedArgument1, expectedArgument2);
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ namespace StyleCop.Analyzers.Test.CSharp7.LayoutRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.LayoutRules;
using TestHelper;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.LayoutRules.SA1500BracesForMultiLineStatementsMustNotShareLine,
StyleCop.Analyzers.LayoutRules.SA1500CodeFixProvider>;

public class SA1500CSharp7UnitTests : SA1500UnitTests
{
Expand Down Expand Up @@ -50,7 +54,7 @@ void LocalFunction5()
}
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -141,28 +145,26 @@ void LocalFunction6()
DiagnosticResult[] expectedDiagnostics =
{
// Invalid local function #1
this.CSharpDiagnostic().WithLocation(8, 31),
Diagnostic().WithLocation(8, 31),

// Invalid local function #2
this.CSharpDiagnostic().WithLocation(12, 31),
Diagnostic().WithLocation(12, 31),

// Invalid local function #3
this.CSharpDiagnostic().WithLocation(17, 31),
this.CSharpDiagnostic().WithLocation(18, 29),
Diagnostic().WithLocation(17, 31),
Diagnostic().WithLocation(18, 29),

// Invalid local function #4
this.CSharpDiagnostic().WithLocation(21, 31),
Diagnostic().WithLocation(21, 31),

// Invalid local function #5
this.CSharpDiagnostic().WithLocation(27, 29),
Diagnostic().WithLocation(27, 29),

// Invalid local function #6
this.CSharpDiagnostic().WithLocation(31, 9),
Diagnostic().WithLocation(31, 9),
};

await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ namespace StyleCop.Analyzers.Test.CSharp7.LayoutRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.LayoutRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.LayoutRules.SA1502ElementMustNotBeOnASingleLine,
StyleCop.Analyzers.LayoutRules.SA1502CodeFixProvider>;

public class SA1502CSharp7UnitTests : SA1502UnitTests
{
Expand All @@ -27,7 +31,7 @@ void Bar()
}
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -45,8 +49,8 @@ void Bar() { }
}
}";

var expected = this.CSharpDiagnostic().WithLocation(5, 20);
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
var expected = Diagnostic().WithLocation(5, 20);
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -64,8 +68,8 @@ public void Method()
}
}";

var expected = this.CSharpDiagnostic().WithLocation(5, 19);
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
var expected = Diagnostic().WithLocation(5, 19);
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -84,8 +88,8 @@ int Bar()
}
}";

var expected = this.CSharpDiagnostic().WithLocation(6, 9);
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
var expected = Diagnostic().WithLocation(6, 9);
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -104,7 +108,7 @@ int Bar() {
}
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -122,7 +126,7 @@ public void Method()
}
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -149,7 +153,8 @@ void Bar()
}
}";

await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
var expected = Diagnostic().WithLocation(5, 20);
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -177,7 +182,8 @@ int Bar()
}
}";

await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
var expected = Diagnostic().WithLocation(5, 19);
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -206,7 +212,8 @@ int Bar()
}
}";

await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
var expected = Diagnostic().WithLocation(6, 9);
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -234,7 +241,8 @@ int Bar() /* TR1 */
}
}";

await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
var expected = Diagnostic().WithLocation(5, 29);
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Loading