Skip to content

Commit 53eb701

Browse files
committed
Add hot reload test that adds custom attributes
This test adds new rows to the CustomAttribute table with both new a class and a new method as parents. That should result in an unsorted table, which CoreCLR should be able to handle.
1 parent fe67c3f commit 53eb701

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
using System;
4+
5+
6+
namespace System.Reflection.Metadata.ApplyUpdate.Test
7+
{
8+
[Obsolete]
9+
public class ClassWithCustomAttributes {
10+
[Obsolete]
11+
public static string Method () {
12+
return null;
13+
}
14+
}
15+
}
16+
17+
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
using System;
4+
5+
6+
namespace System.Reflection.Metadata.ApplyUpdate.Test
7+
{
8+
[Obsolete]
9+
public class ClassWithCustomAttributes {
10+
[Obsolete]
11+
public static string Method () {
12+
return null;
13+
}
14+
}
15+
16+
[Obsolete]
17+
public class ClassWithCustomAttributes2 {
18+
[Obsolete]
19+
public static string Method2 () {
20+
return null;
21+
}
22+
}
23+
}
24+
25+
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<RootNamespace>System.Runtime.Loader.Tests</RootNamespace>
4+
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
5+
<TestRuntime>true</TestRuntime>
6+
<DeltaScript>deltascript.json</DeltaScript>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="ClassWithCustomAttributes.cs" />
10+
</ItemGroup>
11+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"changes": [
3+
{"document": "ClassWithCustomAttributes.cs", "update": "ClassWithCustomAttributes_v1.cs"},
4+
]
5+
}
6+

src/libraries/System.Runtime.Loader/tests/ApplyUpdateTest.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,49 @@ void StaticMethodBodyUpdate()
3838
Assert.Equal ("NEWEST STRING", r);
3939
});
4040
}
41+
42+
[Fact]
43+
[ActiveIssue("xyz", TestRuntimes.Mono)]
44+
void ClassWithCustomAttributes()
45+
{
46+
ApplyUpdateUtil.TestCase(static () =>
47+
{
48+
// Get the custom attribtues from the newly-added type and method and check
49+
// That they are the expected ones
50+
var className = "System.Reflection.Metadata.ApplyUpdate.Test.ClassWithCustomAttributes2";
51+
var methodName = "Method2";
52+
#pragma warning disable CS0612
53+
var assm = typeof(ApplyUpdate.Test.ClassWithCustomAttributes).Assembly;
54+
#pragma warning restore CS0612
55+
56+
var ty = assm.GetType(className, throwOnError: false);
57+
58+
Assert.Null (ty);
59+
60+
ApplyUpdateUtil.ApplyUpdate(assm);
61+
62+
ty = assm.GetType(className, throwOnError: false);
63+
64+
Assert.NotNull (ty);
65+
66+
var cattrs = Attribute.GetCustomAttributes(ty);
67+
68+
Assert.NotNull(cattrs);
69+
Assert.Equal(1, cattrs.Length);
70+
Assert.NotNull(cattrs[0]);
71+
Assert.Equal(typeof(ObsoleteAttribute), cattrs[0].GetType());
72+
73+
var mi = ty.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
74+
75+
Assert.NotNull (mi);
76+
77+
cattrs = Attribute.GetCustomAttributes(mi);
78+
79+
Assert.NotNull(cattrs);
80+
Assert.Equal(1, cattrs.Length);
81+
Assert.NotNull(cattrs[0]);
82+
Assert.Equal(typeof(ObsoleteAttribute), cattrs[0].GetType());
83+
});
84+
}
4185
}
4286
}

src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
<ProjectReference Include="LoaderLinkTest.Shared\LoaderLinkTest.Shared.csproj" />
4040
<ProjectReference Include="LoaderLinkTest.Dynamic\LoaderLinkTest.Dynamic.csproj" />
4141
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.MethodBody1\System.Reflection.Metadata.ApplyUpdate.Test.MethodBody1.csproj" />
42+
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.ClassWithCustomAttributes\System.Reflection.Metadata.ApplyUpdate.Test.ClassWithCustomAttributes.csproj" />
43+
4244
</ItemGroup>
4345
<ItemGroup Condition="'$(TargetOS)' == 'Browser'">
4446
<WasmFilesToIncludeFromPublishDir Include="$(AssemblyName).dll" />
@@ -54,6 +56,9 @@
5456
<TrimmerRootAssembly
5557
Condition="$([System.String]::Copy('%(ResolvedFileToPublish.FileName)%(ResolvedFileToPublish.Extension)').EndsWith('System.Reflection.Metadata.ApplyUpdate.Test.MethodBody1.dll'))"
5658
Include="%(ResolvedFileToPublish.FullPath)" />
59+
<TrimmerRootAssembly
60+
Condition="$([System.String]::Copy('%(ResolvedFileToPublish.FileName)%(ResolvedFileToPublish.Extension)').EndsWith('System.Reflection.Metadata.ApplyUpdate.Test.ClassWithCustomAttributes.dll'))"
61+
Include="%(ResolvedFileToPublish.FullPath)" />
5762
</ItemGroup>
5863
</Target>
5964

0 commit comments

Comments
 (0)