From 38658e77b85ef75825b8f16a1721120d034af479 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 7 Jun 2024 21:36:36 +0000 Subject: [PATCH] Add test --- .../TopLevelStatementsTests.cs | 6 ++++ .../DataFlow/FieldDataFlow.cs | 4 +-- .../DataFlow/MethodParametersDataFlow.cs | 4 +-- .../DataFlow/MethodReturnParameterDataFlow.cs | 2 +- .../DataFlow/MethodThisDataFlow.cs | 2 +- .../InvalidAnnotations.csproj | 1 + .../InvalidAnnotations/Program.cs | 28 +++++++++++++++++++ 7 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/InvalidAnnotations.csproj create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/Program.cs diff --git a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/TopLevelStatementsTests.cs b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/TopLevelStatementsTests.cs index 193a04193597ca..ce8db77a4266a5 100644 --- a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/TopLevelStatementsTests.cs +++ b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/TopLevelStatementsTests.cs @@ -13,5 +13,11 @@ public Task BasicDataFlow () { return RunTest (); } + + [Fact] + public Task InvalidAnnotations () + { + return RunTest (); + } } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs index be75f5dca1c44c..43d0ac582cc17b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs @@ -338,13 +338,13 @@ static void RequirePublicFields ( { } - [ExpectedWarning ("IL2077", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] + [UnexpectedWarning ("IL2077", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestFlowOutOfField () { RequirePublicFields (unsupportedTypeInstance); } - [ExpectedWarning ("IL2074", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] + [UnexpectedWarning ("IL2074", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] public static void Test () { var t = GetUnsupportedTypeInstance (); unsupportedTypeInstance = t; diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs index 4d9d0e5284db8f..bd3c5c4adfbbe3 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs @@ -244,7 +244,7 @@ class UnsupportedType () static UnsupportedType GetUnsupportedTypeInstance () => null; [ExpectedWarning ("IL2098", nameof (UnsupportedType))] - [ExpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] + [UnexpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void RequirePublicMethods ( [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] UnsupportedType unsupportedTypeInstance) @@ -259,7 +259,7 @@ static void RequirePublicFields ( { } - [ExpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] + [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] public static void Test () { var t = GetUnsupportedTypeInstance (); RequirePublicMethods (t); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs index b201db94ded6ec..bc94f0813be38b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs @@ -220,7 +220,7 @@ static void TestMethodReturnValue () { RequirePublicFields (t); } - [ExpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] + [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestCtorReturnValue () { var t = new UnsupportedType (); RequirePublicFields (t); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs index c57d784bce24db..e33bb8e54c41a1 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs @@ -122,7 +122,7 @@ static void RequirePublicFields ( [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] UnsupportedType unsupportedTypeInstance) { } - [ExpectedWarning ("IL2075", nameof (UnsupportedType), nameof (UnsupportedType.GetMethod), Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] + [UnexpectedWarning ("IL2075", nameof (UnsupportedType), nameof (UnsupportedType.GetMethod), Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestMethodThisParameter () { var t = GetUnsupportedTypeInstance (); t.GetMethod ("foo"); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/InvalidAnnotations.csproj b/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/InvalidAnnotations.csproj new file mode 100644 index 00000000000000..6b512ec9245ec3 --- /dev/null +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/InvalidAnnotations.csproj @@ -0,0 +1 @@ + diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/Program.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/Program.cs new file mode 100644 index 00000000000000..5874fff6b0abf2 --- /dev/null +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/Program.cs @@ -0,0 +1,28 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Diagnostics.CodeAnalysis; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +[assembly: ExpectedNoWarnings] + +Test (); + +[UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] +[Kept] +static void Test () { + RequireAll (GetUnsupportedType ()); +} + +[ExpectedWarning ("IL2098", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/101215")] +[Kept] +static void RequireAll( + [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] UnsupportedType f) {} + +[Kept] +static UnsupportedType GetUnsupportedType () => new UnsupportedType (); + +[Kept] +[KeptMember (".ctor()")] +class UnsupportedType {}