Skip to content

Commit c729f29

Browse files
authored
Merge pull request #4617 from GitTools/feature/new-cli-tests
Add tests for the cli Source Generator
2 parents 8b382e5 + 95ec97d commit c729f29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+906
-534
lines changed

.editorconfig

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
root = true
12
# http://editorconfig.org
23

34
# top-most EditorConfig file
4-
root = true
55

66
[*]
77
indent_style = space
@@ -10,6 +10,12 @@ end_of_line = lf
1010
trim_trailing_whitespace = true
1111
insert_final_newline = true
1212

13+
# Microsoft .NET properties
14+
dotnet_style_qualification_for_event = false:none
15+
dotnet_style_qualification_for_field = false:none
16+
dotnet_style_qualification_for_method = false:none
17+
dotnet_style_qualification_for_property = false:none
18+
1319
[*.yml]
1420
indent_size = 2
1521

@@ -156,18 +162,18 @@ resharper_csharp_align_multiline_parameter = true
156162
resharper_csharp_instance_members_qualify_members = field
157163

158164
# IDE0005: Using directive is unnecessary.
159-
dotnet_diagnostic.IDE0005.severity = warning
165+
dotnet_diagnostic.ide0005.severity = warning
160166

161167
# RCS1037: Remove trailing white-space.
162-
dotnet_diagnostic.RCS1037.severity = error
168+
dotnet_diagnostic.rcs1037.severity = error
163169

164170
# RCS1036: Remove redundant empty line.
165-
dotnet_diagnostic.RCS1036.severity = error
171+
dotnet_diagnostic.rcs1036.severity = error
166172

167173
xml_space_before_self_closing = true
168174

169175
resharper_arrange_object_creation_when_type_not_evident_highlighting = none
170176

171177
resharper_unused_auto_property_accessor_global_highlighting = none
172178

173-
resharper_unused_method_return_value_global_highlighting = none
179+
resharper_unused_method_return_value_global_highlighting = none

.github/workflows/format.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ jobs:
4848
-
4949
name: Run Format 'ci' solution
5050
run: dotnet format ./build/ --verify-no-changes
51-
-
52-
name: Build 'new-cli' solution
53-
run: dotnet build ./new-cli
54-
-
55-
name: Run Format 'new-cli' solution
56-
run: dotnet format ./new-cli/ --exclude ~/.nuget/packages --verify-no-changes
5751
-
5852
name: Run Format 'GitVersion' solution
5953
run: dotnet format ./src/ --exclude **/AddFormats/ --verify-no-changes

.github/workflows/new-cli.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build (new-cli)
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- 'fix/*'
7+
- 'feature/*'
8+
- 'poc/*'
9+
- 'support/*'
10+
paths:
11+
- '**'
12+
- '!docs/**'
13+
- '!.github/**'
14+
- .github/workflows/new-cli.yml
15+
16+
pull_request:
17+
branches:
18+
- main
19+
- 'support/*'
20+
paths:
21+
- '**'
22+
- '!docs/**'
23+
- '!.github/**'
24+
- .github/workflows/new-cli.yml
25+
26+
permissions:
27+
contents: read
28+
29+
env:
30+
DOTNET_ROLL_FORWARD: "Major"
31+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
32+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
33+
DOTNET_NOLOGO: 1
34+
35+
jobs:
36+
format:
37+
runs-on: ubuntu-24.04
38+
name: Build & Test (new-cli)
39+
steps:
40+
-
41+
name: Checkout
42+
uses: actions/checkout@v4
43+
-
44+
name: Setup .NET SDK
45+
uses: actions/setup-dotnet@v4
46+
with:
47+
global-json-file: global.json
48+
-
49+
name: Build 'new-cli' solution
50+
run: dotnet build ./new-cli
51+
-
52+
name: Run Format 'new-cli' solution
53+
run: dotnet format ./new-cli --exclude ~/.nuget/packages --verify-no-changes
54+
-
55+
name: Test 'new-cli' solution
56+
run: dotnet test ./new-cli --no-build --verbosity normal

build/CI.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<File Path="../.github/workflows/format.yml" />
4343
<File Path="../.github/workflows/homebrew.yml" />
4444
<File Path="../.github/workflows/mkdocs.yml" />
45+
<File Path="../.github/workflows/new-cli.yml" />
4546
<File Path="../.github/workflows/release.yml" />
4647
<File Path="../.github/workflows/stale.yml" />
4748
<File Path="../.github/workflows/winget.yml" />

