-
Notifications
You must be signed in to change notification settings - Fork 655
Add tests for the cli Source Generator #4617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introduced a new test project, `GitVersion.Cli.Generator.Tests`, to support unit testing for `GitVersion.Cli.Generator`. Updated solution and package dependency files to include necessary references and dependencies. This ensures better test coverage and maintains consistency across projects. updates dependency versions updates Microsoft.Extensions.Logging.Abstractions to 9.0.6 and Polly to 8.6.1 this brings the packages up to date for compatibility and potentially includes bug fixes or performance improvements.
Renamed `CommandsImplModule` to `CommandsModule` for clarity and updated related references. Adjusted the accessibility of `GeneratedHeader` and added required namespaces. Enhanced syntax consistency and replaced array construction with shorthand for better readability.
…ommandImplGenerator with sample source code` This commit introduces unit tests for the `CommandImplGenerator` to validate its output. The tests include a sample command source and verify the correctness of the generated implementations, such as `TestCommandImpl`, `CommandsModule`, and `RootCommandImpl`. It ensures compatibility with required dependencies and adheres to .NET 9.0 standards.
Renamed `CommandImplGenerator` to `SystemCommandlineGenerator` and introduced an abstract `CommandBaseGenerator` for better extensibility. Moved source generation logic to the new `SystemCommandlineGenerator` and updated related tests accordingly.
Adds a global usings file to the generated code. This reduces the amount of code needed in the generated files, making them more readable and maintainable.
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.
Replaced the nullable annotation check with the IsRequired property on propertySymbol for determining if a field is required. This improves code clarity and aligns with more explicit APIs.
Moved namespace-related constants from multiple files into the `Content` class for better centralization and consistency. Updated references across the project to use the newly centralized constants, simplifying maintainability. Added `InternalsVisibleTo` in the project file to support unit tests.
Introduce `CliModule` for dependency registration, implementing an `IGitVersionApp` interface to decouple app logic. Refactor `Program.cs` to use the new interface and modularize service initialization, improving maintainability and scalability.
Relocates the CliModule to improve project structure and manage dependencies. It also adds logging at the service registration level.
implements a new test command with an input file option. creates a run configuration for the test command in the IDE.
Migrates from a custom `IContainerRegistrar` and `IContainer` to the standard `IServiceCollection` and `ServiceProvider` from Microsoft.Extensions.DependencyInjection. This simplifies dependency injection and improves compatibility with the .NET ecosystem.
Migrates to Microsoft.Extensions.Logging for logging abstraction. This change removes the custom logging infrastructure and replaces it with the standard Microsoft logging. This provides better integration with other .NET libraries and frameworks and allows for more flexible configuration and management of logging.
Refactors constructors to use readonly backing fields for injected dependencies. Adds .editorconfig settings for .NET code style and updates existing settings.
Changes ILogger injection to ILogger<T> in command classes. This aligns with best practices for dependency injection and improves logging context.
Ensures correct command registration in the IoC container by including the namespace when the command type namespace differs from the main command namespace. Also, adjust the tests to reflect this change.
Renames the `Content` class to `SystemCommandlineContent` for clarity and consistency. This change improves code organization and readability by providing a more descriptive name for the class that contains content related to system command line generation.
Introduces a CLI application infrastructure, including the implementation of `ICliApp` and related dependencies. This provides a structured approach for running CLI commands. Additionally, the command and root command implementations are adjusted to accommodate the new infrastructure.
Adds the extensions namespace to the code generator, ensuring it is correctly included in generated files. This change ensures consistency and proper referencing of extension methods within the generated code.
Extends the command-line interface generator to support additional options for commands. This enhancement allows specifying options with their descriptions, aliases, and required status, improving flexibility.
Qualifies the commands module using the extension namespace. This ensures the code generator correctly references extension methods within the generated files.
Integrates `LoggingEnricher` for enhanced logging configuration and ensures its proper registration in IoC. Updates tests and code generation to support this change.
Updates the `RegisterTypes` method signature across `IGitVersionModule` implementations and usage. This simplifies service registration by enabling method chaining in IoC configuration.
Refactors `GitVersionApp` to implement `ICliApp` and updates dependency injection to register `GitVersionApp` as `ICliApp`. Adjusts `RunAsync` to include `CancellationToken`, ensuring proper cancellation support.
01bfcd4
to
99fc7de
Compare
Splits the format workflow into separate format and build workflows for the new CLI project. This improves the workflow organization and allows for more targeted builds and tests.
99fc7de
to
95ec97d
Compare
Thank you @arturcic for your contribution! |
private readonly IGitRepository repository = repository.NotNull(); | ||
private readonly ILogger _logger = logger.NotNull(); | ||
private readonly IService _service = service.NotNull(); | ||
private readonly IGitRepository _repository = repository.NotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we started prefixing fields with _
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure yet, I guess this used the configurations I had at my current work. That is still much a wip, so whenever it's at a more advanced stage we can get back to the conventions
This pull request introduces several changes across multiple files to improve code organization, enhance functionality, and update dependencies. Key changes include updates to
.editorconfig
for consistency, enhancements to the CLI generator and its tests, dependency updates inDirectory.Packages.props
, and refactoring of theCalculateCommand
implementation.Configuration Updates:
.editorconfig
: Added Microsoft .NET-specific properties and corrected severity levels for diagnostics to lowercase for consistency. [1] [2] [3]CLI Enhancements:
new-cli/GitVersion.Cli.Generator.Tests/SystemCommandlineGeneratorTests.cs
: Added comprehensive tests for the CLI generator, including validation of generated command implementations and modules.new-cli/GitVersion.Cli.Generator/CommandBaseGenerator.cs
: Refactored and renamedCommandImplGenerator
toCommandBaseGenerator
, introducing an abstract method for source code generation and simplifying settings property mapping. [1] [2] [3] [4]Dependency Updates:
new-cli/Directory.Packages.props
: Added new dependencies for testing (NUnit
,Microsoft.NET.Test.Sdk
) and updated existing ones (Polly
).new-cli/GitVersion.Cli.Generator.Tests/GitVersion.Cli.Generator.Tests.csproj
: Added project references and package dependencies to support CLI generator testing.Code Refactoring:
new-cli/GitVersion.Calculation/CalculateCommand.cs
: Refactored to useILogger<CalculateCommand>
and renamed private fields for clarity. Improved logging and repository discovery logic.New Features:
new-cli/.run/TestCommand.run.xml
: Added a new run configuration for theTestCommand
in the CLI project.