From 614706442a3a16aadd095c4e21e3dd3e05e4e015 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Tue, 3 Sep 2024 15:13:15 +0100 Subject: [PATCH 1/2] chore: use `IgnoreGeneratedResult` to ignore unrelated files --- Refit.GeneratorTests/Fixture.cs | 12 +++++++--- ...ainedInterfaceTest#Generated.g.verified.cs | 24 ------------------- ...erfaceTest#PreserveAttribute.g.verified.cs | 19 --------------- ...RefitInterfaceTest#Generated.g.verified.cs | 24 ------------------- ...erfaceTest#PreserveAttribute.g.verified.cs | 19 --------------- ...RefitInterfaceTest#Generated.g.verified.cs | 24 ------------------- ...erfaceTest#PreserveAttribute.g.verified.cs | 19 --------------- ...lobalNamespaceTest#Generated.g.verified.cs | 24 ------------------- ...espaceTest#PreserveAttribute.g.verified.cs | 19 --------------- ...estedNamespaceTest#Generated.g.verified.cs | 24 ------------------- ...espaceTest#PreserveAttribute.g.verified.cs | 19 --------------- ...ericTaskShouldWork#Generated.g.verified.cs | 24 ------------------- ...ShouldWork#PreserveAttribute.g.verified.cs | 19 --------------- ...VoidTaskShouldWork#Generated.g.verified.cs | 24 ------------------- ...ShouldWork#PreserveAttribute.g.verified.cs | 19 --------------- 15 files changed, 9 insertions(+), 304 deletions(-) delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs delete mode 100644 Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs diff --git a/Refit.GeneratorTests/Fixture.cs b/Refit.GeneratorTests/Fixture.cs index affae8dab..344ee4613 100644 --- a/Refit.GeneratorTests/Fixture.cs +++ b/Refit.GeneratorTests/Fixture.cs @@ -33,7 +33,7 @@ public static class Fixture .Where(a => !a.IsDynamic) .ToArray(); - public static Task VerifyForBody(string body) + public static Task VerifyForBody(string body, bool ignoreNonInterfaces = true) { var source = $$""" @@ -120,7 +120,7 @@ private static CSharpCompilation CreateLibrary(params string[] source) return compilation; } - private static Task VerifyGenerator(string source) + private static Task VerifyGenerator(string source, bool ignoreNonInterfaces = true) { var compilation = CreateLibrary(source); @@ -129,7 +129,13 @@ private static Task VerifyGenerator(string source) var ranDriver = driver.RunGenerators(compilation); var settings = new VerifySettings(); - var verify = VerifyXunit.Verifier.Verify(ranDriver, settings); + if (ignoreNonInterfaces) + { + settings.IgnoreGeneratedResult(x => x.HintName.Contains("PreserveAttribute.g.cs", StringComparison.Ordinal)); + settings.IgnoreGeneratedResult(x => x.HintName.Contains("Generated.g.cs", StringComparison.Ordinal)); + } + + var verify = Verify(ranDriver, settings); return verify.ToTask(); } } diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.ContainedInterfaceTest#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedNonRefitInterfaceTest#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.DerivedRefitInterfaceTest#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.GlobalNamespaceTest#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/InterfaceTests.NestedNamespaceTest#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.GenericTaskShouldWork#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs deleted file mode 100644 index 4470d5d71..000000000 --- a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#Generated.g.verified.cs +++ /dev/null @@ -1,24 +0,0 @@ -//HintName: Generated.g.cs - -#pragma warning disable -namespace Refit.Implementation -{ - - /// - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.Diagnostics.DebuggerNonUserCode] - [global::RefitInternalGenerated.PreserveAttribute] - [global::System.Reflection.Obfuscation(Exclude=true)] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - internal static partial class Generated - { -#if NET5_0_OR_GREATER - [System.Runtime.CompilerServices.ModuleInitializer] - [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] - public static void Initialize() - { - } -#endif - } -} -#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs deleted file mode 100644 index 71b34929f..000000000 --- a/Refit.GeneratorTests/_snapshots/ReturnTypeTests.VoidTaskShouldWork#PreserveAttribute.g.verified.cs +++ /dev/null @@ -1,19 +0,0 @@ -//HintName: PreserveAttribute.g.cs - -#pragma warning disable -namespace RefitInternalGenerated -{ - [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] - sealed class PreserveAttribute : global::System.Attribute - { - // - // Fields - // - public bool AllMembers; - - public bool Conditional; - } -} -#pragma warning restore From c08e83c0aced0895cf1e83d7f464d8c92b2685fa Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Tue, 3 Sep 2024 15:16:52 +0100 Subject: [PATCH 2/2] feat: added test to verify generated files --- Refit.GeneratorTests/Fixture.cs | 2 +- Refit.GeneratorTests/GeneratedTest.cs | 14 ++++ ...ShouldEmitAllFiles#Generated.g.verified.cs | 24 +++++++ ...mitAllFiles#IGeneratedClient.g.verified.cs | 66 +++++++++++++++++++ ...itAllFiles#PreserveAttribute.g.verified.cs | 19 ++++++ ...e.DotNet6_0#IGeneratedClient.g.received.cs | 66 +++++++++++++++++++ 6 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 Refit.GeneratorTests/GeneratedTest.cs create mode 100644 Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#Generated.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#PreserveAttribute.g.verified.cs create mode 100644 Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs diff --git a/Refit.GeneratorTests/Fixture.cs b/Refit.GeneratorTests/Fixture.cs index 344ee4613..3b779981f 100644 --- a/Refit.GeneratorTests/Fixture.cs +++ b/Refit.GeneratorTests/Fixture.cs @@ -54,7 +54,7 @@ public interface IGeneratedClient } """; - return VerifyGenerator(source); + return VerifyGenerator(source, ignoreNonInterfaces); } public static Task VerifyForType(string declarations) diff --git a/Refit.GeneratorTests/GeneratedTest.cs b/Refit.GeneratorTests/GeneratedTest.cs new file mode 100644 index 000000000..b75ce1571 --- /dev/null +++ b/Refit.GeneratorTests/GeneratedTest.cs @@ -0,0 +1,14 @@ +namespace Refit.GeneratorTests; + +public class GeneratedTest +{ + [Fact] + public Task ShouldEmitAllFiles() + { + return Fixture.VerifyForBody( + """ + [Get("/users")] + Task Get(); + """, false); + } +} diff --git a/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#Generated.g.verified.cs b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#Generated.g.verified.cs new file mode 100644 index 000000000..4470d5d71 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#Generated.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: Generated.g.cs + +#pragma warning disable +namespace Refit.Implementation +{ + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + internal static partial class Generated + { +#if NET5_0_OR_GREATER + [System.Runtime.CompilerServices.ModuleInitializer] + [System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::Refit.Implementation.Generated))] + public static void Initialize() + { + } +#endif + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs new file mode 100644 index 000000000..19a9fc649 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#IGeneratedClient.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedClient.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedClient + : global::RefitGeneratorTest.IGeneratedClient + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#PreserveAttribute.g.verified.cs b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#PreserveAttribute.g.verified.cs new file mode 100644 index 000000000..71b34929f --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitAllFiles#PreserveAttribute.g.verified.cs @@ -0,0 +1,19 @@ +//HintName: PreserveAttribute.g.cs + +#pragma warning disable +namespace RefitInternalGenerated +{ + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.AttributeUsage (global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Field | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Delegate)] + sealed class PreserveAttribute : global::System.Attribute + { + // + // Fields + // + public bool AllMembers; + + public bool Conditional; + } +} +#pragma warning restore diff --git a/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs new file mode 100644 index 000000000..19a9fc649 --- /dev/null +++ b/Refit.GeneratorTests/_snapshots/GeneratedTest.ShouldEmitGeneratedAndPreserve.DotNet6_0#IGeneratedClient.g.received.cs @@ -0,0 +1,66 @@ +//HintName: IGeneratedClient.g.cs +#nullable disable +#pragma warning disable +namespace Refit.Implementation +{ + + partial class Generated + { + + /// + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::RefitInternalGenerated.PreserveAttribute] + [global::System.Reflection.Obfuscation(Exclude=true)] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + partial class RefitGeneratorTestIGeneratedClient + : global::RefitGeneratorTest.IGeneratedClient + + { + /// + public global::System.Net.Http.HttpClient Client { get; } + readonly global::Refit.IRequestBuilder requestBuilder; + + /// + public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder) + { + Client = client; + this.requestBuilder = requestBuilder; + } + + + + /// + public async global::System.Threading.Tasks.Task Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + + /// + async global::System.Threading.Tasks.Task global::RefitGeneratorTest.IGeneratedClient.Get() + { + var ______arguments = global::System.Array.Empty(); + var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty() ); + try + { + return await ((global::System.Threading.Tasks.Task)______func(this.Client, ______arguments)).ConfigureAwait(false); + } + catch (global::System.Exception ______ex) + { + throw ______ex; + } + } + } + } +} + +#pragma warning restore