-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
040467d
commit 1ac26e3
Showing
10 changed files
with
94 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
namespace Core.ServiceMesh.Abstractions; | ||
|
||
[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)] | ||
public class ServiceMeshAttribute(string name) : Attribute | ||
public class ServiceMeshAttribute(string? name = null) : Attribute | ||
{ | ||
/// <summary> | ||
/// Unique service name. | ||
/// May also include versioning information | ||
/// e.g. SampleServiceV2 | ||
/// </summary> | ||
public string Name => name; | ||
public string Name => name ?? string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Core.ServiceMesh.Abstractions; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
|
||
namespace Core.ServiceMesh.SourceGen.Tests; | ||
|
||
public static class TestHelper | ||
{ | ||
public static async Task VerifySourceGen(string source) | ||
{ | ||
var syntaxTree = CSharpSyntaxTree.ParseText(source); | ||
|
||
// force reference | ||
typeof(ServiceMeshAttribute).ToString(); | ||
|
||
var references = AppDomain | ||
.CurrentDomain.GetAssemblies() | ||
.Where(assembly => !assembly.IsDynamic) | ||
.Select(assembly => MetadataReference.CreateFromFile(assembly.Location)) | ||
.Cast<MetadataReference>(); | ||
|
||
var compilation = CSharpCompilation.Create( | ||
"SourceGeneratorTests", | ||
[syntaxTree], | ||
references, | ||
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) | ||
); | ||
|
||
var sourceDiagnostics = compilation.GetDiagnostics(); | ||
var errors = sourceDiagnostics | ||
.Where(d => d.Severity == DiagnosticSeverity.Error).ToList(); | ||
|
||
Assert.Empty(errors); | ||
|
||
var generator = new ServiceMeshGenerator(); | ||
|
||
var driver = CSharpGeneratorDriver.Create(generator) | ||
.RunGeneratorsAndUpdateCompilation(compilation, out var outputCompilation, out _); | ||
|
||
foreach (var tree in outputCompilation.SyntaxTrees.Skip(1)) | ||
{ | ||
var genSource = tree.ToString(); | ||
var genErrors = tree.GetDiagnostics().Where(x => x.Severity == DiagnosticSeverity.Error); | ||
|
||
Assert.Empty(genErrors); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters