Skip to content

Commit 36a4920

Browse files
committed
Make output-file option required and enable nullable contexts
Set the output-file option as required in tests to ensure proper parsing. Added nullable context enforcement and enabled implicit usings in source generator tests for better code safety and modern language compatibility.
1 parent d5cea5a commit 36a4920

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

new-cli/GitVersion.Cli.Generator.Tests/SystemCommandlineGeneratorTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.CommandLine;
1+
using System.CommandLine;
22
using GitVersion.Infrastructure;
33
using Microsoft.CodeAnalysis;
44
using Microsoft.CodeAnalysis.CSharp;
@@ -69,7 +69,7 @@ public TestCommandImpl(TestCommand command)
6969
{
7070
OutputFileOption = new Option<string>("--output-file", [])
7171
{
72-
Required = false,
72+
Required = true,
7373
Description = "The output file",
7474
};
7575
Add(OutputFileOption);
@@ -81,7 +81,7 @@ Task<int> Run(ParseResult parseResult, CancellationToken cancellationToken)
8181
{
8282
var settings = new TestCommandSettings
8383
{
84-
OutputFile = parseResult.GetValue(OutputFileOption),
84+
OutputFile = parseResult.GetValue(OutputFileOption)!,
8585
};
8686
return command.InvokeAsync(settings, cancellationToken);
8787
}
@@ -174,6 +174,24 @@ public async Task ValidateGeneratedCommandImplementation()
174174
}
175175
};
176176

177+
sourceGeneratorTest.SolutionTransforms.Add(
178+
// make sure the ImplicitUsage is enabled
179+
(solution, projectId) =>
180+
{
181+
var project = solution.GetProject(projectId)!;
182+
183+
// Enable ImplicitUsings
184+
var parseOptions = (CSharpParseOptions)project.ParseOptions!;
185+
var compilationOptions = (CSharpCompilationOptions)project.CompilationOptions!;
186+
187+
// Enable implicit usings (same as `<ImplicitUsings>enable</ImplicitUsings>` in .csproj)
188+
compilationOptions = compilationOptions.WithNullableContextOptions(NullableContextOptions.Enable);
189+
190+
return project
191+
.WithParseOptions(parseOptions.WithLanguageVersion(LanguageVersion.Latest))
192+
.WithCompilationOptions(compilationOptions)
193+
.Solution;
194+
});
177195
await sourceGeneratorTest.RunAsync();
178196
}
179197
}

0 commit comments

Comments
 (0)