chore: ignore repeat files and add test (#1804)
* chore: use `IgnoreGeneratedResult` to ignore unrelated files * feat: added test to verify generated files
This commit is contained in:
Родитель
47ce83ea8c
Коммит
782413588c
|
@ -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 =
|
||||
$$"""
|
||||
|
@ -54,7 +54,7 @@ public static class Fixture
|
|||
}
|
||||
""";
|
||||
|
||||
return VerifyGenerator(source);
|
||||
return VerifyGenerator(source, ignoreNonInterfaces);
|
||||
}
|
||||
|
||||
public static Task VerifyForType(string declarations)
|
||||
|
@ -120,7 +120,7 @@ public static class Fixture
|
|||
return compilation;
|
||||
}
|
||||
|
||||
private static Task<VerifyResult> VerifyGenerator(string source)
|
||||
private static Task<VerifyResult> VerifyGenerator(string source, bool ignoreNonInterfaces = true)
|
||||
{
|
||||
var compilation = CreateLibrary(source);
|
||||
|
||||
|
@ -129,7 +129,13 @@ public static class Fixture
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
namespace Refit.GeneratorTests;
|
||||
|
||||
public class GeneratedTest
|
||||
{
|
||||
[Fact]
|
||||
public Task ShouldEmitAllFiles()
|
||||
{
|
||||
return Fixture.VerifyForBody(
|
||||
"""
|
||||
[Get("/users")]
|
||||
Task<string> Get();
|
||||
""", false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
//HintName: IGeneratedClient.g.cs
|
||||
#nullable disable
|
||||
#pragma warning disable
|
||||
namespace Refit.Implementation
|
||||
{
|
||||
|
||||
partial class Generated
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[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
|
||||
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public global::System.Net.Http.HttpClient Client { get; }
|
||||
readonly global::Refit.IRequestBuilder requestBuilder;
|
||||
|
||||
/// <inheritdoc />
|
||||
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
|
||||
{
|
||||
Client = client;
|
||||
this.requestBuilder = requestBuilder;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async global::System.Threading.Tasks.Task<string> Get()
|
||||
{
|
||||
var ______arguments = global::System.Array.Empty<object>();
|
||||
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>() );
|
||||
try
|
||||
{
|
||||
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
|
||||
}
|
||||
catch (global::System.Exception ______ex)
|
||||
{
|
||||
throw ______ex;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get()
|
||||
{
|
||||
var ______arguments = global::System.Array.Empty<object>();
|
||||
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>() );
|
||||
try
|
||||
{
|
||||
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
|
||||
}
|
||||
catch (global::System.Exception ______ex)
|
||||
{
|
||||
throw ______ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore
|
|
@ -0,0 +1,66 @@
|
|||
//HintName: IGeneratedClient.g.cs
|
||||
#nullable disable
|
||||
#pragma warning disable
|
||||
namespace Refit.Implementation
|
||||
{
|
||||
|
||||
partial class Generated
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[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
|
||||
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public global::System.Net.Http.HttpClient Client { get; }
|
||||
readonly global::Refit.IRequestBuilder requestBuilder;
|
||||
|
||||
/// <inheritdoc />
|
||||
public RefitGeneratorTestIGeneratedClient(global::System.Net.Http.HttpClient client, global::Refit.IRequestBuilder requestBuilder)
|
||||
{
|
||||
Client = client;
|
||||
this.requestBuilder = requestBuilder;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async global::System.Threading.Tasks.Task<string> Get()
|
||||
{
|
||||
var ______arguments = global::System.Array.Empty<object>();
|
||||
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>() );
|
||||
try
|
||||
{
|
||||
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
|
||||
}
|
||||
catch (global::System.Exception ______ex)
|
||||
{
|
||||
throw ______ex;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
async global::System.Threading.Tasks.Task<string> global::RefitGeneratorTest.IGeneratedClient.Get()
|
||||
{
|
||||
var ______arguments = global::System.Array.Empty<object>();
|
||||
var ______func = requestBuilder.BuildRestResultFuncForMethod("Get", global::System.Array.Empty<global::System.Type>() );
|
||||
try
|
||||
{
|
||||
return await ((global::System.Threading.Tasks.Task<string>)______func(this.Client, ______arguments)).ConfigureAwait(false);
|
||||
}
|
||||
catch (global::System.Exception ______ex)
|
||||
{
|
||||
throw ______ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore
|
|
@ -1,24 +0,0 @@
|
|||
//HintName: Generated.g.cs
|
||||
|
||||
#pragma warning disable
|
||||
namespace Refit.Implementation
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[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
|
|
@ -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
|
|
@ -1,24 +0,0 @@
|
|||
//HintName: Generated.g.cs
|
||||
|
||||
#pragma warning disable
|
||||
namespace Refit.Implementation
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[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
|
|
@ -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
|
|
@ -1,24 +0,0 @@
|
|||
//HintName: Generated.g.cs
|
||||
|
||||
#pragma warning disable
|
||||
namespace Refit.Implementation
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[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
|
|
@ -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
|
|
@ -1,24 +0,0 @@
|
|||
//HintName: Generated.g.cs
|
||||
|
||||
#pragma warning disable
|
||||
namespace Refit.Implementation
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[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
|
|
@ -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
|
|
@ -1,24 +0,0 @@
|
|||
//HintName: Generated.g.cs
|
||||
|
||||
#pragma warning disable
|
||||
namespace Refit.Implementation
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[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
|
|
@ -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
|
|
@ -1,24 +0,0 @@
|
|||
//HintName: Generated.g.cs
|
||||
|
||||
#pragma warning disable
|
||||
namespace Refit.Implementation
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[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
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче