-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Testing; | ||
using Microsoft.CodeAnalysis.Testing; | ||
using Microsoft.CodeAnalysis.Testing.Verifiers; | ||
using System.Collections.Immutable; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace MessagePipe.Analyzer.Tests | ||
{ | ||
public class AnalyzerTest | ||
{ | ||
static async Task VerifyAsync(string testCode, int startLine, int startColumn, int endLine, int endColumn) | ||
{ | ||
|
||
await new CSharpAnalyzerTest<MessagePipeAnalyzer, XUnitVerifier> | ||
{ | ||
ReferenceAssemblies = ReferenceAssemblies.Default.WithPackages(ImmutableArray.Create(new PackageIdentity("MessagePipe", "1.4.0"))), | ||
ExpectedDiagnostics = { new DiagnosticResult("MPA001", DiagnosticSeverity.Error).WithSpan(startLine, startColumn, endLine, endColumn) }, | ||
TestCode = testCode | ||
}.RunAsync(); | ||
} | ||
|
||
static async Task VerifyNoErrorAsync(string testCode) | ||
{ | ||
|
||
await new CSharpAnalyzerTest<MessagePipeAnalyzer, XUnitVerifier> | ||
{ | ||
ReferenceAssemblies = ReferenceAssemblies.Default.WithPackages(ImmutableArray.Create(new PackageIdentity("MessagePipe", "1.4.0"))), | ||
ExpectedDiagnostics = { }, | ||
TestCode = testCode | ||
}.RunAsync(); | ||
} | ||
|
||
[Fact] | ||
public async Task SimpleTest() | ||
{ | ||
var testCode = @"using MessagePipe; | ||
class C | ||
{ | ||
public void M(ISubscriber<int> subscriber) | ||
{ | ||
subscriber.Subscribe(x => { }); | ||
} | ||
}"; | ||
|
||
await VerifyAsync(testCode, 7, 9, 7, 39); | ||
} | ||
|
||
[Fact] | ||
public async Task NoErrorReport() | ||
{ | ||
var testCode = @"using MessagePipe; | ||
class C | ||
{ | ||
public void M(ISubscriber<int> subscriber) | ||
{ | ||
var d = subscriber.Subscribe(x => { }); | ||
} | ||
}"; | ||
|
||
await VerifyNoErrorAsync(testCode); | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
tests/MessagePipe.Analyzer.Tests/MessagePipe.Analyzer.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.0" /> | ||
|
||
<PackageReference Include="FluentAssertions" Version="5.10.3" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
|
||
<ProjectReference Include="..\..\src\MessagePipe.Analyzer\MessagePipe.Analyzer.csproj" /> | ||
|
||
<ProjectReference Include="..\..\src\MessagePipe\MessagePipe.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters