-
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.
Add report diagnostics + tests coverage (#28)
- Loading branch information
1 parent
e02c9fe
commit 81728bf
Showing
20 changed files
with
666 additions
and
87 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
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 |
---|---|---|
@@ -1,12 +1,22 @@ | ||
namespace Typely.Generators; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Typely.Generators; | ||
|
||
internal static class DiagnosticDescriptors | ||
{ | ||
//public static DiagnosticDescriptor InvalidLoggingMethodName { get; } = new DiagnosticDescriptor( | ||
//id: "SYSLIB1001", | ||
//title: new LocalizableResourceString(nameof(SR.InvalidLoggingMethodNameMessage), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)), | ||
//messageFormat: new LocalizableResourceString(nameof(SR.InvalidLoggingMethodNameMessage), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)), | ||
//category: "LoggingGenerator", | ||
//DiagnosticSeverity.Error, | ||
//isEnabledByDefault: true); | ||
public static DiagnosticDescriptor TypeNameMissing { get; } = new( | ||
id: "TYPLY0001", | ||
title: "Type name missing.", | ||
messageFormat: "A type is declared without a name in the namespace '{0}'.", | ||
category: "TypelyGenerator", | ||
DiagnosticSeverity.Error, | ||
isEnabledByDefault: true); | ||
|
||
public static DiagnosticDescriptor NameMissing { get; } = new( | ||
id: "TYPLY0002", | ||
title: "Name missing.", | ||
messageFormat: "A type is declared without a user friendly name in the namespace '{0}'.", | ||
category: "TypelyGenerator", | ||
DiagnosticSeverity.Error, | ||
isEnabledByDefault: true); | ||
} |
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
12 changes: 12 additions & 0 deletions
12
tests/Typely.Generators.Tests/Typely/Configurations/MissingTypeNameConfiguration.cs
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,12 @@ | ||
using Typely.Core; | ||
using Typely.Core.Builders; | ||
|
||
namespace Typely.Generators.Tests.Typely.Configurations; | ||
|
||
public class MissingTypeNameConfiguration : ITypelyConfiguration | ||
{ | ||
public void Configure(ITypelyBuilder builder) | ||
{ | ||
builder.OfBool(); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
tests/Typely.Generators.Tests/Typely/Emitting/EmitterTests.cs
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,29 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Typely.Generators.Typely.Emitting; | ||
using Typely.Generators.Typely.Parsing; | ||
|
||
namespace Typely.Generators.Tests.Typely.Emitting; | ||
|
||
public class EmitterTests | ||
{ | ||
[Fact] | ||
public void Emitter_Should_OutputDiagnostics_When_TypeNameIsNull() | ||
{ | ||
var diagnostics = new List<Diagnostic>(); | ||
var emitter = new Emitter(diagnostic => diagnostics.Add(diagnostic), CancellationToken.None); | ||
var emittableType = new EmittableType("int", true, "namespace"); | ||
emittableType.SetName("aa"); | ||
emitter.Emit(emittableType); | ||
Assert.NotEmpty(diagnostics); | ||
} | ||
|
||
[Fact] | ||
public void Emitter_Should_OutputDiagnostics_When_NameIsNull() | ||
{ | ||
var diagnostics = new List<Diagnostic>(); | ||
var emitter = new Emitter(diagnostic => diagnostics.Add(diagnostic), CancellationToken.None); | ||
var emittableType = new EmittableType("int", true, "namespace"); | ||
emitter.Emit(emittableType); | ||
Assert.NotEmpty(diagnostics); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/Typely.Generators.Tests/Typely/Parsing/EmittableTypeBuilderFactoryTests.cs
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,16 @@ | ||
using Typely.Generators.Typely.Parsing; | ||
using Typely.Generators.Typely.Parsing.TypeBuilders; | ||
|
||
namespace Typely.Generators.Tests.Typely.Parsing; | ||
|
||
public class EmittableTypeBuilderFactoryTests | ||
{ | ||
[Fact] | ||
public void UnsupportedType_Should_Throw() | ||
{ | ||
var statement = new ParsedStatement(null!) { Root = "builder", }; | ||
statement.Invocations.Add(new ParsedInvocation(null!, "OfUnsupportedType")); | ||
|
||
Assert.Throws<NotSupportedException>(() => EmittableTypeBuilderFactory.Create("namespace", statement)); | ||
} | ||
} |
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
Oops, something went wrong.