Skip to content

Commit acbcaee

Browse files
authored
Update default TargetFramework and adjust test setups (#993)
Changed ProjectBuilder's default TargetFramework to NetLatest. Updated tests to explicitly set NetStandard2_0 where needed, ensuring consistent test behavior.
1 parent a961de4 commit acbcaee

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public sealed partial class ProjectBuilder
2727
public bool IsValidCode { get; private set; } = true;
2828
public bool IsValidFixCode { get; private set; } = true;
2929
public LanguageVersion LanguageVersion { get; private set; } = LanguageVersion.Latest;
30-
public TargetFramework TargetFramework { get; private set; } = TargetFramework.NetStandard2_0;
30+
public TargetFramework TargetFramework { get; private set; } = TargetFramework.NetLatest;
3131
public IList<MetadataReference> References { get; } = [];
3232
public IList<string> ApiReferences { get; } = [];
3333
public IList<DiagnosticAnalyzer> DiagnosticAnalyzer { get; } = [];

tests/Meziantou.Analyzer.Test/Rules/OptimizeLinqUsageAnalyzerUseDirectMethodsTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public Test()
6767
";
6868

6969
await CreateProjectBuilder()
70+
.WithTargetFramework(TargetFramework.NetStandard2_0)
7071
.WithSourceCode(SourceCode)
7172
.ShouldReportDiagnosticWithMessage("Use 'Find()' instead of 'FirstOrDefault()'")
7273
.ShouldFixCodeWith(CodeFix)
@@ -119,6 +120,7 @@ public Test()
119120
";
120121

121122
await CreateProjectBuilder()
123+
.WithTargetFramework(TargetFramework.NetStandard2_0)
122124
.WithSourceCode(SourceCode)
123125
.AddAnalyzerConfiguration("MA0020.report_when_conversion_needed", "true")
124126
.ShouldReportDiagnosticWithMessage("Use 'Find()' instead of 'FirstOrDefault()'")

tests/Meziantou.Analyzer.Test/Rules/OptimizeStringBuilderUsageAnalyzerTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void A()
6161
public async Task Append_ReportDiagnostic(string text)
6262
{
6363
await CreateProjectBuilder()
64+
.WithTargetFramework(TargetFramework.NetStandard2_0)
6465
.WithSourceCode(@"using System.Text;
6566
class Test
6667
{
@@ -122,6 +123,7 @@ void A()
122123
public async Task AppendLine_ReportDiagnostic(string text)
123124
{
124125
await CreateProjectBuilder()
126+
.WithTargetFramework(TargetFramework.NetStandard2_0)
125127
.WithSourceCode(@"using System.Text;
126128
class Test
127129
{
@@ -309,6 +311,7 @@ void A()
309311
public async Task Append_InterpolatedString()
310312
{
311313
await CreateProjectBuilder()
314+
.WithTargetFramework(TargetFramework.NetStandard2_0)
312315
.WithSourceCode(@"using System.Text;
313316
class Test
314317
{
@@ -332,6 +335,7 @@ void A()
332335
public async Task AppendLine_InterpolatedString_FinishWithString()
333336
{
334337
await CreateProjectBuilder()
338+
.WithTargetFramework(TargetFramework.NetStandard2_0)
335339
.WithSourceCode(@"using System.Text;
336340
class Test
337341
{
@@ -355,6 +359,7 @@ void A()
355359
public async Task AppendLine_InterpolatedString_FinishWithChar()
356360
{
357361
await CreateProjectBuilder()
362+
.WithTargetFramework(TargetFramework.NetStandard2_0)
358363
.WithSourceCode(@"using System.Text;
359364
class Test
360365
{
@@ -378,6 +383,7 @@ void A()
378383
public async Task AppendLine_InterpolatedString_FinishWithObject()
379384
{
380385
await CreateProjectBuilder()
386+
.WithTargetFramework(TargetFramework.NetStandard2_0)
381387
.WithSourceCode(@"using System.Text;
382388
class Test
383389
{
@@ -573,6 +579,7 @@ void A()
573579
public async Task Append_StringJoin_AppendJoin_OldTargetFramework()
574580
{
575581
await CreateProjectBuilder()
582+
.WithTargetFramework(TargetFramework.NetStandard2_0)
576583
.WithSourceCode(@"using System.Text;
577584
class Test
578585
{

tests/Meziantou.Analyzer.Test/Rules/UseAnOverloadThatHasCancellationTokenAnalyzerTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@ static async IAsyncEnumerable<int> AsyncEnumerable([EnumeratorCancellation] Canc
725725
";
726726

727727
await CreateProjectBuilder()
728-
.AddAsyncInterfaceApi()
729728
.WithSourceCode(SourceCode)
730729
.WithCodeFixProvider<UseAnOverloadThatHasCancellationTokenFixer_Argument>()
731730
.ShouldFixCodeWith(Fix)
@@ -770,7 +769,6 @@ public static async Task A(IAsyncEnumerable<int> enumerable)
770769
";
771770

772771
await CreateProjectBuilder()
773-
.AddAsyncInterfaceApi()
774772
.WithSourceCode(SourceCode)
775773
.WithCodeFixProvider<UseAnOverloadThatHasCancellationTokenFixer_AwaitForEach>()
776774
.ShouldFixCodeWith(Fix)
@@ -798,7 +796,6 @@ public static async Task A(IAsyncEnumerable<int> enumerable)
798796
";
799797

800798
await CreateProjectBuilder()
801-
.AddAsyncInterfaceApi()
802799
.WithSourceCode(SourceCode)
803800
.ValidateAsync();
804801
}
@@ -824,7 +821,6 @@ public static async Task A(IAsyncEnumerable<int> enumerable)
824821
";
825822

826823
await CreateProjectBuilder()
827-
.AddAsyncInterfaceApi()
828824
.WithSourceCode(SourceCode)
829825
.ValidateAsync();
830826
}
@@ -855,7 +851,6 @@ static async IAsyncEnumerable<int> AsyncEnumerable([EnumeratorCancellation] Canc
855851
";
856852

857853
await CreateProjectBuilder()
858-
.AddAsyncInterfaceApi()
859854
.WithSourceCode(SourceCode)
860855
.ValidateAsync();
861856
}
@@ -884,7 +879,6 @@ static void A(CancellationToken cancellationToken = default)
884879
";
885880

886881
await CreateProjectBuilder()
887-
.AddAsyncInterfaceApi()
888882
.WithSourceCode(SourceCode)
889883
.ValidateAsync();
890884
}

tests/Meziantou.Analyzer.Test/Rules/ValidateArgumentsCorrectlyAnalyzerTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ async IAsyncEnumerable<int> A(string a)
257257
}";
258258

259259
await CreateProjectBuilder()
260-
.AddAsyncInterfaceApi()
261260
.WithSourceCode(SourceCode)
262261
.ShouldFixCodeWith(CodeFix)
263262
.ValidateAsync();

0 commit comments

Comments
 (0)