new-cli/.run/TestCommand.run.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="TestCommand" type="DotNetProject" factoryName=".NET Project">
3+
<option name="EXE_PATH" value="$PROJECT_DIR$/GitVersion.Cli/bin/Debug/net9.0/gitversion" />
4+
<option name="PROGRAM_PARAMETERS" value="test -i test.txt" />
5+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
6+
<option name="PASS_PARENT_ENVS" value="1" />
7+
<option name="USE_EXTERNAL_CONSOLE" value="0" />
8+
<option name="ENV_FILE_PATHS" value="" />
9+
<option name="REDIRECT_INPUT_PATH" value="" />
10+
<option name="PTY_MODE" value="Auto" />
11+
<option name="USE_MONO" value="0" />
12+
<option name="RUNTIME_ARGUMENTS" value="" />
13+
<option name="AUTO_ATTACH_CHILDREN" value="0" />
14+
<option name="MIXED_MODE_DEBUG" value="0" />
15+
<option name="PROJECT_PATH" value="$PROJECT_DIR$/GitVersion.Cli/GitVersion.Cli.csproj" />
16+
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
17+
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
18+
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
19+
<option name="PROJECT_KIND" value="DotNetCore" />
20+
<option name="PROJECT_TFM" value="net9.0" />
21+
<method v="2">
22+
<option name="Build" />
23+
</method>
24+
</configuration>
25+
</component>

new-cli/Directory.Packages.props

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@
77
<PackageVersion Include="LibGit2Sharp" Version="0.31.0" />
88
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0" />
99
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
10+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
11+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
1012
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="4.14.0" />
1113
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
1214
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
1315
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.7" />
14-
<PackageVersion Include="Polly" Version="8.6.0" />
16+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.7" />
17+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
18+
<PackageVersion Include="NUnit" Version="4.3.2" />
19+
<PackageVersion Include="NUnit.Analyzers" Version="4.9.2">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageVersion>
23+
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" />
24+
<PackageVersion Include="Polly" Version="8.6.1" />
1525
<PackageVersion Include="Roslynator.Analyzers" Version="4.13.1" />
1626
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.13.1" />
1727
<!-- specific packages -->
@@ -24,4 +34,4 @@
2434
<PackageVersion Include="System.IO.Abstractions" Version="22.0.15" />
2535
<PackageVersion Include="System.Text.Json" Version="9.0.7" />
2636
</ItemGroup>
27-
</Project>
37+
</Project>

new-cli/GitVersion.Calculation/CalculateCommand.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
using GitVersion.Extensions;
22
using GitVersion.Git;
3-
using GitVersion.Infrastructure;
3+
using Microsoft.Extensions.Logging;
44

55
namespace GitVersion.Commands;
66

77
public record CalculateSettings : GitVersionSettings;
88

99
[Command("calculate", "Calculates the version object from the git history.")]
10-
public class CalculateCommand(ILogger logger, IService service, IGitRepository repository) : ICommand<CalculateSettings>
10+
public class CalculateCommand(ILogger<CalculateCommand> logger, IService service, IGitRepository repository) : ICommand<CalculateSettings>
1111
{
12-
private readonly ILogger logger = logger.NotNull();
13-
private readonly IService service = service.NotNull();
14-
private readonly IGitRepository repository = repository.NotNull();
12+
private readonly ILogger _logger = logger.NotNull();
13+
private readonly IService _service = service.NotNull();
14+
private readonly IGitRepository _repository = repository.NotNull();
1515

1616
public Task<int> InvokeAsync(CalculateSettings settings, CancellationToken cancellationToken = default)
1717
{
18-
var value = service.Call();
18+
var value = _service.Call();
1919
if (settings.WorkDir != null)
2020
{
21-
this.repository.DiscoverRepository(settings.WorkDir.FullName);
22-
var branches = this.repository.Branches.ToList();
23-
this.logger.LogInformation("Command : 'calculate', LogFile : '{logFile}', WorkDir : '{workDir}' ",
21+
_repository.DiscoverRepository(settings.WorkDir.FullName);
22+
var branches = _repository.Branches.ToList();
23+
_logger.LogInformation("Command : 'calculate', LogFile : '{logFile}', WorkDir : '{workDir}' ",
2424
settings.LogFile, settings.WorkDir);
25-
this.logger.LogInformation("Found {count} branches", branches.Count);
25+
_logger.LogInformation("Found {count} branches", branches.Count);
2626
}
2727

2828
return Task.FromResult(value);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<RootNamespace>GitVersion.Cli.Generator.Tests</RootNamespace>
5+
<IsPackable>false</IsPackable>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
10+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
11+
<PackageReference Include="System.CommandLine" />
12+
13+
<PackageReference Include="Microsoft.CSharp" />
14+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" />
15+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
18+
<PackageReference Include="NUnit" />
19+
<PackageReference Include="NUnit.Analyzers">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
23+
<PackageReference Include="NUnit3TestAdapter" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<Using Include="NUnit.Framework" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<ProjectReference Include="..\GitVersion.Cli.Generator\GitVersion.Cli.Generator.csproj" />
32+
<ProjectReference Include="..\GitVersion.Common.Command\GitVersion.Common.Command.csproj" />
33+
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj" />
34+
</ItemGroup>
35+
36+
</Project>

0 commit comments

Comments
 (0)