Skip to content

Commit 20c83c7

Browse files
chore: upgrade dotnet and dependencies to latest LTS versions (#561)
* Upgraded from .net 6.0 to 8.0 and upgraded nuget packages * Upgraded code to make it net 8 compatible Adopt nullable reference types and modernize tests Updated method signatures to use nullable reference types (`string?`, `params string?[]`, etc.) for improved nullability handling and alignment with C# 8.0 standards. Refactored floating-point parsing tests to use explicit `double` types and introduced `GetDoublePointSymbolsData` for better test coverage. Improved assertions by replacing outdated patterns (e.g., `Assert.True(false)`) with clearer alternatives like `Assert.Fail`. Enhanced null handling in tests by updating parameters and default values to handle nullable scenarios explicitly. Modernized syntax with updated collection initializers and nullable annotations. Fixed a typo in a method name and ensured consistent use of nullable annotations across the codebase. Added test cases to cover edge cases and improve validation logic. Performed general code cleanup, including removing redundant comments, consolidating test data, and improving formatting for readability and maintainability.
1 parent 60b4b9f commit 20c83c7

17 files changed

+93
-56
lines changed

src/CommandLineUtils/McMaster.Extensions.CommandLineUtils.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<IsPackable>true</IsPackable>
77
<Description>Command-line parsing API.</Description>
@@ -25,4 +25,8 @@ McMaster.Extensions.CommandLineUtils.ArgumentEscaper
2525
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
2626
</ItemGroup>
2727

28+
<ItemGroup>
29+
<PackageReference Update="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
30+
</ItemGroup>
31+
2832
</Project>
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<IsPackable>true</IsPackable>
77
<Description>Provides command-line parsing API integration with the generic host API (Microsoft.Extensions.Hosting).</Description>
88
<PackageTags>commandline;parsing;hosting</PackageTags>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
13-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
12+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.10" />
13+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.10" />
1414
</ItemGroup>
1515

1616
<ItemGroup>
1717
<ProjectReference Include="..\CommandLineUtils\McMaster.Extensions.CommandLineUtils.csproj" />
1818
</ItemGroup>
1919

20+
<ItemGroup>
21+
<PackageReference Update="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
22+
</ItemGroup>
23+
2024
</Project>

test/CommandLineUtils.Tests/AttributeValidatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void OnExecute() { }
9494
[InlineData("email", 1)]
9595
[InlineData("email@email@email", 1)]
9696
[InlineData("[email protected]", 0)]
97-
public void ValidatesEmailArgument(string email, int exitCode)
97+
public void ValidatesEmailArgument(string? email, int exitCode)
9898
{
9999
Assert.Equal(exitCode, CommandLineApplication.Execute<EmailArgumentApp>(new TestConsole(_output), email));
100100
}

test/CommandLineUtils.Tests/CommandLineApplicationExecutorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private class HelpClass
197197
{
198198
private void OnExecute()
199199
{
200-
Assert.True(false, "This should not execute");
200+
Assert.Fail("This should not execute");
201201
}
202202
}
203203

test/CommandLineUtils.Tests/CommandLineApplicationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ public void NestedInheritedOptions()
720720
[InlineData(new[] { "-t", "val", "--", "a", "--", "b" }, new[] { "a", "--", "b" }, "val")]
721721
[InlineData(new[] { "--", "--help" }, new[] { "--help" }, null)]
722722
[InlineData(new[] { "--", "--version" }, new[] { "--version" }, null)]
723-
public void ArgumentSeparator(string[] input, string[] expectedRemaining, string topLevelValue)
723+
public void ArgumentSeparator(string[] input, string[] expectedRemaining, string? topLevelValue)
724724
{
725725
var app = new CommandLineApplication
726726
{
@@ -1047,7 +1047,7 @@ public void ThrowsExceptionOnEmptyCommandOrArgument()
10471047
[InlineData(null)]
10481048
[InlineData("")]
10491049
[InlineData("-")]
1050-
public void ThrowsExceptionOnInvalidArgument(string inputOption)
1050+
public void ThrowsExceptionOnInvalidArgument(string? inputOption)
10511051
{
10521052
var app = new CommandLineApplication();
10531053

test/CommandLineUtils.Tests/CommandLineProcessorTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CommandLineProcessorTests
2525
[InlineData(new[] { "-af", "Path.txt" }, true, false, false, "Path.txt")]
2626
[InlineData(new[] { "-f:Path.txt" }, false, false, false, "Path.txt")]
2727
[InlineData(new[] { "-a", "-c", "-f", "Path.txt" }, true, false, true, "Path.txt")]
28-
public void CanParseClusteredOptions(string[] input, bool a, bool b, bool c, string f)
28+
public void CanParseClusteredOptions(string[] input, bool a, bool b, bool c, string? f)
2929
{
3030
var app = new CommandLineApplication
3131
{
@@ -62,7 +62,7 @@ public void CanParseClusteredOptionMultipleTimes()
6262
[InlineData("-vl=diag", "diag")]
6363
[InlineData("-vl", null)]
6464
[InlineData("-lv", null)]
65-
public void ItClustersSingleOrNoValueOptions(string input, string expectedLogValue)
65+
public void ItClustersSingleOrNoValueOptions(string input, string? expectedLogValue)
6666
{
6767
var app = new CommandLineApplication
6868
{
@@ -252,7 +252,7 @@ public void CanUseSingleDashAsArgumentValue()
252252
[InlineData("--log: ", " ")]
253253
[InlineData("--log:verbose", "verbose")]
254254
[InlineData("--log=verbose", "verbose")]
255-
public void CanParseSingleOrNoValueParameter(string input, string expected)
255+
public void CanParseSingleOrNoValueParameter(string input, string? expected)
256256
{
257257
var app = new CommandLineApplication();
258258
var opt = app.Option("--log", "Log level", CommandOptionType.SingleOrNoValue);
@@ -266,7 +266,7 @@ public void CanParseSingleOrNoValueParameter(string input, string expected)
266266
[InlineData(new[] { "--param1" }, null, null)]
267267
[InlineData(new[] { "--param1", "--param2", "p2" }, null, "p2")]
268268
[InlineData(new[] { "--param1:p1", "--param2", "p2" }, "p1", "p2")]
269-
public void CanParseSingleOrNoValueParameters(string[] args, string param1, string param2)
269+
public void CanParseSingleOrNoValueParameters(string[] args, string? param1, string? param2)
270270
{
271271
var app = new CommandLineApplication();
272272
var opt1 = app.Option("--param1", "param1", CommandOptionType.SingleOrNoValue);

test/CommandLineUtils.Tests/CommandOptionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class CommandOptionTests
2828
[InlineData("--name=<VALUE>", null, null, "name", "VALUE")]
2929
[InlineData("-a:<VALUE> --name:<VALUE>", "a", null, "name", "VALUE")]
3030
[InlineData("-a=<VALUE> --name=<VALUE>", "a", null, "name", "VALUE")]
31-
public void ItParsesSingleValueTemplate(string template, string shortName, string symbolName, string longName, string valueName)
31+
public void ItParsesSingleValueTemplate(string template, string? shortName, string? symbolName, string? longName, string? valueName)
3232
{
3333
var opt = new CommandOption(template, CommandOptionType.SingleValue);
3434
Assert.Equal(shortName, opt.ShortName);
@@ -40,7 +40,7 @@ public void ItParsesSingleValueTemplate(string template, string shortName, strin
4040
[Theory]
4141
[InlineData("--name[:<VALUE>]", null, null, "name", "VALUE")]
4242
[InlineData("--name[=<VALUE>]", null, null, "name", "VALUE")]
43-
public void ItParsesSingleOrNoValueTemplate(string template, string shortName, string symbolName, string longName, string valueName)
43+
public void ItParsesSingleOrNoValueTemplate(string template, string? shortName, string? symbolName, string longName, string valueName)
4444
{
4545
var opt = new CommandOption(template, CommandOptionType.SingleOrNoValue);
4646
Assert.Equal(shortName, opt.ShortName);

test/CommandLineUtils.Tests/CustomValidationAttributeTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public class CustomValidationAttributeTest
1212
[InlineData(null)]
1313
[InlineData("-c", "red")]
1414
[InlineData("-c", "blue")]
15-
public void CustomValidationAttributePasses(params string[] args)
15+
public void CustomValidationAttributePasses(params string?[] args)
1616
{
1717
var app = new CommandLineApplication<RedBlueProgram>();
1818
app.Conventions.UseDefaultConventions();
19-
var result = app.Parse(args ?? System.Array.Empty<string>());
19+
var result = app.Parse(args ?? []);
2020
Assert.Equal(ValidationResult.Success, result.SelectedCommand.GetValidationResult());
2121
var program = Assert.IsType<CommandLineApplication<RedBlueProgram>>(result.SelectedCommand);
2222
Assert.Same(app, program);
@@ -30,7 +30,7 @@ public void CustomValidationAttributePasses(params string[] args)
3030
[InlineData("-c", "")]
3131
[InlineData("-c", null)]
3232
[InlineData("-c", "green")]
33-
public void CustomValidationAttributeFails(params string[] args)
33+
public void CustomValidationAttributeFails(params string?[] args)
3434
{
3535
var app = new CommandLineApplication<RedBlueProgram>();
3636
app.Conventions.UseAttributes();

test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public class MyApp
288288
[InlineData("--help", "--help", " --help Show help information.", " Subcommand ")]
289289
[InlineData("-?", "-?", " -? Show help information.", " Subcommand ")]
290290
[InlineData(null, "-?|-h|--help", " -?|-h|--help Show help information.", " Subcommand ")]
291-
public void ShowHelpWithSubcommands(string helpOption, string expectedHintText, string expectedOptionsText,
291+
public void ShowHelpWithSubcommands(string? helpOption, string expectedHintText, string expectedOptionsText,
292292
string expectedCommandsText)
293293
{
294294
var app = new CommandLineApplication { Name = "test" };

test/CommandLineUtils.Tests/ExecuteMethodConventionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ public async Task ItExecutesAsyncMethod()
133133
var app = new CommandLineApplication<ProgramWithAsyncOnExecute>(console);
134134
app.Conventions.UseOnExecuteMethodFromModel();
135135
var executeTask = app.ExecuteAsync(Array.Empty<string>());
136-
await ProgramWithAsyncOnExecute.ExecuteStarted.Task.ConfigureAwait(false);
136+
await ProgramWithAsyncOnExecute.ExecuteStarted.Task.ConfigureAwait(true);
137137
Assert.False(app.Model.Token.IsCancellationRequested);
138138
Assert.NotEqual(CancellationToken.None, app.Model.Token);
139139
console.RaiseCancelKeyPress();
140-
var result = await executeTask.ConfigureAwait(false);
140+
var result = await executeTask.ConfigureAwait(true);
141141
Assert.Equal(4, result);
142142
Assert.True(app.Model.Token.IsCancellationRequested);
143143
}

0 commit comments

Comments
 (0)