-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify tests to distinguish between emit- and interpreted-based invoke
- Loading branch information
1 parent
2fbc50f
commit dc31c58
Showing
16 changed files
with
308 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/libraries/Common/tests/System/Reflection/InvokeEmitTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Xunit; | ||
|
||
namespace System.Reflection.Tests | ||
{ | ||
public class InvokeEmitTests | ||
{ | ||
[Fact] | ||
public static void VerifyInvokeIsUsingEmit_Method() | ||
{ | ||
MethodInfo method = typeof(TestClassThatThrows).GetMethod(nameof(TestClassThatThrows.Throw))!; | ||
TargetInvocationException ex = Assert.Throws<TargetInvocationException>(() => method.Invoke(null, null)); | ||
Exception exInner = ex.InnerException; | ||
|
||
Assert.Contains("Here", exInner.ToString()); | ||
Assert.Contains("InvokeStub_TestClassThatThrows", exInner.ToString()); | ||
Assert.DoesNotContain("System.RuntimeMethodHandle.InvokeMethod", exInner.ToString()); | ||
} | ||
|
||
[Fact] | ||
public static void VerifyInvokeIsUsingEmit_Constructor() | ||
{ | ||
ConstructorInfo ctor = typeof(TestClassThatThrows).GetConstructor(Type.EmptyTypes)!; | ||
TargetInvocationException ex = Assert.Throws<TargetInvocationException>(() => ctor.Invoke(null)); | ||
Exception exInner = ex.InnerException; | ||
|
||
Assert.Contains("Here", exInner.ToString()); | ||
Assert.Contains("InvokeStub_TestClassThatThrows", exInner.ToString()); | ||
Assert.DoesNotContain("System.RuntimeMethodHandle.InvokeMethod", exInner.ToString()); | ||
} | ||
|
||
private class TestClassThatThrows | ||
{ | ||
public TestClassThatThrows() | ||
{ | ||
throw new Exception("Here"); | ||
} | ||
|
||
public static void Throw() => throw new Exception("Here"); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/libraries/Common/tests/System/Reflection/InvokeInterpretedTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Xunit; | ||
|
||
namespace System.Reflection.Tests | ||
{ | ||
public class InvokeInterpretedTests | ||
{ | ||
[Fact] | ||
public static void VerifyInvokeIsUsingEmit_Method() | ||
{ | ||
MethodInfo method = typeof(TestClassThatThrows).GetMethod(nameof(TestClassThatThrows.Throw))!; | ||
TargetInvocationException ex = Assert.Throws<TargetInvocationException>(() => method.Invoke(null, null)); | ||
Exception exInner = ex.InnerException; | ||
|
||
Assert.Contains("Here", exInner.ToString()); | ||
Assert.Contains("System.RuntimeMethodHandle.InvokeMethod", exInner.ToString()); | ||
Assert.DoesNotContain("InvokeStub_TestClassThatThrows", exInner.ToString()); | ||
} | ||
|
||
[Fact] | ||
public static void VerifyInvokeIsUsingEmit_Constructor() | ||
{ | ||
ConstructorInfo ctor = typeof(TestClassThatThrows).GetConstructor(Type.EmptyTypes)!; | ||
TargetInvocationException ex = Assert.Throws<TargetInvocationException>(() => ctor.Invoke(null)); | ||
Exception exInner = ex.InnerException; | ||
|
||
Assert.Contains("Here", exInner.ToString()); | ||
Assert.Contains("System.RuntimeMethodHandle.InvokeMethod", exInner.ToString()); | ||
Assert.DoesNotContain("InvokeStub_TestClassThatThrows", exInner.ToString()); | ||
} | ||
|
||
private class TestClassThatThrows | ||
{ | ||
public TestClassThatThrows() | ||
{ | ||
throw new Exception("Here"); | ||
} | ||
|
||
public static void Throw() => throw new Exception("Here"); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/libraries/System.Reflection/tests/InvokeEmit/System.Reflection.InvokeEmit.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<TestRuntime>true</TestRuntime> | ||
<IncludeRemoteExecutor>true</IncludeRemoteExecutor> | ||
<TargetFrameworks>$(NetCoreAppCurrent)-windows</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="..\Common.cs" /> | ||
<Compile Include="..\ConstructorInfoTests.cs" /> | ||
<Compile Include="..\MethodInfoTests.cs" /> | ||
<Compile Include="..\PropertyInfoTests.cs" /> | ||
<Compile Include="$(CommonTestPath)\System\Reflection\InvokeEmitTests.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\TestAssembly\TestAssembly.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<!-- Assemblies that should be excluded from the bundle --> | ||
<__ExcludeFromBundle Include="TestAssembly.dll" /> | ||
</ItemGroup> | ||
</Project> |
5 changes: 5 additions & 0 deletions
5
src/libraries/System.Reflection/tests/InvokeEmit/runtimeconfig.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"configProperties": { | ||
"Switches.System.Reflection.ForceEmitInvoke": true | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ystem.Reflection/tests/InvokeInterpreted/System.Reflection.InvokeInterpreted.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<TestRuntime>true</TestRuntime> | ||
<IncludeRemoteExecutor>true</IncludeRemoteExecutor> | ||
<TargetFrameworks>$(NetCoreAppCurrent)-windows</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="..\Common.cs" /> | ||
<Compile Include="..\ConstructorInfoTests.cs" /> | ||
<Compile Include="..\MethodInfoTests.cs" /> | ||
<Compile Include="..\PropertyInfoTests.cs" /> | ||
<Compile Include="$(CommonTestPath)\System\Reflection\InvokeInterpretedTests.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\TestAssembly\TestAssembly.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<!-- Assemblies that should be excluded from the bundle --> | ||
<__ExcludeFromBundle Include="TestAssembly.dll" /> | ||
</ItemGroup> | ||
</Project> |
5 changes: 5 additions & 0 deletions
5
src/libraries/System.Reflection/tests/InvokeInterpreted/runtimeconfig.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"configProperties": { | ||
"Switches.System.Reflection.ForceInterpretedInvoke": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ntime/tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<TestRuntime>true</TestRuntime> | ||
<IncludeRemoteExecutor>true</IncludeRemoteExecutor> | ||
<TargetFrameworks>$(NetCoreAppCurrent)-windows</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="..\BindingFlagsDoNotWrap.cs" /> | ||
<Compile Include="..\InvokeRefReturn.cs" /> | ||
<Compile Include="..\InvokeWithRefLikeArgs.cs" /> | ||
<Compile Include="..\PointerTests.cs" /> | ||
<Compile Include="$(CommonTestPath)\System\Reflection\InvokeEmitTests.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Moq" Version="$(MoqVersion)" /> | ||
</ItemGroup> | ||
</Project> |
5 changes: 5 additions & 0 deletions
5
src/libraries/System.Runtime/tests/System/Reflection/InvokeEmit/runtimeconfig.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"configProperties": { | ||
"Switches.System.Reflection.ForceEmitInvoke": true | ||
} | ||
} |
Oops, something went wrong.