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
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ public Task VerifyDefineAttributeBehavior()
return RunTest(allowMissingWarnings: true);
}

[Fact]
public Task VerifyKeptAttributeAttributeWorks()
{
return RunTest(allowMissingWarnings: true);
}

[Fact]
public Task VerifyLocalsAreChanged()
{
return RunTest(allowMissingWarnings: true);
}

[Fact]
public Task VerifyResourceInAssemblyAttributesBehavior()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,18 @@ public KeptAttributeAttribute(Type type)
{
ArgumentNullException.ThrowIfNull(type);
}

/// <summary>
/// Use this constructor when you want to explicitly verify that an attribute with specific parameters survived.
///
/// This is useful when you have a test that has multiple attributes of the same type but passed each is passed different parameters
/// and you want to verify which one(s) survived
/// </summary>
/// <param name="type"></param>
/// <param name="args"></param>
Comment thread
sbomer marked this conversation as resolved.
public KeptAttributeAttribute(Type type, params object[] args)
{
ArgumentNullException.ThrowIfNull(type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
using Mono.Linker.Tests.Cases.Reflection.Dependencies;
using Mono.Linker.Tests.Cases.Reflection.Dependencies.Library;

[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAssociationAttribute<UsedTypeMap>))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAssociationAttribute<UsedProxyTypeMap>))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedExternalTypeMap>))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedWithoutAssemblyTargetUniverse>))]
[assembly: TypeMap<UsedTypeMap>("TrimTargetIsTarget", typeof(TargetAndTrimTarget), typeof(TargetAndTrimTarget))]
[assembly: TypeMap<UsedTypeMap>("TrimTargetIsUnrelated", typeof(TargetType), typeof(TrimTarget))]
[assembly: TypeMap<UsedTypeMap>(nameof(AllocatedNoTypeCheckClassTarget), typeof(AllocatedNoTypeCheckClassTarget), typeof(AllocatedNoTypeCheckClass))]
Expand All @@ -33,28 +28,48 @@
[assembly: TypeMap<UsedTypeMap>("Ldobj", typeof(LdobjTarget), typeof(LdobjType))]
[assembly: TypeMap<UsedTypeMap>("ArrayElement", typeof(ArrayElementTarget), typeof(ArrayElement))]
[assembly: TypeMap<UsedTypeMap>("TrimTargetIsAllocatedNoTypeCheckNoBoxStruct", typeof(ConstructedNoTypeCheckOrBoxTarget), typeof(ConstructedNoTypeCheckNoBoxStruct))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "TrimTargetIsTarget", typeof(TargetAndTrimTarget), typeof(TargetAndTrimTarget))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "TrimTargetIsUnrelated", typeof(TargetType), typeof(TrimTarget))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), nameof(AllocatedNoTypeCheckClassTarget), typeof(AllocatedNoTypeCheckClassTarget), typeof(AllocatedNoTypeCheckClass))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), nameof(AlloctedNoTypeCheckStructTarget), typeof(AlloctedNoTypeCheckStructTarget), typeof(AllocatedNoTypeCheckStruct))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "TypeMapEntryOnly", typeof(TypeMapEntryOnly))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), nameof(UnboxedOnlyTarget), typeof(UnboxedOnlyTarget), typeof(UnboxedOnly))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "TypedRefSource", typeof(MakeRefTargetType), typeof(MakeRef))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "TypedRefTarget", typeof(RefValueTargetType), typeof(RefValue))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "Constrained", typeof(ConstrainedTarget), typeof(Constrained))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "ConstrainedStatic", typeof(ConstraintedStaticTarget), typeof(ConstrainedStatic))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "Ldobj", typeof(LdobjTarget), typeof(LdobjType))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "ArrayElement", typeof(ArrayElementTarget), typeof(ArrayElement))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedTypeMap>), "TrimTargetIsAllocatedNoTypeCheckNoBoxStruct", typeof(ConstructedNoTypeCheckOrBoxTarget), typeof(ConstructedNoTypeCheckNoBoxStruct))]

