Skip to content

Commit

Permalink
Gate enum tests that depend on Ref.Emit
Browse files Browse the repository at this point in the history
In dotnet#49925 I blindly followed the existing pattern but the existing pattern was wrong because with that we get failing tests:

```
System.InvalidOperationException : No data found for System.Tests.EnumTests.IsDefined_UnsupportedEnumType_ThrowsInvalidOperationException
```
  • Loading branch information
MichalStrehovsky committed Mar 23, 2021
1 parent 010cbfe commit ffa7e8d
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/libraries/System.Runtime/tests/System/EnumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1979,23 +1979,20 @@ public static void Format_Invalid()

public static IEnumerable<object[]> UnsupportedEnumType_TestData()
{
if (PlatformDetection.IsReflectionEmitSupported)
{
yield return new object[] { s_floatEnumType, 1.0f };
yield return new object[] { s_doubleEnumType, 1.0 };
yield return new object[] { s_intPtrEnumType, (IntPtr)1 };
yield return new object[] { s_uintPtrEnumType, (UIntPtr)1 };
}
yield return new object[] { s_floatEnumType, 1.0f };
yield return new object[] { s_doubleEnumType, 1.0 };
yield return new object[] { s_intPtrEnumType, (IntPtr)1 };
yield return new object[] { s_uintPtrEnumType, (UIntPtr)1 };
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[MemberData(nameof(UnsupportedEnumType_TestData))]
public static void GetName_Unsupported_ThrowsArgumentException(Type enumType, object value)
{
AssertExtensions.Throws<ArgumentException>("value", () => Enum.GetName(enumType, value));
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[MemberData(nameof(UnsupportedEnumType_TestData))]
public static void IsDefined_UnsupportedEnumType_ThrowsInvalidOperationException(Type enumType, object value)
{
Expand All @@ -2006,16 +2003,13 @@ public static void IsDefined_UnsupportedEnumType_ThrowsInvalidOperationException

public static IEnumerable<object[]> UnsupportedEnum_TestData()
{
if (PlatformDetection.IsReflectionEmitSupported)
{
yield return new object[] { Enum.ToObject(s_floatEnumType, 1) };
yield return new object[] { Enum.ToObject(s_doubleEnumType, 2) };
yield return new object[] { Enum.ToObject(s_intPtrEnumType, 1) };
yield return new object[] { Enum.ToObject(s_uintPtrEnumType, 2) };
}
yield return new object[] { Enum.ToObject(s_floatEnumType, 1) };
yield return new object[] { Enum.ToObject(s_doubleEnumType, 2) };
yield return new object[] { Enum.ToObject(s_intPtrEnumType, 1) };
yield return new object[] { Enum.ToObject(s_uintPtrEnumType, 2) };
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[MemberData(nameof(UnsupportedEnum_TestData))]
public static void ToString_UnsupportedEnumType_ThrowsArgumentException(Enum e)
{
Expand All @@ -2024,7 +2018,7 @@ public static void ToString_UnsupportedEnumType_ThrowsArgumentException(Enum e)
Assert.True(formatXExceptionName == nameof(InvalidOperationException) || formatXExceptionName == "ContractException");
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[MemberData(nameof(UnsupportedEnumType_TestData))]
public static void Format_UnsupportedEnumType_ThrowsArgumentException(Type enumType, object value)
{
Expand Down

0 comments on commit ffa7e8d

Please sign in to comment.