Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit 953d051

Browse files
committed
Update test framework to use the latest from StyleCop.Analyzers
1 parent 5a1b01d commit 953d051

13 files changed

+881
-353
lines changed

AsyncUsageAnalyzers/AsyncUsageAnalyzers.Test/AsyncUsageAnalyzers.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
</Reference>
118118
</ItemGroup>
119119
<ItemGroup>
120+
<Compile Include="Helpers\DiagnosticResultLocation.cs" />
121+
<Compile Include="Helpers\MetadataReferences.cs" />
122+
<Compile Include="Helpers\TestDiagnosticProvider.cs" />
120123
<Compile Include="Naming\AvoidAsyncSuffixUnitTests.cs" />
121124
<Compile Include="Naming\UseAsyncSuffixUnitTests.cs" />
122125
<Compile Include="Reliability\AvoidAsyncVoidUnitTests.cs" />

AsyncUsageAnalyzers/AsyncUsageAnalyzers.Test/Helpers/CodeFixVerifier.Helper.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
using Microsoft.CodeAnalysis;
2-
using Microsoft.CodeAnalysis.CodeActions;
3-
using Microsoft.CodeAnalysis.Formatting;
4-
using Microsoft.CodeAnalysis.Simplification;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Threading;
8-
using System.Threading.Tasks;
9-
using System.Collections.Immutable;
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
103

114
namespace TestHelper
125
{
6+
using System.Collections.Generic;
7+
using System.Collections.Immutable;
8+
using System.Linq;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
using Microsoft.CodeAnalysis;
12+
using Microsoft.CodeAnalysis.CodeActions;
13+
using Microsoft.CodeAnalysis.Formatting;
14+
using Microsoft.CodeAnalysis.Simplification;
15+
1316
/// <summary>
1417
/// Diagnostic Producer class with extra methods dealing with applying code fixes.
1518
/// All methods are static

AsyncUsageAnalyzers/AsyncUsageAnalyzers.Test/Helpers/DiagnosticResult.cs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,10 @@
1-
using Microsoft.CodeAnalysis;
2-
using System;
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44
namespace TestHelper
55
{
6-
/// <summary>
7-
/// Location where the diagnostic appears, as determined by path, line number, and column number.
8-
/// </summary>
9-
public struct DiagnosticResultLocation
10-
{
11-
public string Path;
12-
public int Line;
13-
public int Column;
14-
15-
public DiagnosticResultLocation(string path, int line, int column)
16-
{
17-
if (line < 0 && column < 0)
18-
{
19-
throw new ArgumentOutOfRangeException("At least one of line and column must be > 0");
20-
}
21-
22-
if (line < -1 || column < -1)
23-
{
24-
throw new ArgumentOutOfRangeException("Both line and column must be >= -1");
25-
}
26-
27-
this.Path = path;
28-
this.Line = line;
29-
this.Column = column;
30-
}
31-
}
6+
using System;
7+
using Microsoft.CodeAnalysis;
328

339
/// <summary>
3410
/// Structure that stores information about a <see cref="Diagnostic"/> appearing in a source.
@@ -142,6 +118,13 @@ public DiagnosticResult WithArguments(params object[] arguments)
142118
return result;
143119
}
144120

121+
public DiagnosticResult WithMessageFormat(LocalizableString messageFormat)
122+
{
123+
DiagnosticResult result = this;
124+
result.MessageFormat = messageFormat;
125+
return result;
126+
}
127+
145128
public DiagnosticResult WithLocation(int line, int column)
146129
{
147130
return this.WithLocation("Test0.cs", line, column);
@@ -154,5 +137,17 @@ public DiagnosticResult WithLocation(string path, int line, int column)
154137
result.locations[result.locations.Length - 1] = new DiagnosticResultLocation(path, line, column);
155138
return result;
156139
}
140+
141+
public DiagnosticResult WithLineOffset(int offset)
142+
{
143+
DiagnosticResult result = this;
144+
Array.Resize(ref result.locations, result.locations?.Length ?? 0);
145+
for (int i = 0; i < result.locations.Length; i++)
146+
{
147+
result.locations[i].Line += offset;
148+
}
149+
150+
return result;
151+
}
157152
}
158-
}
153+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace TestHelper
5+
{
6+
using System;
7+
8+
/// <summary>
9+
/// Location where the diagnostic appears, as determined by path, line number, and column number.
10+
/// </summary>
11+
public struct DiagnosticResultLocation
12+
{
13+
public string Path;
14+
public int Line;
15+
public int Column;
16+
17+
public DiagnosticResultLocation(string path, int line, int column)
18+
{
19+
if (line < 0 && column < 0)
20+
{
21+
throw new ArgumentOutOfRangeException("At least one of line and column must be > 0");
22+
}
23+
24+
if (line < -1 || column < -1)
25+
{
26+
throw new ArgumentOutOfRangeException("Both line and column must be >= -1");
27+
}
28+
29+
this.Path = path;
30+
this.Line = line;
31+
this.Column = column;
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)