Skip to content

Commit

Permalink
Cleanup NETCOREAPP ifdef usage in System.Runtime.Tests (#22224)
Browse files Browse the repository at this point in the history
Fixes #21827
  • Loading branch information
jkotas authored Feb 1, 2020
1 parent 4f97bc7 commit 483d042
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 456 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,33 @@ public static bool IsDrawingSupported
get
{
#if NETCOREAPP
if (IsWindows)
if (!IsWindows)
{
#endif
return IsNotWindowsNanoServer && IsNotWindowsServerCore;
#if NETCOREAPP
}
else if (IsOSX)
{
return NativeLibrary.TryLoad("libgdiplus.dylib", out _);
}
else
{
return NativeLibrary.TryLoad("libgdiplus.so", out _) || NativeLibrary.TryLoad("libgdiplus.so.0", out _);
if (IsOSX)
{
return NativeLibrary.TryLoad("libgdiplus.dylib", out _);
}
else
{
return NativeLibrary.TryLoad("libgdiplus.so", out _) || NativeLibrary.TryLoad("libgdiplus.so.0", out _);
}
}
#endif

return IsNotWindowsNanoServer && IsNotWindowsServerCore;

}
}

public static bool IsInContainer => GetIsInContainer();
public static bool SupportsSsl3 => GetSsl3Support();

#if NETCOREAPP
public static bool IsReflectionEmitSupported = RuntimeFeature.IsDynamicCodeSupported;
#else
public static bool IsReflectionEmitSupported = true;
#endif

public static bool IsInvokingStaticConstructorsSupported => true;

// System.Security.Cryptography.Xml.XmlDsigXsltTransform.GetOutput() relies on XslCompiledTransform which relies
Expand Down
12 changes: 2 additions & 10 deletions src/libraries/System.Runtime/tests/System/ActivatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public static void CreateInstance_MultipleMatchingConstructors_ThrowsAmbiguousMa
Assert.Throws<AmbiguousMatchException>(() => Activator.CreateInstance(typeof(Choice1), new object[] { null }));
}

#if NETCOREAPP
[Fact]
public void CreateInstance_NotRuntimeType_ThrowsArgumentException()
{
Expand All @@ -135,7 +134,6 @@ public void CreateInstance_NotRuntimeType_ThrowsArgumentException()
AssertExtensions.Throws<ArgumentException>("type", () => Activator.CreateInstance(nonRuntimeType, new object[0]));
}
}
#endif

public static IEnumerable<object[]> CreateInstance_ContainsGenericParameters_TestData()
{
Expand All @@ -155,13 +153,7 @@ public static IEnumerable<object[]> CreateInstance_InvalidType_TestData()
{
yield return new object[] { typeof(void) };
yield return new object[] { typeof(void).MakeArrayType() };
yield return new object[] { Type.GetType("System.ArgIterator") };
// Fails with TypeLoadException in .NET Core as array types of ref structs
// are not supported.
if (!PlatformDetection.IsNetCore)
{
yield return new object[] { Type.GetType("System.ArgIterator").MakeArrayType() };
}
yield return new object[] { typeof(ArgIterator) };
}

[Theory]
Expand Down Expand Up @@ -262,11 +254,11 @@ public void CreateInstance_ConstructorThrowsFromCache_ThrowsTargetInvocationExce
}

[Theory]
[SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp, "Activation Attributes are not supported in .NET Core.")]
[InlineData(typeof(MarshalByRefObject))]
[InlineData(typeof(SubMarshalByRefObject))]
public void CreateInstance_MarshalByRefObjectNetCore_ThrowsPlatformNotSupportedException(Type type)
{
// Activation Attributes are not supported in .NET Core.
Assert.Throws<PlatformNotSupportedException>(() => Activator.CreateInstance(type, null, new object[] { 1 } ));
Assert.Throws<PlatformNotSupportedException>(() => Activator.CreateInstance(type, null, new object[] { 1, 2 } ));
}
Expand Down
713 changes: 374 additions & 339 deletions src/libraries/System.Runtime/tests/System/EnumTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ public static void Exception_SerializeObjectState()
}