// The TypeMap Universes are kept separate such that Proxy attributes shouldn't be kept if only the External type map is needed.
[assembly: TypeMap<UsedExternalTypeMap>("UsedOnlyForExternalTypeMap", typeof(UsedExternalTarget), typeof(UsedTrimTarget))] // Kept
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedExternalTypeMap>), "UsedOnlyForExternalTypeMap", typeof(UsedExternalTarget), typeof(UsedTrimTarget))]
[assembly: TypeMapAssociation<UsedExternalTypeMap>(typeof(UsedProxySource), typeof(UsedProxyTarget))] // Removed

// The TypeMap Universes are kept separate such that External attributes shouldn't be kept if only the Proxy type map is needed.
[assembly: TypeMap<UsedProxyTypeMap>("UsedOnlyForExternalTypeMap", typeof(UsedExternalTarget2), typeof(UsedTrimTarget2))] // Removed
[assembly: TypeMapAssociation<UsedProxyTypeMap>(typeof(UsedProxySource2), typeof(UsedProxyTarget2))] // Kept
[assembly: KeptAttributeAttribute(typeof(TypeMapAssociationAttribute<UsedProxyTypeMap>), typeof(UsedProxySource2), typeof(UsedProxyTarget2))]

[assembly: TypeMapAssociation<UsedTypeMap>(typeof(SourceClass), typeof(ProxyType))]
[assembly: TypeMapAssociation<UsedTypeMap>(typeof(TypeCheckOnlyClass), typeof(TypeCheckOnlyProxy))]
[assembly: TypeMapAssociation<UsedTypeMap>(typeof(AllocatedNoBoxStructType), typeof(AllocatedNoBoxProxy))]
[assembly: TypeMapAssociation<UsedTypeMap>(typeof(I), typeof(IImpl))]
[assembly: TypeMapAssociation<UsedTypeMap>(typeof(IInterfaceWithDynamicImpl), typeof(IDynamicImpl))]
[assembly: TypeMapAssociation<UsedTypeMap>(typeof(ArrayElement), typeof(ArrayElementProxy))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAssociationAttribute<UsedTypeMap>), typeof(SourceClass), typeof(ProxyType))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAssociationAttribute<UsedTypeMap>), typeof(AllocatedNoBoxStructType), typeof(AllocatedNoBoxProxy))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAssociationAttribute<UsedTypeMap>), typeof(IInterfaceWithDynamicImpl), typeof(IDynamicImpl))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAssociationAttribute<UsedTypeMap>), typeof(ArrayElement), typeof(ArrayElementProxy))]

[assembly: TypeMap<UnusedTypeMap>("UnusedName", typeof(UnusedTargetType), typeof(TrimTarget))]
[assembly: TypeMapAssociation<UsedTypeMap>(typeof(UnusedSourceClass), typeof(UnusedProxyType))]
[assembly: TypeMap<UsedTypeMap>("ClassWithStaticMethod", typeof(TargetType4), typeof(ClassWithStaticMethod))]
[assembly: TypeMap<UsedTypeMap>("ClassWithStaticMethodAndField", typeof(TargetType5), typeof(ClassWithStaticMethodAndField))]

[assembly: TypeMap<UsedWithoutAssemblyTargetUniverse>("UnimportantString", typeof(PreservedTargetType))]
[assembly: KeptAttributeAttribute(typeof(TypeMapAttribute<UsedWithoutAssemblyTargetUniverse>), "UnimportantString", typeof(PreservedTargetType))]

[assembly: KeptAttributeAttribute(typeof(TypeMapAssemblyTargetAttribute<UsedTypeMap>))]
[assembly: TypeMapAssemblyTarget<UsedTypeMap>("library")]
Expand Down
Loading
Loading