Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more libraries tests #73104

Merged
merged 6 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<IlcArg Condition="$(ExportsFile) != ''" Include="--exportsfile:$(ExportsFile)" />
<IlcArg Include="@(AutoInitializedAssemblies->'--initassembly:%(Identity)')" />
<IlcArg Include="@(RuntimeHostConfigurationOption->'--appcontextswitch:%(Identity)=%(Value)')" />
<IlcArg Include="--appcontextswitch:RUNTIME_IDENTIFIER=$(RuntimeIdentifier)" />
<IlcArg Include="@(DirectPInvoke->'--directpinvoke:%(Identity)')" />
<IlcArg Include="@(DirectPInvokeList->'--directpinvokelist:%(Identity)')" />
<IlcArg Include="@(_TrimmerFeatureSettings->'--feature:%(Identity)=%(Value)')" />
Expand Down
29 changes: 17 additions & 12 deletions src/libraries/System.Console/tests/TermInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -10,6 +11,8 @@
[SkipOnPlatform(TestPlatforms.Android | TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Not supported on Android, Browser, iOS, MacCatalyst, or tvOS.")]
public class TermInfo
{
private const string SystemConsoleFullNameSuffix = ", System.Console";

// Names of internal members accessed via reflection
private const string TerminfoType = "System.TermInfo";
private const string TerminfoDatabaseType = TerminfoType + "+Database";
Expand All @@ -25,12 +28,13 @@ public class TermInfo
private const string TerminfoLocationsField = "_terminfoLocations";

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/72833", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
[PlatformSpecific(TestPlatforms.AnyUnix)] // Tests TermInfo
public void VerifyInstalledTermInfosParse()
{
bool foundAtLeastOne = false;

string[] locations = GetFieldValueOnObject<string[]>(TerminfoLocationsField, null, typeof(Console).GetTypeInfo().Assembly.GetType(TerminfoDatabaseType));
string[] locations = GetFieldValueOnObject<string[]>(TerminfoLocationsField, null, Type.GetType(TerminfoDatabaseType + SystemConsoleFullNameSuffix));
foreach (string location in locations)
{
if (!Directory.Exists(location))
Expand Down Expand Up @@ -62,12 +66,13 @@ public void VerifyInstalledTermInfosParse()
[PlatformSpecific(TestPlatforms.AnyUnix)] // Tests TermInfo
public void VerifyTermInfoSupportsNewAndLegacyNcurses()
{
MethodInfo readDbMethod = typeof(Console).GetTypeInfo().Assembly.GetType(TerminfoDatabaseType).GetTypeInfo().GetDeclaredMethods(ReadDatabaseMethod).Where(m => m.GetParameters().Count() == 2).Single();
MethodInfo readDbMethod = Type.GetType(TerminfoDatabaseType + SystemConsoleFullNameSuffix).GetTypeInfo().GetDeclaredMethods(ReadDatabaseMethod).Where(m => m.GetParameters().Count() == 2).Single();
readDbMethod.Invoke(null, new object[] { "xterm", "ncursesFormats" }); // This will throw InvalidOperationException in case we don't support the legacy format
readDbMethod.Invoke(null, new object[] { "screen-256color", "ncursesFormats" }); // This will throw InvalidOperationException if we can't parse the new format
}

[Theory]
[ActiveIssue("https://github.com/dotnet/runtime/issues/72833", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
[PlatformSpecific(TestPlatforms.AnyUnix)] // Tests TermInfo
[InlineData("xterm-256color", "\u001B\u005B\u00330m", "\u001B\u005B\u00340m", 0)]
[InlineData("xterm-256color", "\u001B\u005B\u00331m", "\u001B\u005B\u00341m", 1)]
Expand Down Expand Up @@ -121,37 +126,37 @@ public void TryingToLoadTermThatDoesNotExistDoesNotThrow()

private object ReadTermInfoDatabase(string term)
{
MethodInfo readDbMethod = typeof(Console).GetTypeInfo().Assembly.GetType(TerminfoDatabaseType).GetTypeInfo().GetDeclaredMethods(ReadDatabaseMethod).Where(m => m.GetParameters().Count() == 1).Single();
MethodInfo readDbMethod = Type.GetType(TerminfoDatabaseType + SystemConsoleFullNameSuffix).GetTypeInfo().GetDeclaredMethods(ReadDatabaseMethod).Where(m => m.GetParameters().Count() == 1).Single();
return readDbMethod.Invoke(null, new object[] { term });
}

private object CreateTermColorInfo(object db)
{
return typeof(Console).GetTypeInfo().Assembly.GetType(TerminalFormatStringsType).GetTypeInfo().DeclaredConstructors
return Type.GetType(TerminalFormatStringsType + SystemConsoleFullNameSuffix).GetTypeInfo().DeclaredConstructors
.Where(c => c.GetParameters().Count() == 1).Single().Invoke(new object[] { db });
}

private string GetForegroundFormat(object colorInfo)
{
return GetFieldValueOnObject<string>(ForegroundFormatField, colorInfo, typeof(Console).GetTypeInfo().Assembly.GetType(TerminalFormatStringsType));
return GetFieldValueOnObject<string>(ForegroundFormatField, colorInfo, Type.GetType(TerminalFormatStringsType + SystemConsoleFullNameSuffix));
}

private string GetBackgroundFormat(object colorInfo)
{
return GetFieldValueOnObject<string>(BackgroundFormatField, colorInfo, typeof(Console).GetTypeInfo().Assembly.GetType(TerminalFormatStringsType));
return GetFieldValueOnObject<string>(BackgroundFormatField, colorInfo, Type.GetType(TerminalFormatStringsType + SystemConsoleFullNameSuffix));
}

private int GetMaxColors(object colorInfo)
{
return GetFieldValueOnObject<int>(MaxColorsField, colorInfo, typeof(Console).GetTypeInfo().Assembly.GetType(TerminalFormatStringsType));
return GetFieldValueOnObject<int>(MaxColorsField, colorInfo, Type.GetType(TerminalFormatStringsType + SystemConsoleFullNameSuffix));
}

private string GetResetFormat(object colorInfo)
{
return GetFieldValueOnObject<string>(ResetFormatField, colorInfo, typeof(Console).GetTypeInfo().Assembly.GetType(TerminalFormatStringsType));
return GetFieldValueOnObject<string>(ResetFormatField, colorInfo, Type.GetType(TerminalFormatStringsType + SystemConsoleFullNameSuffix));
}

private T GetFieldValueOnObject<T>(string name, object instance, Type baseType)
private T GetFieldValueOnObject<T>(string name, object instance, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] Type baseType)
{
return (T)baseType.GetTypeInfo().GetDeclaredField(name).GetValue(instance);
}
Expand All @@ -160,7 +165,7 @@ private object CreateFormatParam(object o)
{
Assert.True((o.GetType() == typeof(int)) || (o.GetType() == typeof(string)));

TypeInfo ti = typeof(Console).GetTypeInfo().Assembly.GetType(FormatParamType).GetTypeInfo();
TypeInfo ti = Type.GetType(FormatParamType + SystemConsoleFullNameSuffix).GetTypeInfo();
ConstructorInfo ci = null;

foreach (ConstructorInfo c in ti.DeclaredConstructors)
Expand All @@ -184,8 +189,8 @@ private object CreateFormatParam(object o)

private string EvaluateParameterizedStrings(string format, params object[] parameters)
{
Type formatArrayType = typeof(Console).GetTypeInfo().Assembly.GetType(FormatParamType).MakeArrayType();
MethodInfo mi = typeof(Console).GetTypeInfo().Assembly.GetType(ParameterizedStringsType).GetTypeInfo()
Type formatArrayType = Type.GetType(FormatParamType + SystemConsoleFullNameSuffix).MakeArrayType();
MethodInfo mi = Type.GetType(ParameterizedStringsType + SystemConsoleFullNameSuffix).GetTypeInfo()
.GetDeclaredMethods(EvaluateMethod).First(m => m.GetParameters()[1].ParameterType.IsArray);

// Create individual FormatParams
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Numerics.Tensors/tests/TensorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void ConstructFromDimensions(TensorConstructor tensorConstructor)
Assert.Equal(3, tensor.Dimensions[2]);
}

[Theory()]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNonZeroLowerBoundArraySupported))]
[MemberData(nameof(GetSingleTensorConstructors))]
public void ConstructTensorFromArrayRank3WithLowerBounds(TensorConstructor tensorConstructor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void RelativeSearchPath_Is_Null()
Assert.Null(AppDomain.CurrentDomain.RelativeSearchPath);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.HasHostExecutable))]
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.Android | TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "The dotnet sdk will not be available on these platforms")]
public void TargetFrameworkTest()
{
Expand Down Expand Up @@ -258,7 +258,7 @@ public void ExecuteAssemblyByName()
}).Dispose();
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void ExecuteAssembly()
{
CopyTestAssemblies();
Expand Down Expand Up @@ -361,7 +361,7 @@ public void Load()
Assert.NotNull(AppDomain.CurrentDomain.Load(typeof(AppDomainTests).Assembly.FullName));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
[SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser.")]
public void LoadBytes()
{
Expand Down Expand Up @@ -651,7 +651,7 @@ public CorrectlyPropagatesException(string message) : base(message)
{ }
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/43909", TestRuntimes.Mono)]
[InlineData(true)]
[InlineData(false)]
Expand Down Expand Up @@ -811,7 +811,9 @@ public static void GetPermissionSet()
#pragma warning restore SYSLIB0003 // Obsolete: CAS
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.FileCreateCaseSensitive))]
public static bool FileCreateCaseSensitiveAndAssemblyLoadingSupported => PlatformDetection.FileCreateCaseSensitive && PlatformDetection.IsAssemblyLoadingSupported;

