Skip to content

Commit

Permalink
Update Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justindbaur committed Nov 10, 2024
1 parent 7eaaf27 commit 98a62ae
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 24 deletions.
13 changes: 10 additions & 3 deletions src/Pretender.SourceGenerator/Emitter/CreateEmitter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Operations;
using Pretender.SourceGenerator.Parser;
using Pretender.SourceGenerator.Writing;
Expand All @@ -11,10 +12,14 @@ internal class CreateEmitter
private readonly IInvocationOperation _originalOperation;
private readonly KnownTypeSymbols _knownTypeSymbols;
private readonly ImmutableArray<ITypeSymbol>? _typeArguments;
private readonly ImmutableArray<InterceptsLocationInfo> _locations;
#pragma warning disable RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
private readonly ImmutableArray<InterceptableLocation> _locations;
#pragma warning restore RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
private readonly int _index;

public CreateEmitter(IInvocationOperation originalOperation, KnownTypeSymbols knownTypeSymbols, ImmutableArray<ITypeSymbol>? typeArguments, ImmutableArray<InterceptsLocationInfo> locations, int index)
#pragma warning disable RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
public CreateEmitter(IInvocationOperation originalOperation, KnownTypeSymbols knownTypeSymbols, ImmutableArray<ITypeSymbol>? typeArguments, ImmutableArray<InterceptableLocation> locations, int index)
#pragma warning restore RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
{
_originalOperation = originalOperation;
_knownTypeSymbols = knownTypeSymbols;
Expand All @@ -35,7 +40,9 @@ public void Emit(IndentedTextWriter writer, CancellationToken cancellationToken)

foreach (var location in _locations)
{
writer.WriteLine(@$"[InterceptsLocation(@""{location.FilePath}"", {location.LineNumber}, {location.CharacterNumber})]");
#pragma warning disable RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
writer.WriteLine(location.GetInterceptsLocationAttributeSyntax());
#pragma warning restore RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}
writer.Write($"internal static {returnType.ToUnknownTypeString()} Create{_index}");

Expand Down
2 changes: 1 addition & 1 deletion src/Pretender.SourceGenerator/KnownBlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace System.Runtime.CompilerServices
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
file sealed class InterceptsLocationAttribute : Attribute
{
public InterceptsLocationAttribute(string filePath, int line, int column)
public InterceptsLocationAttribute(int version, string data)
{
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/Pretender.SourceGenerator/Parser/CreateParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Pretender.SourceGenerator.Emitter;
using Pretender.SourceGenerator.Invocation;

Expand All @@ -8,11 +9,15 @@ namespace Pretender.SourceGenerator.Parser
internal class CreateParser
{
private readonly CreateInvocation _createInvocation;
private readonly ImmutableArray<InterceptsLocationInfo> _locations;
#pragma warning disable RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
private readonly ImmutableArray<InterceptableLocation> _locations;
#pragma warning restore RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
private readonly int _index;
private readonly KnownTypeSymbols _knownTypeSymbols;

public CreateParser(CreateInvocation createInvocation, ImmutableArray<InterceptsLocationInfo> locations, int index, KnownTypeSymbols knownTypeSymbols)
#pragma warning disable RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
public CreateParser(CreateInvocation createInvocation, ImmutableArray<InterceptableLocation> locations, int index, KnownTypeSymbols knownTypeSymbols)
#pragma warning restore RSEXPERIMENTAL002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
{
_createInvocation = createInvocation;
_locations = locations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace System.Runtime.CompilerServices
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
file sealed class InterceptsLocationAttribute : Attribute
{
public InterceptsLocationAttribute(string filePath, int line, int column)
public InterceptsLocationAttribute(int version, string data)
{
}
}
Expand Down Expand Up @@ -51,7 +51,7 @@ public void Method(string arg)

file static class SetupInterceptors
{
[InterceptsLocation(@"MyTest.cs", 22, 17)]
[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "xbIAQFg+yi3VoCyQ0Vr0a1IBAABNeVRlc3QuY3M=")]
internal static IPretendSetup<global::FieldReference.ITest> Setup0(this Pretend<global::FieldReference.ITest> pretend, Action<global::FieldReference.ITest> setupExpression)
{
return pretend.GetOrCreateSetup(0, static (pretend, expr) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace System.Runtime.CompilerServices
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
file sealed class InterceptsLocationAttribute : Attribute
{
public InterceptsLocationAttribute(string filePath, int line, int column)
public InterceptsLocationAttribute(int version, string data)
{
}
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public string Bar

file static class SetupInterceptors
{
[InterceptsLocation(@"MyTest.cs", 13, 6)]
[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "eVizwPmkdgJkF56KQQgEXv8AAABNeVRlc3QuY3M=")]
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) =>
Expand All @@ -123,7 +123,7 @@ file static class VerifyInterceptors

file static class CreateInterceptors
{
[InterceptsLocation(@"MyTest.cs", 16, 38)]
[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "eVizwPmkdgJkF56KQQgEXk4BAABNeVRlc3QuY3M=")]
internal static global::ISimpleInterface Create0(this Pretend<global::ISimpleInterface> pretend)
{
return new PretendISimpleInterface(pretend);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace System.Runtime.CompilerServices
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
file sealed class InterceptsLocationAttribute : Attribute
{
public InterceptsLocationAttribute(string filePath, int line, int column)
public InterceptsLocationAttribute(int version, string data)
{
}
}
Expand Down Expand Up @@ -52,7 +52,7 @@ public PretendIMyInterface(ICallHandler callHandler)

file static class SetupInterceptors
{
[InterceptsLocation(@"MyTest.cs", 21, 17)]
[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "uNYJO7f/XsEA3+a79KlSmqABAABNeVRlc3QuY3M=")]
internal static IPretendSetup<global::TaskOfTMethodNamespace.IMyInterface, global::System.Threading.Tasks.Task<string>> Setup0(this Pretend<global::TaskOfTMethodNamespace.IMyInterface> pretend, Func<global::TaskOfTMethodNamespace.IMyInterface, global::System.Threading.Tasks.Task<string>> setupExpression)
{
return pretend.GetOrCreateSetup<global::System.Threading.Tasks.Task<string>>(0, static (pretend, expr) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace System.Runtime.CompilerServices
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
file sealed class InterceptsLocationAttribute : Attribute
{
public InterceptsLocationAttribute(string filePath, int line, int column)
public InterceptsLocationAttribute(int version, string data)
{
}
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public string Bar

file static class SetupInterceptors
{
[InterceptsLocation(@"MyTest.cs", 13, 6)]
[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "00nUpp0g7RW7juGzPi8Bb/8AAABNeVRlc3QuY3M=")]
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) =>
Expand All @@ -133,7 +133,7 @@ file static class SetupInterceptors

file static class VerifyInterceptors
{
[InterceptsLocation(@"MyTest.cs", 18, 24)]
[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "00nUpp0g7RW7juGzPi8Bb3oBAABNeVRlc3QuY3M=")]
internal static void Verify0(this Pretend<global::ISimpleInterface> pretend, Func<global::ISimpleInterface, string?> setupExpression, Called called)
{
var setup = pretend.GetOrCreateSetup<string?>(0, static (pretend, expr) =>
Expand All @@ -160,7 +160,7 @@ internal static void Verify0(this Pretend<global::ISimpleInterface> pretend, Fun

file static class CreateInterceptors
{
[InterceptsLocation(@"MyTest.cs", 16, 38)]
[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "00nUpp0g7RW7juGzPi8Bb1YBAABNeVRlc3QuY3M=")]
internal static global::ISimpleInterface Create0(this Pretend<global::ISimpleInterface> pretend)
{
return new PretendISimpleInterface(pretend);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0-beta1.24318.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0-2.final" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0-2.final" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0-3.final" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0-3.final" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion test/SourceGeneratorTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public async Task RunAndCompareAsync(string source, [CallerMemberName] string te
private void CompareAgainstBaseline(GeneratedSourceResult result, string testMethodName)
{
var normalizedName = result.HintName[..^3].Replace('.', '_') + ".cs";
#if !GENERATE_SOURCE
#if GENERATE_SOURCE
var resultFileName = result.HintName.Replace('.', '_');
var baseLineName = $"{GetType().Name}.{testMethodName}.{normalizedName}";
var resourceName = Assert.Single(typeof(TestBase).Assembly.GetManifestResourceNames()
Expand Down

0 comments on commit 98a62ae

Please sign in to comment.