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
2 changes: 1 addition & 1 deletion external/cecil
Submodule cecil updated from 3bef7f to ff616b
53 changes: 0 additions & 53 deletions test/ILLink.RoslynAnalyzer.Tests/TestCase.cs

This file was deleted.

47 changes: 16 additions & 31 deletions test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,29 @@ public static async Task RunTestFile (string suiteName, string testName, params
SourceText.From (File.OpenRead (testPath), Encoding.UTF8),
path: testPath);

var testDependenciesSource = TestCase.GetTestDependencies (tree)
var testDependenciesSource = GetTestDependencies (rootSourceDir, tree)
.Select (f => SyntaxFactory.ParseSyntaxTree (SourceText.From (File.OpenRead (f))));
var comp = await TestCaseCompilation.CreateCompilation (
var (comp, model) = await TestCaseCompilation.CreateCompilation (
tree,
msbuildProperties,
additionalSources: testDependenciesSource);
foreach (var testCase in BuildTestCasesForTree (tree)) {
testCase.Run (comp);
}

var diags = await comp.GetAnalyzerDiagnosticsAsync ();
var testChecker = new TestChecker ((CSharpSyntaxTree) tree, model, diags);
testChecker.Check ();
}

/// <summary>
/// Builds a <see cref="TestCase" /> for each member in the tree.
/// </summary>
private static IEnumerable<TestCase> BuildTestCasesForTree (SyntaxTree tree)
private static IEnumerable<string> GetTestDependencies (string rootSourceDir, SyntaxTree testSyntaxTree)
{
var root = tree.GetRoot ();
foreach (var node in root.DescendantNodes ()) {
if (node is MemberDeclarationSyntax m) {
var attrs = m.AttributeLists.SelectMany (al => al.Attributes.Where (IsWellKnown)).ToList ();
if (attrs.Count > 0) {
yield return new TestCase (m, attrs);
}
}
}

static bool IsWellKnown (AttributeSyntax attr)
{
switch (attr.Name.ToString ()) {
// Currently, the analyzer's test infra only understands these attributes when placed on methods.
case "ExpectedWarning":
case "LogContains":
case "LogDoesNotContain":
case "UnrecognizedReflectionAccessPattern":
return true;
}

return false;
foreach (var attribute in testSyntaxTree.GetRoot ().DescendantNodes ().OfType<AttributeSyntax> ()) {
if (attribute.Name.ToString () != "SetupCompileBefore")
continue;

var testNamespace = testSyntaxTree.GetRoot ().DescendantNodes ().OfType<NamespaceDeclarationSyntax> ().Single ().Name.ToString ();
var testSuiteName = testNamespace.Substring (testNamespace.LastIndexOf ('.') + 1);
var args = LinkerTestBase.GetAttributeArguments (attribute);
foreach (var sourceFile in ((ImplicitArrayCreationExpressionSyntax) args["#1"]).DescendantNodes ().OfType<LiteralExpressionSyntax> ())
yield return Path.Combine (rootSourceDir, testSuiteName, LinkerTestBase.GetStringFromExpression (sourceFile));
}
}

Expand Down
Loading