-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for dotnet/linker#2358 (dotnet/linker#2369)
Currently this causes a crash in the linker due to null location scope. Commit migrated from dotnet/linker@da412ca
- Loading branch information
1 parent
74017e6
commit ac94046
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
.../LinkAttributes/Dependencies/LinkerAttributeRemovalAndPreserveAssembly_Lib.Descriptor.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<linker> | ||
<assembly fullname="test" /> | ||
</linker> |
10 changes: 10 additions & 0 deletions
10
....Tests.Cases/LinkAttributes/Dependencies/LinkerAttributeRemovalAndPreserveAssembly_Lib.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Mono.Linker.Tests.Cases.LinkAttributes.Dependencies | ||
{ | ||
public static class Used | ||
{ | ||
public static void Use () { } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...r.Tests.Cases/LinkAttributes/LinkerAttributeRemovalAndPreserveAssembly.LinkAttributes.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<linker> | ||
<assembly fullname="*"> | ||
<type fullname="Mono.Linker.Tests.Cases.LinkAttributes.AttributeToRemoveAttribute"> | ||
<attribute internal="RemoveAttributeInstances"/> | ||
</type> | ||
</assembly> | ||
</linker> |
48 changes: 48 additions & 0 deletions
48
.../test/Mono.Linker.Tests.Cases/LinkAttributes/LinkerAttributeRemovalAndPreserveAssembly.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
using Mono.Linker.Tests.Cases.LinkAttributes.Dependencies; | ||
|
||
namespace Mono.Linker.Tests.Cases.LinkAttributes | ||
{ | ||
[IgnoreDescriptors (false)] | ||
|
||
// The test verifies that removed attributes which are later on kept due to descriptors correctly warn. | ||
// The setup is: | ||
// - test assembly with the AttributeToRemoveAttribute type | ||
// - link attributes.xml which marks the attribute for removal (applied early, in this case via command line, but could be a embedded in the test assembly) | ||
// - the attribute is used by the test assembly | ||
// - another assembly lib.dll is added and is referenced (after the attribute is used/marked) | ||
// - This new assembly has a descriptor which marks the entire test assembly (note that it marks the TEST assembly) | ||
// - This marking causes the warning, as it's an explicit request to keep the attribute which was supposed to be removed | ||
|
||
[SetupLinkAttributesFile ("LinkerAttributeRemovalAndPreserveAssembly.LinkAttributes.xml")] | ||
|
||
[SetupCompileBefore ( | ||
"lib.dll", | ||
new[] { "Dependencies/LinkerAttributeRemovalAndPreserveAssembly_Lib.cs" })] | ||
// https://github.com/dotnet/linker/issues/2358 - adding the descriptor currently causes nullref in the linker | ||
// resources: new object[] { new string[] { "Dependencies/LinkerAttributeRemovalAndPreserveAssembly_Lib.Descriptor.xml", "ILLink.Descriptors.xml" } })] | ||
|
||
[ExpectedNoWarnings] | ||
|
||
class LinkerAttributeRemovalAndPreserveAssembly | ||
{ | ||
public static void Main () | ||
{ | ||
TestAttributeRemoval (); | ||
} | ||
|
||
[AttributeToRemoveAttribute] | ||
[Kept] | ||
static void TestAttributeRemoval () | ||
{ | ||
Used.Use (); | ||
} | ||
} | ||
|
||
public class AttributeToRemoveAttribute : Attribute { } | ||
} |