This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
Test restructure #2113
Closed
Closed
Test restructure #2113
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
609f292
Test restructure
tlakollo 5151793
Add raf source to testcaseutils so it can be shared between the analyzer
tlakollo fec8f41
Merge branch 'main' of https://github.com/mono/linker into TestRestru…
tlakollo 04b85b5
Add more attributes to RequiresCapability
tlakollo b7c79c9
Merge branch 'main' of https://github.com/mono/linker into TestRestru…
tlakollo 6cceb41
Add more RequiresAssemblyFiles tests
tlakollo d35a8e4
Merge branch 'main' of https://github.com/mono/linker into TestRestru…
tlakollo cf9c63a
Add lazy delegate tests
tlakollo fdaf485
Move mismatching attributes tests to linker
tlakollo d1cac9f
Create tests that mimic having a reference and source files in linker
tlakollo 957777a
Handle the case in which compiler generates a static constructor with
tlakollo 0877a61
PR comments
tlakollo 6d8511e
Merge branch 'main' of https://github.com/mono/linker into TestRestru…
tlakollo f1e2409
PR comments
tlakollo 5d52eaf
Merge branch 'main' of https://github.com/mono/linker into TestRestru…
tlakollo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule cecil
updated
from a27b1f to e069cd
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,7 +2,10 @@ | |
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
| using Xunit; | ||
|
|
||
|
|
@@ -13,20 +16,27 @@ namespace ILLink.RoslynAnalyzer.Tests | |
| /// </summary> | ||
| public class LinkerTestCases : TestCaseUtils | ||
| { | ||
| [Theory] | ||
| [MemberData (nameof (TestCaseUtils.GetTestData), parameters: nameof (RequiresCapability))] | ||
| public void RequiresCapability (MethodDeclarationSyntax m, List<AttributeSyntax> attrs) | ||
| private static Lazy<IEnumerable<MetadataReference>> _additionalReferences = new Lazy<IEnumerable<MetadataReference>> (LoadDependencies); | ||
|
|
||
| private static IEnumerable<MetadataReference> LoadDependencies () | ||
| { | ||
| switch (m.Identifier.ValueText) { | ||
| // There is a discrepancy between the way linker and the analyzer represent the location of the error, | ||
| // linker will point to the method caller and the analyzer will point to a line of code. | ||
| // The TestTypeIsBeforeFieldInit scenario is supported by the analyzer, just the diagnostic message is different | ||
| // We verify the analyzer generating the right diagnostic in RequiresUnreferencedCodeAnalyzerTests.cs | ||
| case "TestTypeIsBeforeFieldInit": | ||
| return; | ||
| List<MetadataReference> additionalReferences = new List<MetadataReference> (); | ||
| var s_refFiles = GetReferenceFilesByDirName (); | ||
| foreach (var refFile in s_refFiles["Dependencies"]) { | ||
| if (refFile.Contains ("RequiresCapability")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels somewhat fragile looking into the string of a filename here. |
||
| additionalReferences.Add (TestCaseUtils.GetCompilation (File.ReadAllText (refFile)).Result.EmitToImageReference ()); | ||
| } | ||
|
|
||
| RunTest<RequiresUnreferencedCodeAnalyzer> (m, attrs, UseMSBuildProperties (MSBuildPropertyOptionNames.EnableTrimAnalyzer)); | ||
| return additionalReferences; | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData (nameof (TestCaseUtils.GetTestData), parameters: "RequiresCapability")] | ||
| public void RequiresUnreferencedCodeCapability (SyntaxNode m, List<AttributeSyntax> attrs) => | ||
| RunTest<RequiresUnreferencedCodeAnalyzer> (m, attrs, _additionalReferences.Value, UseMSBuildProperties (MSBuildPropertyOptionNames.EnableTrimAnalyzer)); | ||
|
|
||
| [Theory] | ||
| [MemberData (nameof (TestCaseUtils.GetTestData), parameters: "RequiresCapability")] | ||
| public void RequiresAssemblyFilesCapability (SyntaxNode m, List<AttributeSyntax> attrs) => | ||
| RunTest<RequiresAssemblyFilesAnalyzer> (m, attrs, _additionalReferences.Value, UseMSBuildProperties (MSBuildPropertyOptionNames.EnableSingleFileAnalyzer)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not put this in LinkerTestCases.cs? It feels like
GetReferenceFilesByDirNameshould only be used there and have the dependencies resolved before compilation (ideally through looking at the linker attributes that we use to add assemblies to the compilation).