Skip to content

Commit effaf35

Browse files
authored
Improve tests for COM warnings from PInvokes (dotnet/linker#2080)
Use the ExpectedWarning test attributes. Add tests for more cases. Add tests for suppression and for RUC interaction. Commit migrated from dotnet/linker@a3f68c6
1 parent 02a30e7 commit effaf35

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,53 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Runtime.InteropServices;
45
using System.Text;
56
using Mono.Linker.Tests.Cases.Expectations.Assertions;
67

78
namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
89
{
9-
[LogContains ("SomeMethodTakingInterface")]
10-
[LogContains ("SomeMethodTakingObject")]
10+
[SkipKeptItemsValidation]
11+
[ExpectedNoWarnings]
1112
[KeptModuleReference ("Foo")]
1213
class ComPInvokeWarning
1314
{
15+
[UnconditionalSuppressMessage ("trim", "IL2026")]
1416
static void Main ()
1517
{
1618
SomeMethodTakingInterface (null);
1719
SomeMethodTakingObject (null);
20+
GetInterface ();
21+
CanSuppressWarningOnParameter (null);
22+
CanSuppressWarningOnReturnType ();
23+
CanSuppressWithRequiresUnreferencedCode (null);
1824
}
1925

20-
[Kept]
26+
[ExpectedWarning ("IL2050")]
2127
[DllImport ("Foo")]
2228
static extern void SomeMethodTakingInterface (IFoo foo);
2329

24-
[Kept]
30+
[ExpectedWarning ("IL2050")]
2531
[DllImport ("Foo")]
2632
static extern void SomeMethodTakingObject ([MarshalAs (UnmanagedType.IUnknown)] object obj);
2733

28-
[Kept]
34+
[ExpectedWarning ("IL2050")]
35+
[DllImport ("Foo")]
36+
static extern IFoo GetInterface ();
37+
38+
[UnconditionalSuppressMessage ("trim", "IL2050")]
39+
[DllImport ("Foo")]
40+
static extern void CanSuppressWarningOnParameter ([MarshalAs (UnmanagedType.IUnknown)] object obj);
41+
42+
[UnconditionalSuppressMessage ("trim", "IL2050")]
43+
[DllImport ("Foo")]
44+
static extern IFoo CanSuppressWarningOnReturnType ();
45+
46+
[ExpectedWarning ("IL2050")] // Issue https://github.com/mono/linker/issues/1989
47+
[RequiresUnreferencedCode ("test")]
48+
[DllImport ("Foo")]
49+
static extern void CanSuppressWithRequiresUnreferencedCode (IFoo foo);
50+
2951
interface IFoo { }
3052
}
3153
}

0 commit comments

Comments
 (0)