Skip to content

Commit

Permalink
Setup Baseline Compare
Browse files Browse the repository at this point in the history
  • Loading branch information
justindbaur committed Nov 20, 2023
1 parent 94458e6 commit 935bce8
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 115 deletions.
File renamed without changes.
7 changes: 5 additions & 2 deletions pretender.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pretender.SourceGenerator",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2667A3D7-30CA-4DF5-B2F4-A7554C6D3ADD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceGeneratorTests", "test\SourceGeneratorTests\SourceGeneratorTests.csproj", "{09EB76D6-C82D-48A9-A0F7-B9BCC10B7621}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pretender.SourceGenerator.SpecTests", "test\SourceGeneratorTests\Pretender.SourceGenerator.SpecTests.csproj", "{09EB76D6-C82D-48A9-A0F7-B9BCC10B7621}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9E33F6C1-8032-4CCA-A485-685B730A6EAE}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "example\Example.csproj", "{6D387D31-B80A-4E0C-A0F8-066185964A44}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.Tests", "example\Example.Tests.csproj", "{6D387D31-B80A-4E0C-A0F8-066185964A44}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "perf", "perf", "{DA78B66F-EE75-46B5-8EC8-6F498A8AFC64}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Comparison", "perf\Comparison\Comparison.csproj", "{96C653E3-D10B-47A0-8E42-0B93119AE145}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pretender.Tests", "test\Pretender.Tests\Pretender.Tests.csproj", "{17552274-CC28-438A-80BB-4A161F95AB11}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "example", "example", "{3BF89FF8-E743-46DF-BC57-F4B617DB8D92}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -117,6 +119,7 @@ Global
{F22B60A6-3E45-42EE-842D-321232A90968} = {DFB5E6EE-B017-40FD-BC67-CE0471060A68}
{90CC0802-39BB-4390-8A06-C7FD0C14D5C7} = {DFB5E6EE-B017-40FD-BC67-CE0471060A68}
{09EB76D6-C82D-48A9-A0F7-B9BCC10B7621} = {2667A3D7-30CA-4DF5-B2F4-A7554C6D3ADD}
{6D387D31-B80A-4E0C-A0F8-066185964A44} = {3BF89FF8-E743-46DF-BC57-F4B617DB8D92}
{96C653E3-D10B-47A0-8E42-0B93119AE145} = {DA78B66F-EE75-46B5-8EC8-6F498A8AFC64}
{17552274-CC28-438A-80BB-4A161F95AB11} = {2667A3D7-30CA-4DF5-B2F4-A7554C6D3ADD}
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion src/Pretender/Pretend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Verify(IPretendSetup<T> pretendSetup, Called called)
// TODO: Make this obsolete
public void Handle(CallInfo callInfo)
{
_calls = [];
_calls ??= [];
_calls.Add(callInfo);

if (_setups != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace System.Runtime.CompilerServices
{
using System;
using System.CodeDom.Compiler;

[GeneratedCode("Pretender.SourceGenerator", "1.0.0.0")]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
file sealed class InterceptsLocationAttribute : Attribute
{
public InterceptsLocationAttribute(string filePath, int line, int column)
{
}
}
}

namespace Pretender.SourceGeneration
{
using System.Runtime.CompilerServices;
using Pretender;

file static class CreateInterceptors
{
[InterceptsLocation("MyTest.cs", 16, 38)]
internal static global::ISimpleInterface Create0(this Pretend<global::ISimpleInterface> pretend)
{
return new PretendISimpleInterface8199A3(pretend);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace System.Runtime.CompilerServices
{
using System;
using System.CodeDom.Compiler;

[GeneratedCode("Pretender.SourceGenerator", "1.0.0.0")]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
file sealed class InterceptsLocationAttribute : Attribute
{
public InterceptsLocationAttribute(string filePath, int line, int column)
{
}
}
}

namespace Pretender.SourceGeneration
{
using System;
using System.Runtime.CompilerServices;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Pretender;
using Pretender.Internals;

file static class SetupInterceptors
{
[InterceptsLocation("MyTest.cs", 13, 6)]
internal static IPretendSetup<global::ISimpleInterface, string> Setup0(this Pretend<global::ISimpleInterface> pretend, Func<global::ISimpleInterface, string> setupExpression)
{
return pretend.GetOrCreateSetup<string>(0, static (pretend, expr) =>
{
return new ReturningCompiledSetup<global::ISimpleInterface, string>(pretend, PretendISimpleInterface8199A3.MethodInfo_get_Bar_3685A65, matcher: Cache.NoOpMatcher, expr.Target, defaultValue: default);
}, setupExpression);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// <auto-generated/>
#nullable enable
/// <inheritdoc/>
namespace Pretender.SourceGeneration
{
using System.Reflection;
using Pretender;

/// <inheritdoc/>
internal class PretendISimpleInterface8199A3 : global::ISimpleInterface
{
public static readonly MethodInfo MethodInfo_Foo_3EB6F56 = typeof(global::ISimpleInterface).GetMethod(nameof(Foo))!;
public static readonly MethodInfo MethodInfo_VoidMethod_4CB5F7 = typeof(global::ISimpleInterface).GetMethod(nameof(VoidMethod))!;
public static readonly MethodInfo MethodInfo_AsyncMethod_3177B39 = typeof(global::ISimpleInterface).GetMethod(nameof(AsyncMethod))!;
public static readonly MethodInfo MethodInfo_AsyncReturningMethod_35E1C1E = typeof(global::ISimpleInterface).GetMethod(nameof(AsyncReturningMethod))!;
public static readonly MethodInfo MethodInfo_TryParse_3859BF9 = typeof(global::ISimpleInterface).GetMethod(nameof(TryParse))!;
public static readonly MethodInfo MethodInfo_get_Bar_3685A65 = typeof(global::ISimpleInterface).GetProperty(nameof(Bar)).GetMethod!;
public static readonly MethodInfo MethodInfo_set_Bar_2D53694 = typeof(global::ISimpleInterface).GetProperty(nameof(Bar)).SetMethod!;
private readonly Pretend<global::ISimpleInterface> _pretend;
/// <inheritdoc/>
public PretendISimpleInterface8199A3(Pretend<global::ISimpleInterface> pretend)
{
_pretend = pretend;
}

public string? Foo(string? bar, int baz)
{
object? [] __arguments = [bar, baz];
var __callInfo = new CallInfo(MethodInfo_Foo_3EB6F56, __arguments);
_pretend.Handle(__callInfo);
return (string? )__callInfo.ReturnValue;
}

public void VoidMethod(bool baz)
{
object? [] __arguments = [baz];
var __callInfo = new CallInfo(MethodInfo_VoidMethod_4CB5F7, __arguments);
_pretend.Handle(__callInfo);
}

public global::System.Threading.Tasks.Task AsyncMethod()
{
object? [] __arguments = [];
var __callInfo = new CallInfo(MethodInfo_AsyncMethod_3177B39, __arguments);
_pretend.Handle(__callInfo);
return (global::System.Threading.Tasks.Task)__callInfo.ReturnValue;
}

public global::System.Threading.Tasks.Task<string> AsyncReturningMethod(string bar)
{
object? [] __arguments = [bar];
var __callInfo = new CallInfo(MethodInfo_AsyncReturningMethod_35E1C1E, __arguments);
_pretend.Handle(__callInfo);
return (global::System.Threading.Tasks.Task<string>)__callInfo.ReturnValue;
}

public bool TryParse(string thing, out bool myValue)
{
object? [] __arguments = [thing, myValue];
var __callInfo = new CallInfo(MethodInfo_TryParse_3859BF9, __arguments);
_pretend.Handle(__callInfo);
myValue = __arguments[1];
return (bool)__callInfo.ReturnValue;
}

public string Bar
{
get
{
object? [] __arguments = [];
var __callInfo = new CallInfo(MethodInfo_get_Bar_3685A65, __arguments);
_pretend.Handle(__callInfo);
return (string)__callInfo.ReturnValue;
}

set
{
object? [] __arguments = [value];
var __callInfo = new CallInfo(MethodInfo_set_Bar_2D53694, __arguments);
_pretend.Handle(__callInfo);
}
}
}
}
35 changes: 3 additions & 32 deletions test/SourceGeneratorTests/MainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,15 @@ public partial class MainTests : TestBase
[Fact]
public async Task ReturningMethod()
{
var (result, compilation) = await RunGeneratorAsync($$"""
await RunAndCompareAsync($$"""
var pretendSimpleInterface = Pretend.That<ISimpleInterface>();
pretendSimpleInterface
.Setup(i => i.Bar)
.Returns("Hi");
var pretend = pretendSimpleInterface.Create();
pretendSimpleInterface.Verify(i => i.Bar, 2);
""");

Assert.Equal(4, result.GeneratedSources.Length);

//Assert.All(result.GeneratedSources, (result) =>
//{
// CompareAgainstBaseline(result);
//});
var source1 = result.GeneratedSources[0];
var text1 = source1.SourceText.ToString();
var source2 = result.GeneratedSources[1];
var text2 = source2.SourceText.ToString();
var source3 = result.GeneratedSources[2];
var text3 = source3.SourceText.ToString();
var source4 = result.GeneratedSources[3];
var text4 = source4.SourceText.ToString();
}


Expand All @@ -40,18 +23,6 @@ public async Task Test2()
var (result, compilation) = await RunGeneratorAsync($$"""
var pretendSimpleInterface = Pretend.That<SimpleAbstractClass>();
pretendSimpleInterface
.Setup(i => i.Foo("1", 2))
.Returns("Hello");
pretendSimpleInterface
.Setup(i => i.Foo("1", 2))
.Returns("Hello");
pretendSimpleInterface
.Setup(i => i.Foo("2", 3))
.Returns("Bye!");
var simpleInterface = pretendSimpleInterface.Create();
""");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Baselines\**\*.txt" />
<EmbeddedResource Include="Baselines\**\*.cs" />
</ItemGroup>

<ItemGroup>
<Compile Remove="Baselines\**\*.cs" />
</ItemGroup>

</Project>
Loading

0 comments on commit 935bce8

Please sign in to comment.