[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public static void Exception_OverriddenToStringOnInnerException()
{
var inner = new DerivedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace System.Tests
{
public class RealFormatterTests : RealFormatterTestsBase
{
// The actual tests are defined in: src\Common\tests\System\RealFormatterTestsBase.netcoreapp.cs
// The actual tests are defined in: src\Common\tests\System\RealFormatterTestsBase.cs

protected override string InvariantToStringDouble(double d, string format)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace System.Tests
{
public class RealParserTests : RealParserTestsBase
{
// The actual tests are defined in: src\Common\tests\System\RealParserTestsBase.netcoreapp.cs
// The actual tests are defined in: src\Common\tests\System\RealParserTestsBase.cs

protected override string InvariantToStringDouble(double d)
{
Expand Down
100 changes: 9 additions & 91 deletions src/libraries/System.Runtime/tests/System/Type/TypePropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,6 @@ public abstract class ArrayTypeTestBase : TypePropertyTestBase

public override bool HasElementType => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;

public override bool IsTypeDefinition => false;
}

Expand Down Expand Up @@ -390,10 +386,6 @@ public abstract class PrimitiveTypeTestBase : StructTypeTestBase
public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.SequentialLayout | TypeAttributes.Sealed | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;

public override bool IsPrimitive => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
}

public abstract class EnumTypeTestBase : StructTypeTestBase
Expand Down Expand Up @@ -521,21 +513,13 @@ public class ObjectTests : ClassTypeTestBase
public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;

public override Type BaseType => null;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
}

public class ValueTypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(ValueType);

public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
}

public class EnumTypeTests : ClassTypeTestBase
Expand All @@ -545,22 +529,11 @@ public class EnumTypeTests : ClassTypeTestBase
public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;

public override Type BaseType => typeof(ValueType);

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
}

public class VoidTests : StructTypeTestBase
{
public override Type CreateType() => typeof(void);

public override TypeAttributes Attributes =>
PlatformDetection.IsNetCore ? base.Attributes : base.Attributes | TypeAttributes.Serializable;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
}

public class IntRefTests : TypePropertyTestBase
Expand All @@ -573,10 +546,6 @@ public class IntRefTests : TypePropertyTestBase

public override bool IsByRef => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;

public override bool IsTypeDefinition => false;

public override bool HasElementType => true;
Expand All @@ -599,10 +568,6 @@ public class IntPointerTests : TypePropertyTestBase
public override bool HasElementType => true;

public override Type ElementType => typeof(int);

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
}

public class IntArrayTests : ArrayTypeTestBase
Expand Down Expand Up @@ -655,10 +620,6 @@ public class ArrayTypeTests : ClassTypeTestBase
public override Type CreateType() => typeof(Array);

public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
}

public class NonGenericClassTests : ClassTypeTestBase
Expand All @@ -676,10 +637,6 @@ public class NonGenericSubClassOfNonGenericTests : ClassTypeTestBase
public class TypedReferenceTypeTests : StructTypeTestBase
{
public override Type CreateType() => typeof(TypedReference);

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
}

public class GenericClass1Tests : ClassTypeTestBase
Expand Down Expand Up @@ -859,10 +816,6 @@ public class GenericTypeParameter1Of1Tests : TypePropertyTestBase

public override bool IsGenericParameter => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;

public override bool IsTypeDefinition => false;

public override int? GenericParameterPosition => 0;
Expand All @@ -882,10 +835,6 @@ public class GenericTypeParameter1Of2Tests : TypePropertyTestBase

public override bool IsGenericParameter => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;

public override bool IsTypeDefinition => false;

public override int? GenericParameterPosition => 0;
Expand All @@ -905,10 +854,6 @@ public class GenericTypeParameter2Of2Tests : TypePropertyTestBase

public override bool IsGenericParameter => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;

public override bool IsTypeDefinition => false;

public override int? GenericParameterPosition => 1;
Expand All @@ -928,10 +873,6 @@ public class NestedGenericTypeParameter1Tests : TypePropertyTestBase

public override bool IsGenericParameter => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;

public override bool IsTypeDefinition => false;

public override int? GenericParameterPosition => 0;
Expand All @@ -951,10 +892,6 @@ public class NestedGenericTypeParameter2Tests : TypePropertyTestBase

public override bool IsGenericParameter => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;

public override bool IsTypeDefinition => false;

public override int? GenericParameterPosition => 1;
Expand All @@ -976,10 +913,6 @@ public class GenericMethodParameter1Of2Tests : TypePropertyTestBase

public override bool IsGenericParameter => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;

public override bool IsTypeDefinition => false;

public override int? GenericParameterPosition => 0;
Expand All @@ -1001,47 +934,32 @@ public class GenericMethodParameter2Of2Tests : TypePropertyTestBase

public override bool IsGenericParameter => true;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;

public override bool IsTypeDefinition => false;

public override int? GenericParameterPosition => 1;
}

public class MarshalByRefObjectTests : TypePropertyTestBase
public class MarshalByRefObjectTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(MarshalByRefObject);

public override TypeAttributes Attributes => PlatformDetection.IsNetCore
? TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit
: TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;
public override TypeAttributes Attributes => base.Attributes | TypeAttributes.Abstract;

public override bool IsMarshalByRef => !PlatformDetection.IsNetCore;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
// Remoting is not supported in .NET Core
public override bool IsMarshalByRef => false;
}

public class ContextBoundObjectTests : TypePropertyTestBase
public class ContextBoundObjectTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(ContextBoundObject);

public override TypeAttributes Attributes => PlatformDetection.IsNetCore
? TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit
: TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;
public override TypeAttributes Attributes => base.Attributes | TypeAttributes.Abstract;

public override Type BaseType => typeof(MarshalByRefObject);

public override bool IsMarshalByRef => !PlatformDetection.IsNetCore;

public override bool IsContextful => !PlatformDetection.IsNetCore;

public override bool IsSecurityCritical => PlatformDetection.IsNetCore;

public override bool IsSecurityTransparent => !PlatformDetection.IsNetCore;
// Remoting is not supported in .NET Core
public override bool IsMarshalByRef => false;
public override bool IsContextful => false;
}

public enum ByteEnum : byte { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public static void MakeTypedReference_ToObjectTests()
Assert.Equal(structObj, TypedReference.ToObject(reference));
}

[SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp, "https://github.com/dotnet/coreclr/pull/21193")]
[Fact]
public static void MakeTypedReference_ReadOnlyField_Succeeds()
{
Expand Down

0 comments on commit 483d042

Please sign in to comment.