Skip to content

Commit b4f8d4f

Browse files
authored
Harden some reflection invoke tests (#113000)
1 parent 1f6b690 commit b4f8d4f

File tree

9 files changed

+32
-112
lines changed

9 files changed

+32
-112
lines changed

src/libraries/Common/tests/System/Reflection/InvokeEmitTests.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/libraries/Common/tests/System/Reflection/InvokeInterpretedTests.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/libraries/System.Diagnostics.StackTrace/tests/StackFrameTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ public void Ctor_FNeedFileInfo(bool fNeedFileInfo)
3535
VerifyStackFrame(stackFrame, fNeedFileInfo, 0, typeof(StackFrameTests).GetMethod(nameof(Ctor_FNeedFileInfo)));
3636
}
3737

38-
[Theory]
39-
[ActiveIssue("https://github.com/mono/mono/issues/15183", TestRuntimes.Mono)]
40-
[InlineData(StackFrame.OFFSET_UNKNOWN)]
41-
[InlineData(0)]
42-
[InlineData(1)]
43-
public void Ctor_SkipFrames(int skipFrames)
44-
{
45-
var stackFrame = new StackFrame(skipFrames);
46-
VerifyStackFrame(stackFrame, true, skipFrames, typeof(StackFrameTests).GetMethod(nameof(Ctor_SkipFrames)), isCurrentFrame: skipFrames == 0);
47-
}
48-
4938
[Theory]
5039
[ActiveIssue("https://github.com/mono/mono/issues/15187", TestRuntimes.Mono)]
5140
[InlineData(StackFrame.OFFSET_UNKNOWN, true)]

src/libraries/System.Runtime/tests/System.Reflection.Tests/ConstructorCommonTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,22 @@ public void Invoke_Struct()
163163
Assert.Equal(1, obj.x);
164164
Assert.Equal(2, obj.y);
165165
}
166+
167+
[Fact]
168+
[ActiveIssue("https://github.com/dotnet/runtime/issues/50957", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoAOT))]
169+
public static void VerifyInnerException()
170+
{
171+
ConstructorInfo ctor = typeof(TestClassThatThrows).GetConstructor(Type.EmptyTypes)!;
172+
TargetInvocationException ex = Assert.Throws<TargetInvocationException>(() => ctor.Invoke(null));
173+
Assert.Contains("Here", ex.InnerException.ToString());
174+
}
175+
176+
private class TestClassThatThrows
177+
{
178+
public TestClassThatThrows()
179+
{
180+
throw new Exception("Here");
181+
}
182+
}
166183
}
167184
}

src/libraries/System.Runtime/tests/System.Reflection.Tests/InvokeEmit/System.Reflection.InvokeEmit.Tests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
44
<TestRuntime>true</TestRuntime>
@@ -14,7 +14,6 @@
1414
<Compile Include="..\MethodInfoTests.cs" />
1515
<Compile Include="..\MethodInvokerTests.cs" />
1616
<Compile Include="..\PropertyInfoTests.cs" />
17-
<Compile Include="$(CommonTestPath)\System\Reflection\InvokeEmitTests.cs" />
1817
</ItemGroup>
1918
<ItemGroup>
2019
<ProjectReference Include="..\TestAssembly\TestAssembly.csproj" />

src/libraries/System.Runtime/tests/System.Reflection.Tests/InvokeInterpreted/System.Reflection.InvokeInterpreted.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<Compile Include="..\MethodInfoTests.cs" />
1515
<Compile Include="..\MethodInvokerTests.cs" />
1616
<Compile Include="..\PropertyInfoTests.cs" />
17-
<Compile Include="$(CommonTestPath)\System\Reflection\InvokeInterpretedTests.cs" />
1817
</ItemGroup>
1918
<ItemGroup>
2019
<ProjectReference Include="..\TestAssembly\TestAssembly.csproj" />

src/libraries/System.Runtime/tests/System.Reflection.Tests/MethodCommonTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,5 +293,19 @@ public unsafe void TestFunctionPointerAsReturnType()
293293
Assert.IsType<IntPtr>(ret);
294294
Assert.True((IntPtr)ret != 0);
295295
}
296+
297+
[Fact]
298+
[ActiveIssue("https://github.com/dotnet/runtime/issues/50957", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoAOT))]
299+
public static void VerifyInnerException()
300+
{
301+
MethodInfo method = typeof(TestClassThatThrows).GetMethod(nameof(TestClassThatThrows.Throw))!;
302+
TargetInvocationException ex = Assert.Throws<TargetInvocationException>(() => method.Invoke(null, null));
303+
Assert.Contains("Here", ex.InnerException.ToString());
304+
}
305+
306+
private class TestClassThatThrows
307+
{
308+
public static void Throw() => throw new Exception("Here");
309+
}
296310
}
297311
}

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<Compile Include="..\InvokeRefReturn.cs" />
1111
<Compile Include="..\InvokeWithRefLikeArgs.cs" />
1212
<Compile Include="..\PointerTests.cs" />
13-
<Compile Include="$(CommonTestPath)\System\Reflection\InvokeEmitTests.cs" />
1413
</ItemGroup>
1514
<ItemGroup>
1615
<PackageReference Include="Moq" Version="$(MoqVersion)" />

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<Compile Include="..\InvokeRefReturn.cs" />
1111
<Compile Include="..\InvokeWithRefLikeArgs.cs" />
1212
<Compile Include="..\PointerTests.cs" />
13-
<Compile Include="$(CommonTestPath)\System\Reflection\InvokeInterpretedTests.cs" />
1413
</ItemGroup>
1514
<ItemGroup>
1615
<PackageReference Include="Moq" Version="$(MoqVersion)" />

0 commit comments

Comments
 (0)