[ConditionalTheory(nameof(FileCreateCaseSensitiveAndAssemblyLoadingSupported))]
[MemberData(nameof(TestingCreateInstanceFromObjectHandleData))]
public static void TestingCreateInstanceFromObjectHandle(string physicalFileName, string assemblyFile, string type, string returnedFullNameType, Type exceptionType)
{
Expand Down Expand Up @@ -872,7 +874,7 @@ public static IEnumerable<object[]> TestingCreateInstanceFromObjectHandleData()
yield return new object[] { "AssemblyResolveTestApp.dll", "assemblyresolvetestapp.dll", "assemblyresolvetestapp.publicclassnodefaultconstructorsample", "AssemblyResolveTestApp.PublicClassNoDefaultConstructorSample", exceptionType };
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
[MemberData(nameof(TestingCreateInstanceObjectHandleData))]
public static void TestingCreateInstanceObjectHandle(string assemblyName, string type, string returnedFullNameType, Type exceptionType)
{
Expand Down Expand Up @@ -921,7 +923,7 @@ public static void TestingCreateInstanceObjectHandle(string assemblyName, string
{ "assemblyresolvetestapp", "assemblyresolvetestapp.publicclassnodefaultconstructorsample", "AssemblyResolveTestApp.PublicClassNoDefaultConstructorSample", typeof(TypeLoadException) }
};

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
[MemberData(nameof(TestingCreateInstanceFromObjectHandleFullSignatureData))]
public static void TestingCreateInstanceFromObjectHandleFullSignature(string physicalFileName, string assemblyFile, string type, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, string returnedFullNameType)
{
Expand Down Expand Up @@ -951,7 +953,7 @@ public static IEnumerable<object[]> TestingCreateInstanceFromObjectHandleFullSig
}
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
[MemberData(nameof(TestingCreateInstanceObjectHandleFullSignatureData))]
public static void TestingCreateInstanceObjectHandleFullSignature(string assemblyName, string type, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, string returnedFullNameType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static void StartNewAndRestart()
}
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDebuggerTypeProxyAttributeSupported))]
public static void DebuggerAttributesValid()
{
Stopwatch watch = new Stopwatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void ProcessorCount_Windows_MatchesGetSystemInfo()
public static int GetProcessorCount() => Environment.ProcessorCount;

[PlatformSpecific(TestPlatforms.Windows)]
[Theory]
[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/52910", TestRuntimes.Mono)]
[InlineData(8000, 0, null)]
[InlineData(8000, 2000, null)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class EnvironmentStackTrace
static string s_stackTrace;

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/73051", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
[ActiveIssue("https://github.com/mono/mono/issues/15315", TestRuntimes.Mono)]
public void StackTraceTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ public static void GetAssemblyName_AssemblyNameProxy()
AssertExtensions.Throws<ArgumentException>("path", null, () => anp.GetAssemblyName(string.Empty));
Assert.Throws<FileNotFoundException>(() => anp.GetAssemblyName(Guid.NewGuid().ToString("N")));

Assembly a = typeof(AssemblyNameProxyTests).Assembly;
Assert.Equal(new AssemblyName(a.FullName).ToString(), anp.GetAssemblyName(Path.GetFullPath(a.Location)).ToString());
if (PlatformDetection.HasAssemblyFiles)
{
Assembly a = typeof(AssemblyNameProxyTests).Assembly;
Assert.Equal(new AssemblyName(a.FullName).ToString(), anp.GetAssemblyName(Path.GetFullPath(a.Location)).ToString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public void DumpRuntimeInformationToConsole()
Console.WriteLine($"### FRAMEWORK: Version={Environment.Version} Description={RuntimeInformation.FrameworkDescription.Trim()}");

string binariesLocation = Path.GetDirectoryName(typeof(object).Assembly.Location);
string binariesLocationFormat = PlatformDetection.IsInAppContainer ? "Unknown" : new DriveInfo(binariesLocation).DriveFormat;
string binariesLocationFormat = string.IsNullOrEmpty(binariesLocation) ? "Unknown" : new DriveInfo(binariesLocation).DriveFormat;
Console.WriteLine($"### BINARIES: {binariesLocation} (drive format {binariesLocationFormat})");

string tempPathLocation = Path.GetTempPath();
string tempPathLocationFormat = PlatformDetection.IsInAppContainer ? "Unknown" : new DriveInfo(tempPathLocation).DriveFormat;
string tempPathLocationFormat = string.IsNullOrEmpty(binariesLocation) ? "Unknown" : new DriveInfo(tempPathLocation).DriveFormat;
Console.WriteLine($"### TEMP PATH: {tempPathLocation} (drive format {tempPathLocationFormat})");

Console.WriteLine($"### CURRENT DIRECTORY: {Environment.CurrentDirectory}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public void VerifyLinuxRid()
.Substring("ID=".Length)
.Trim('\"', '\'');

// This gets burned in at publish time on NativeAOT
if (PlatformDetection.IsNativeAot)
expectedOSName = "linux";

Assert.StartsWith(expectedOSName, RuntimeInformation.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase);
}

Expand Down
Loading