Skip to content

feat: Exclude generated attributes from code coverage #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public string Build()
cb.AppendLine(
"[global::System.CodeDom.Compiler.GeneratedCode(\"AutomaticInterface\", \"\")]"
);
cb.AppendLine($"{(asInternal ? "internal" : "public")} partial interface {interfaceName}{genericType}");
cb.AppendLine(
$"{(asInternal ? "internal" : "public")} partial interface {interfaceName}{genericType}"
);
cb.AppendLine("{");

cb.Indent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace AutomaticInterface
/// <param name="namespaceName">Namespace name for the generated interface. Defaults to the same namespace as the class.</param>
/// <param name="interfaceName">Interface name for the generated interface. Defaults to an interface version of the class name.</param>
[AttributeUsage(AttributeTargets.Class)]
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal sealed class {{{AutomaticInterfaceGenerator.DefaultAttributeName}}}Attribute : Attribute
{
internal {{{AutomaticInterfaceGenerator.DefaultAttributeName}}}Attribute(string {{{AutomaticInterfaceGenerator.NamespaceParameterName}}} = "", string {{{AutomaticInterfaceGenerator.InterfaceParameterName}}} = "", bool asInternal = false) { }
Expand Down Expand Up @@ -59,6 +61,8 @@ namespace AutomaticInterface
/// Ignore this member in a generated Interface from this class
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event)]
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal sealed class {{{AutomaticInterfaceGenerator.IgnoreAutomaticInterfaceAttributeName}}}Attribute : Attribute
{
internal {{{AutomaticInterfaceGenerator.IgnoreAutomaticInterfaceAttributeName}}}Attribute() { }
Expand Down
16 changes: 8 additions & 8 deletions AutomaticInterface/Tests/Misc/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ class DemoClass
}

[Fact]
public async Task AsInternal()
{
public async Task AsInternal()
{
const string code = """

using AutomaticInterface;
Expand All @@ -381,13 +381,13 @@ public string AMethod(DemoClass? x, string y)
}
}

""";
""";
await Verify(Infrastructure.GenerateCode(code));
}
}

[Fact]
public async Task AsInternalExplicitFalse()
{
public async Task AsInternalExplicitFalse()
{
const string code = """

using AutomaticInterface;
Expand All @@ -401,7 +401,7 @@ public string AMethod(DemoClass? x, string y)
}
}

""";
""";
await Verify(Infrastructure.GenerateCode(code));
}
}
Loading