Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -134,8 +135,8 @@ public Task SimpleProjectableComputedInNestedClassProperty()
using System;
using EntityFrameworkCore.Projectables;
namespace Foo {
class C {
class D {
public class C {
public class D {
public int Bar { get; set; }

[Projectable]
Expand Down Expand Up @@ -2540,7 +2541,7 @@ public record Entity

#region Helpers

Compilation CreateCompilation(string source, bool expectedToCompile = true)
Compilation CreateCompilation([StringSyntax("csharp")] string source, bool expectedToCompile = true)
{
var references = Basic.Reference.Assemblies.
#if NET10_0
Expand Down Expand Up @@ -2592,7 +2593,7 @@ private GeneratorDriverRunResult RunGenerator(Compilation compilation)
var subject = new ProjectionExpressionGenerator();
var driver = CSharpGeneratorDriver
.Create(subject)
.RunGenerators(compilation);
.RunGeneratorsAndUpdateCompilation(compilation, out var outputCompilation, out _);

var result = driver.GetRunResult();

Expand All @@ -2602,11 +2603,11 @@ private GeneratorDriverRunResult RunGenerator(Compilation compilation)
}
else
{
_testOutputHelper.WriteLine($"Diagnostics produced:");
_testOutputHelper.WriteLine("Diagnostics produced:");

foreach (var diagnostic in result.Diagnostics)
{
_testOutputHelper.WriteLine($" > " + diagnostic.ToString());
_testOutputHelper.WriteLine(" > " + diagnostic);
}
}

Expand All @@ -2616,7 +2617,30 @@ private GeneratorDriverRunResult RunGenerator(Compilation compilation)
_testOutputHelper.WriteLine(newSyntaxTree.GetText().ToString());
}

return driver.GetRunResult();
// Verify that the generated code compiles without errors
var hasGeneratorErrors = result.Diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error);
if (!hasGeneratorErrors && result.GeneratedTrees.Length > 0)
{
_testOutputHelper.WriteLine("Checking that generated code compiles...");

var compilationErrors = outputCompilation
.GetDiagnostics()
.Where(d => d.Severity == DiagnosticSeverity.Error)
.ToList();

if (compilationErrors.Count > 0)
{
_testOutputHelper.WriteLine("Generated code produced compilation errors:");
foreach (var error in compilationErrors)
{
_testOutputHelper.WriteLine(" > " + error);
}
}

Assert.Empty(compilationErrors);
}

return result;
}

#endregion
Expand Down