Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LinkerAttributeRemovalAndPreserveAssembly.cs « LinkAttributes « Mono.Linker.Tests.Cases « test - github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 779465c4d256ad597be8e40dbd0d0b555c1bf2ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 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" },
		resources: new object[] { new string[] { "Dependencies/LinkerAttributeRemovalAndPreserveAssembly_Lib.Descriptor.xml", "ILLink.Descriptors.xml" } })]

	[ExpectedWarning ("IL2045", FileName = "ILLink.Descriptors.xml in lib, Version=0.0.0.0, Culture=neutral, PublicKeyToken")]
	[ExpectedNoWarnings]

	[KeptMember (".ctor()")]
	class LinkerAttributeRemovalAndPreserveAssembly
	{
		public static void Main ()
		{
			TestAttributeRemoval ();
		}

		[AttributeToRemoveAttribute]
		[Kept]
		static void TestAttributeRemoval ()
		{
			Used.Use ();
		}
	}

	// The attribute is kept (partially) because we found out about it too late
	// It does report a warning though
	[Kept]
	[KeptBaseType (typeof (Attribute))]
	[KeptMember (".ctor()")]
	public class AttributeToRemoveAttribute : Attribute { }
}