Skip to content

Commit 9fcd59e

Browse files
committed
Fixing test running in CI
1 parent c1a65a7 commit 9fcd59e

File tree

7 files changed

+61
-45
lines changed

7 files changed

+61
-45
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- "[0-9]+.[0-9]+.[0-9]+"
1010
- "[0-9]+.[0-9]+.[0-9]+-**"
1111
pull_request:
12-
types: [opened, reopened, edited, syncrhonize]
12+
types: [opened, reopened, edited, synchronize]
1313

1414
jobs:
1515
test:
@@ -38,9 +38,7 @@ jobs:
3838
dotnet test
3939
--configuration Release
4040
-p:GeneratorVersion=${{ matrix.roslyn }}
41-
--logger GitHubActions
42-
--
43-
RunConfiguration.CollectSourceInformation=true
41+
--logger "console;verbosity=normal"
4442
4543
- name: Upload Test Results
4644
if: failure()
@@ -67,11 +65,12 @@ jobs:
6765
- name: 🔍 Enable problem matchers
6866
run: echo "::add-matcher::.github/matchers/dotnet.json"
6967

70-
- name: 🔧 Load packages
71-
run: dotnet restore
72-
7368
- name: 🛠️ Build code
74-
run: dotnet build --configuration Release -p:Version=${{ github.ref_name }} -p:GitSha=${{ github.sha }} --no-restore
69+
run: >
70+
dotnet build
71+
--configuration Release
72+
-p:Version=${{ github.ref_name }}
73+
-p:GitSha=${{ github.sha }}
7574
7675
- name: 📝 Generate Release Notes
7776
run: gh release create ${{ github.ref_name }} --draft --generate-notes nugets/*.nupkg

src/AutoCtor.Tests/AutoCtor.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
</ItemGroup>
4141

4242
<ItemGroup>
43-
<PackageReference Include="GitHubActionsTestLogger" PrivateAssets="all" />
4443
<PackageReference Include="MarkdownSnippets.MsBuild" PrivateAssets="all" />
4544
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
4645
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" />

src/AutoCtor.Tests/ExampleTests.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Immutable;
2-
using System.Xml.Linq;
32
using Microsoft.CodeAnalysis;
43
using Microsoft.CodeAnalysis.CSharp;
54
using static ExampleTestsHelper;
@@ -82,40 +81,32 @@ await AssertRunsEqual(firstResult, secondResult,
8281

8382
private static CompilationBuilder CreateCompilation(CodeFileTheoryData theoryData)
8483
{
85-
var srcDir = BaseDir?.Parent;
86-
var packageVersionsFile = Path.Combine(srcDir?.FullName ?? "", "Directory.Packages.props");
87-
88-
var doc = XDocument.Load(packageVersionsFile);
89-
var versionXml = doc.Root?.Descendants("PackageVersion")
90-
.FirstOrDefault(el => el.Attribute("Include")?.Value == "Microsoft.Extensions.DependencyInjection.Abstractions");
91-
92-
var version = versionXml?.Attribute("Version")?.Value ?? "9.0.8";
84+
var version = TestFileHelper.GetPackageVersion("Microsoft.Extensions.DependencyInjection.Abstractions");
9385

9486
return CreateCompilation<AutoConstructAttribute>(theoryData)
95-
.AddNugetReference(
96-
"Microsoft.Extensions.DependencyInjection.Abstractions", version);
87+
.AddNugetReference("Microsoft.Extensions.DependencyInjection.Abstractions", version);
9788
}
9889

99-
private static DirectoryInfo? BaseDir { get; } = new DirectoryInfo(Environment.CurrentDirectory)?.Parent?.Parent;
100-
101-
private static IEnumerable<string> GetExamplesFiles(string path) => Directory.GetFiles(Path.Combine(BaseDir?.FullName ?? "", path), "*.cs").Where(e => !e.Contains(".g."));
90+
private static IEnumerable<string> GetExamplesFiles(string path)
91+
=> Directory.GetFiles(Path.Combine(TestFileHelper.BaseDir?.FullName ?? "", path), "*.cs")
92+
.Where(e => !e.Contains(".g."));
10293

103-
public static IEnumerable<CodeFileTheoryData> GetExamples()
94+
public static IEnumerable<Func<CodeFileTheoryData>> GetExamples()
10495
{
105-
if (BaseDir == null)
96+
if (TestFileHelper.BaseDir is null)
10697
throw new Exception("BaseDir is null");
10798

10899
foreach (var example in GetExamplesFiles("Examples"))
109100
{
110-
yield return new CodeFileTheoryData(example) with
101+
yield return () => new CodeFileTheoryData(example) with
111102
{
112103
IgnoredCompileDiagnostics = ["CS0414", "CS0169"] // Ignore unused fields
113104
};
114105
}
115106

116107
foreach (var guardExample in GetExamplesFiles("GuardExamples"))
117108
{
118-
yield return new CodeFileTheoryData(guardExample) with
109+
yield return () => new CodeFileTheoryData(guardExample) with
119110
{
120111
Options = new() { { "build_property.AutoCtorGuards", "true" } }
121112
};
@@ -124,7 +115,7 @@ public static IEnumerable<CodeFileTheoryData> GetExamples()
124115
foreach (var langExample in GetExamplesFiles("LangExamples"))
125116
{
126117
var verifiedName = string.Concat("Verified_", PreprocessorSymbols.Last().AsSpan(7));
127-
yield return new CodeFileTheoryData(langExample) with
118+
yield return () => new CodeFileTheoryData(langExample) with
128119
{
129120
VerifiedDirectory = Path.Combine(Path.GetDirectoryName(langExample) ?? "", verifiedName),
130121
LangPreview = true,

src/AutoCtor.Tests/Utilities/CompilationBuilder.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
internal class CompilationBuilder
77
{
88
private const string DEFAULT_TARGET_FRAMEWORK = "net9.0";
9-
private const string NETCORE_VERSION = "9.0.8";
109

1110
private ImmutableArray<ReferenceAssemblies> _nugetReferences;
1211
private ImmutableArray<MetadataReference> _references;
@@ -51,24 +50,24 @@ public async Task<CSharpCompilation> Build(string assemblyName)
5150
.WithOptions(_compilationOptions);
5251
}
5352

54-
public CompilationBuilder AddNugetReference(string id, string version, string targetFramework = "", string path = "")
53+
public CompilationBuilder AddNugetReference(string id, string version, string targetFramework = DEFAULT_TARGET_FRAMEWORK, string path = "")
5554
{
56-
var framework = string.IsNullOrEmpty(targetFramework) ? DEFAULT_TARGET_FRAMEWORK : targetFramework;
57-
5855
return new(this)
5956
{
6057
_nugetReferences = _nugetReferences.Add(new(
61-
framework,
58+
targetFramework,
6259
new(id, version),
63-
Path.Join(string.IsNullOrEmpty(path) ? "lib" : path, framework)
60+
Path.Join(string.IsNullOrEmpty(path) ? "lib" : path, targetFramework)
6461
))
6562
};
6663
}
6764

68-
public CompilationBuilder AddNetCoreReference(string targetFramework = "", string version = NETCORE_VERSION)
65+
public CompilationBuilder AddNetCoreReference(
66+
string targetFramework = DEFAULT_TARGET_FRAMEWORK,
67+
string? version = null)
6968
=> AddNugetReference(
7069
"Microsoft.NETCore.App.Ref",
71-
version,
70+
version ?? TestFileHelper.GetPackageVersion("Microsoft.NETCore.App.Ref"),
7271
targetFramework,
7372
"ref");
7473

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Xml.Linq;
2+
3+
public static class TestFileHelper
4+
{
5+
public static DirectoryInfo? BaseDir { get; } = new DirectoryInfo(Environment.CurrentDirectory)?.Parent?.Parent;
6+
7+
private static XDocument? _packageVersionDoc;
8+
private static XDocument PackageVersionDoc
9+
{
10+
get
11+
{
12+
if (_packageVersionDoc is null)
13+
{
14+
var srcDir = BaseDir?.Parent;
15+
var packageVersionsFile = Path.Combine(srcDir?.FullName ?? "", "Directory.Packages.props");
16+
_packageVersionDoc = XDocument.Load(packageVersionsFile);
17+
}
18+
return _packageVersionDoc;
19+
}
20+
}
21+
22+
public static string GetPackageVersion(string packageName)
23+
{
24+
var versionXml = PackageVersionDoc.Root?.Descendants("PackageVersion")
25+
.FirstOrDefault(el => el.Attribute("Include")?.Value == packageName);
26+
27+
return versionXml?.Attribute("Version")?.Value
28+
?? throw new Exception($"{packageName} missing from Directory.Packages.props");
29+
}
30+
}

src/AutoCtor.Tests/VerifyChecksTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using VerifyTUnit;
2-
3-
namespace AutoCtor.Tests;
1+
namespace AutoCtor.Tests;
42

53
public class VerifyChecksTests
64
{

src/Directory.Packages.props

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
87
<PackageVersion Include="MarkdownSnippets.MsBuild" Version="27.0.2" />
98
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
109
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
1110
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
12-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
13-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
11+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.10" />
12+
<PackageVersion Include="Microsoft.NETCore.App.Ref" Version="9.0.10" />
13+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
1414
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
15-
<PackageVersion Include="TUnit" Version="0.67.19" />
15+
<PackageVersion Include="TUnit" Version="0.75.0" />
1616
<PackageVersion Include="Verify.DiffPlex" Version="3.1.2" />
1717
<PackageVersion Include="Verify.SourceGenerators" Version="2.5.0" />
18-
<PackageVersion Include="Verify.TUnit" Version="31.0.1" />
18+
<PackageVersion Include="Verify.TUnit" Version="31.0.4" />
1919
</ItemGroup>
20-
</Project>
20+
</Project>

0 commit comments

Comments
 (0)