Skip to content
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
9 changes: 6 additions & 3 deletions src/libraries/System.Reflection/tests/AssemblyNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,11 @@ public static void GetAssemblyName()
Assert.Throws<System.BadImageFormatException>(() => AssemblyName.GetAssemblyName(tempFile.Path));
}

Assembly a = typeof(AssemblyNameTests).Assembly;
Assert.Equal(new AssemblyName(a.FullName).ToString(), AssemblyName.GetAssemblyName(AssemblyPathHelper.GetAssemblyLocation(a)).ToString());
if (!PlatformDetection.IsNativeAot)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generally incompatible with single-file. Would it be better to skip the test when AssemblyPathHelper.GetAssemblyLocation returns empty path?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #68980 to track this

{
Assembly a = typeof(AssemblyNameTests).Assembly;
Assert.Equal(new AssemblyName(a.FullName).ToString(), AssemblyName.GetAssemblyName(AssemblyPathHelper.GetAssemblyLocation(a)).ToString());
}
}

[Fact]
Expand Down Expand Up @@ -371,7 +374,7 @@ public void FullName_CurrentlyExecutingAssembly()
Assert.Equal(assemblyName.Name.Length, assemblyName.FullName.IndexOf(','));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void EmptyFusionLog()
{
FileNotFoundException fnfe = Assert.Throws<FileNotFoundException>(() => Assembly.LoadFrom(@"\non\existent\file.dll"));
Expand Down
86 changes: 55 additions & 31 deletions src/libraries/System.Reflection/tests/AssemblyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ public class AssemblyTests : FileCleanupTestBase

public AssemblyTests()
{
// Assembly.Location does not return the file path for single-file deployment targets.
DestTestAssemblyPath = Path.Combine(base.TestDirectory, s_sourceTestAssemblyName);
LoadFromTestPath = Path.Combine(base.TestDirectory, "System.Reflection.Tests.dll");
File.Copy(SourceTestAssemblyPath, DestTestAssemblyPath);
string currAssemblyPath = Path.Combine(Environment.CurrentDirectory, "System.Reflection.Tests.dll");
File.Copy(currAssemblyPath, LoadFromTestPath, true);
if (PlatformDetection.IsAssemblyLoadingSupported)
{
// Assembly.Location does not return the file path for single-file deployment targets.
DestTestAssemblyPath = Path.Combine(base.TestDirectory, s_sourceTestAssemblyName);
LoadFromTestPath = Path.Combine(base.TestDirectory, "System.Reflection.Tests.dll");
File.Copy(SourceTestAssemblyPath, DestTestAssemblyPath);
string currAssemblyPath = Path.Combine(Environment.CurrentDirectory, "System.Reflection.Tests.dll");
File.Copy(currAssemblyPath, LoadFromTestPath, true);
}
}

[Theory]
Expand Down Expand Up @@ -150,7 +153,11 @@ public void GetEntryAssembly()
{
Assert.NotNull(Assembly.GetEntryAssembly());
string assembly = Assembly.GetEntryAssembly().ToString();
bool correct = assembly.IndexOf("xunit.console", StringComparison.OrdinalIgnoreCase) != -1;

// The single file test runner is not xunit.console
string expectedAssembly = PlatformDetection.IsNativeAot ? "System.Reflection.Tests" : "xunit.console";

bool correct = assembly.IndexOf(expectedAssembly, StringComparison.OrdinalIgnoreCase) != -1;
Assert.True(correct, $"Unexpected assembly name {assembly}");
}

Expand All @@ -174,7 +181,7 @@ public void GetFile()
}
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void GetFile_InMemory()
{
var inMemBlob = File.ReadAllBytes(SourceTestAssemblyPath);
Expand All @@ -186,7 +193,7 @@ public void GetFile_InMemory()
Assert.Throws<FileNotFoundException>(() => asm.GetFiles(getResourceModules: false));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void CodeBaseInMemory()
{
var inMemBlob = File.ReadAllBytes(SourceTestAssemblyPath);
Expand Down Expand Up @@ -337,7 +344,7 @@ public void Load_Invalid()
Assert.Throws<FileNotFoundException>(() => Assembly.Load(new AssemblyName("no such assembly"))); // No such assembly
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFile()
{
Assembly currentAssembly = typeof(AssemblyTests).Assembly;
Expand All @@ -361,20 +368,20 @@ public void LoadFile()
Assert.Equal(loadedAssembly1, loadedAssembly2);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFile_NullPath_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("path", () => Assembly.LoadFile(null));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFile_NoSuchPath_ThrowsFileNotFoundException()
{
string rootedPath = Path.GetFullPath(Guid.NewGuid().ToString("N"));
AssertExtensions.ThrowsContains<FileNotFoundException>(() => Assembly.LoadFile(rootedPath), rootedPath);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFile_PartiallyQualifiedPath_ThrowsArgumentException()
{
string path = "System.Runtime.Tests.dll";
Expand All @@ -384,7 +391,7 @@ public void LoadFile_PartiallyQualifiedPath_ThrowsArgumentException()

// This test should apply equally to Unix, but this reliably hits a particular one of the
// myriad ways that assembly load can fail
[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
[PlatformSpecific(TestPlatforms.Windows)]
public void LoadFile_ValidPEBadIL_ThrowsBadImageFormatExceptionWithPath()
{
Expand All @@ -395,7 +402,7 @@ public void LoadFile_ValidPEBadIL_ThrowsBadImageFormatExceptionWithPath()
AssertExtensions.ThrowsContains<BadImageFormatException>(() => Assembly.LoadFile(path), path);
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
[InlineData(0)]
[InlineData(5)]
[InlineData(50)]
Expand All @@ -415,21 +422,21 @@ public void LoadFile_ValidPEBadIL_ThrowsBadImageFormatExceptionWithPath_ByInitia
AssertExtensions.ThrowsContains<BadImageFormatException>(() => Assembly.LoadFile(path), path);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFromUsingHashValue()
{
Assert.Throws<NotSupportedException>(() => Assembly.LoadFrom("abc", null, System.Configuration.Assemblies.AssemblyHashAlgorithm.SHA1));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFrom_SamePath_ReturnsEqualAssemblies()
{
Assembly assembly1 = Assembly.LoadFrom(DestTestAssemblyPath);
Assembly assembly2 = Assembly.LoadFrom(DestTestAssemblyPath);
Assert.Equal(assembly1, assembly2);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFrom_SameIdentityAsAssemblyWithDifferentPath_ReturnsEqualAssemblies()
{
Assembly assembly1 = Assembly.LoadFrom(AssemblyPathHelper.GetAssemblyLocation(typeof(AssemblyTests).Assembly));
Expand All @@ -440,42 +447,42 @@ public void LoadFrom_SameIdentityAsAssemblyWithDifferentPath_ReturnsEqualAssembl
Assert.Equal(assembly1, assembly2);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFrom_NullAssemblyFile_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("assemblyFile", () => Assembly.LoadFrom(null));
AssertExtensions.Throws<ArgumentNullException>("assemblyFile", () => Assembly.UnsafeLoadFrom(null));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFrom_EmptyAssemblyFile_ThrowsArgumentException()
{
AssertExtensions.Throws<ArgumentException>("path", null, (() => Assembly.LoadFrom("")));
AssertExtensions.Throws<ArgumentException>("path", null, (() => Assembly.UnsafeLoadFrom("")));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFrom_NoSuchFile_ThrowsFileNotFoundException()
{
Assert.Throws<FileNotFoundException>(() => Assembly.LoadFrom("NoSuchPath"));
Assert.Throws<FileNotFoundException>(() => Assembly.UnsafeLoadFrom("NoSuchPath"));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void UnsafeLoadFrom_SamePath_ReturnsEqualAssemblies()
{
Assembly assembly1 = Assembly.UnsafeLoadFrom(DestTestAssemblyPath);
Assembly assembly2 = Assembly.UnsafeLoadFrom(DestTestAssemblyPath);
Assert.Equal(assembly1, assembly2);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadFrom_WithHashValue_ThrowsNotSupportedException()
{
Assert.Throws<NotSupportedException>(() => Assembly.LoadFrom(DestTestAssemblyPath, new byte[0], Configuration.Assemblies.AssemblyHashAlgorithm.None));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void LoadModule()
{
Assembly assembly = typeof(AssemblyTests).Assembly;
Expand Down Expand Up @@ -513,7 +520,14 @@ public void Location_ExecutingAssembly_IsNotNull()
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] // single file
public void CodeBase()
{
Assert.NotEmpty(Helpers.ExecutingAssembly.CodeBase);
if (PlatformDetection.IsNativeAot)
{
Assert.Throws<NotSupportedException>(() => _ = Helpers.ExecutingAssembly.CodeBase);
}
else
{
Assert.NotEmpty(Helpers.ExecutingAssembly.CodeBase);
}
}
#pragma warning restore SYSLIB0012

Expand Down Expand Up @@ -589,9 +603,16 @@ public void CreateQualifiedName()
[Fact]
public void GetReferencedAssemblies()
{
// It is too brittle to depend on the assembly references so we just call the method and check that it does not throw.
AssemblyName[] assemblies = Helpers.ExecutingAssembly.GetReferencedAssemblies();
Assert.NotEmpty(assemblies);
if (PlatformDetection.IsNativeAot)
{
Assert.Throws<PlatformNotSupportedException>(() => Helpers.ExecutingAssembly.GetReferencedAssemblies());
}
else
{
// It is too brittle to depend on the assembly references so we just call the method and check that it does not throw.
AssemblyName[] assemblies = Helpers.ExecutingAssembly.GetReferencedAssemblies();
Assert.NotEmpty(assemblies);
}
}

public static IEnumerable<object[]> Modules_TestData()
Expand Down Expand Up @@ -654,6 +675,7 @@ public static IEnumerable<object[]> GetCallingAssembly_TestData()

[Theory]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51673", typeof(PlatformDetection), nameof(PlatformDetection.IsBrowser), nameof(PlatformDetection.IsMonoAOT))]
[ActiveIssue("https://github.com/dotnet/runtimelab/issues/155", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
[MemberData(nameof(GetCallingAssembly_TestData))]
public void GetCallingAssembly(Assembly assembly1, Assembly assembly2, bool expected)
{
Expand All @@ -667,6 +689,7 @@ public void GetExecutingAssembly()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/67569", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void GetSatelliteAssemblyNeg()
{
Assert.Throws<ArgumentNullException>(() => (typeof(AssemblyTests).Assembly.GetSatelliteAssembly(null)));
Expand Down Expand Up @@ -701,7 +724,7 @@ public void AssemblyLoadFromStringNeg()
Assert.Throws<FileNotFoundException>(() => Assembly.Load("no such assembly")); // No such assembly
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void AssemblyLoadFromBytes()
{
Assembly assembly = typeof(AssemblyTests).Assembly;
Expand All @@ -725,7 +748,7 @@ public void AssemblyLoadFromBytesNeg()
Assert.Throws<BadImageFormatException>(() => Assembly.Load(new byte[0]));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/36892", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void AssemblyLoadFromBytesWithSymbols()
{
Expand All @@ -746,7 +769,7 @@ public void AssemblyReflectionOnlyLoadFromString()
Assert.Throws<PlatformNotSupportedException>(() => Assembly.ReflectionOnlyLoad(an.FullName));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported))]
public void AssemblyReflectionOnlyLoadFromBytes()
{
Assembly assembly = typeof(AssemblyTests).Assembly;
Expand Down Expand Up @@ -826,6 +849,7 @@ public static void AssemblyGetForwardedTypes()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtimelab/issues/155", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public static void AssemblyGetForwardedTypesLoadFailure()
{
Assembly a = typeof(TypeInForwardedAssembly).Assembly;
Expand Down
6 changes: 4 additions & 2 deletions src/libraries/System.Reflection/tests/ConstructorInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Invoke()
Assert.NotNull(obj);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsInvokingStaticConstructorsSupported))]
public void Invoke_StaticConstructor_NullObject_NullParameters()
{
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWithStaticConstructor));
Expand All @@ -68,7 +68,7 @@ public void Invoke_StaticConstructor_NullObject_NullParameters()
Assert.Null(obj);
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsInvokingStaticConstructorsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/40351", TestRuntimes.Mono)]
public void Invoke_StaticConstructorMultipleTimes()
{
Expand Down Expand Up @@ -127,6 +127,7 @@ public void Invoke_OneDimensionalArray_NegativeLengths_ThrowsOverflowException()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/67531", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void Invoke_TwoDimensionalArray_CustomBinder_IncorrectTypeArguments()
{
var ctor = typeof(int[,]).GetConstructor(new[] { typeof(int), typeof(int) });
Expand Down Expand Up @@ -155,6 +156,7 @@ public void Invoke_TwoParameters()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/67531", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void Invoke_TwoParameters_CustomBinder_IncorrectTypeArgument()
{
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Reflection/tests/MemberInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public void MethodInfoReflectedTypeDoesNotSurviveRuntimeHandles()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtimelab/issues/830", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void GetCustomAttributesData()
{
MemberInfo[] m = typeof(MemberInfoTests).GetMember("SampleClass");
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Reflection/tests/MethodInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ public static void Invoke_OptionalParameterUnassingableFromMissing_WithMissingVa
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/67531", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void Invoke_TwoParameters_CustomBinder_IncorrectTypeArguments()
{
MethodInfo method = GetMethod(typeof(MI_SubClass), nameof(MI_SubClass.StaticIntIntMethodReturningInt));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void Attributes(Type type, string name, int index, ParameterAttributes ex

[Theory]
[MemberData(nameof(s_CustomAttributesTestData))]
[ActiveIssue("https://github.com/dotnet/runtimelab/issues/830", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void CustomAttributesTest(Type attrType)
{
ParameterInfo parameterInfo = GetParameterInfo(typeof(ParameterInfoMetadata), "MethodWithOptionalDefaultOutInMarshalParam", 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<!-- these tests depend on the pdb files -->
<DebuggerSupport Condition="'$(DebuggerSupport)' == '' and '$(TargetOS)' == 'Browser'">true</DebuggerSupport>
</PropertyGroup>
<ItemGroup>
<RdXmlFile Include="default.rd.xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(CommonTestPath)System\Reflection\MockParameterInfo.cs"
Link="Common\System\Reflection\MockParameterInfo.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Reflection/tests/TypeInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ class G<T, U> where T : U
static volatile object s_boxedInt32;

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/67568", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void IsAssignableNullable()
{
Type nubInt = typeof(Nullable<int>);
Expand Down Expand Up @@ -1655,6 +1656,7 @@ private static (Type, Type) CreateGeneratedTypes()
}

[Theory, MemberData(nameof(GetMemberWithSameMetadataDefinitionAsData))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/67533", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void GetMemberWithSameMetadataDefinitionAs(Type openGenericType, Type closedGenericType, bool checkDeclaringType)
{
BindingFlags all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
Expand Down
Loading