Skip to content

Commit

Permalink
Write a better test for #33
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Jul 27, 2024
1 parent c19c251 commit f713475
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/InlineIL.Tests.Common/ReferencedAssemblyType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace InlineIL.Tests.Common;

public class TypeFromReferencedAssembly
{
public readonly StructFromReferencedAssembly FieldWithTypeFromThisAssembly = default;
}

public struct StructFromReferencedAssembly;
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
using Microsoft.Diagnostics.Tracing;
using System.Diagnostics.CodeAnalysis;
using InlineIL.Tests.Common;
using static InlineIL.IL.Emit;

namespace InlineIL.Tests.UnverifiableAssemblyToProcess;

[SuppressMessage("ReSharper", "UnusedType.Global")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "UnassignedField.Global")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public class FieldRefTestCases
{
public static nint ReadEventRecord(TraceEvent traceEvent)
public void ReadFieldFromReferencedAssemblyType()
{
// Repro of issue #33

IL.Push(traceEvent);
Ldfld(FieldRef.Field(typeof(TraceEvent), "eventRecord"));
return IL.Return<nint>();
IL.Push(new TypeFromReferencedAssembly());
Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly), nameof(TypeFromReferencedAssembly.FieldWithTypeFromThisAssembly)));
Pop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
<TargetFrameworks>netstandard2.0;net48</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.13" />
</ItemGroup>

<Import Project="../TestAssemblies.targets" />

</Project>
9 changes: 8 additions & 1 deletion src/InlineIL.Tests/Weaving/FieldRefTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ public void should_handle_field_references()
}

[Fact]
public void ShouldReferenceFieldInDifferentWays()
public void should_handle_fields_with_types_from_referenced_assemblies()
{
var instance = GetUnverifiableInstance();
instance.ReadFieldFromReferencedAssemblyType();
}

[Fact]
public void should_reference_field_in_different_ways()
{
var result = (int[])GetInstance().ReturnStaticIntFieldInDifferentWays();
result.ShouldAll(i => i == result[0]);
Expand Down

0 comments on commit f713475

Please sign in to comment.