| Name | Message | Date |
|---|---|---|
| 📄 BuildCallGraphShould.cs | 6 days ago | |
| 📄 FindCalleesShould.cs | 6 days ago | |
| 📄 FindCallersShould.cs | 6 days ago | |
| 📄 SourceToCallGraphHelper.cs | 6 days ago |
📄
core/tests/CallGraphBuilderTests/BuildCallGraphShould.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System.Linq; using System.Threading; using System.Threading.Tasks; using GlobExpressions; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Text; using Shouldly; using Xunit; namespace Cfa.Tests.CallGraphBuilderTests; public sealed class BuildCallGraphShould { [Fact] public async Task ExcludeTestProjectMembersButNotProductionFilesNamedTests() { // Arrange using var workspace = new AdhocWorkspace(); var app = workspace.AddProject( ProjectInfo.Create( ProjectId.CreateNewId(), VersionStamp.Default, "App", "App", LanguageNames.CSharp, filePath: "/repo/App.csproj", compilationOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary), metadataReferences: [MetadataReference.CreateFromFile(typeof(object).Assembly.Location)] ) ); var tests = workspace.AddProject( ProjectInfo.Create( ProjectId.CreateNewId(), VersionStamp.Default, "App.Tests", "App.Tests", LanguageNames.CSharp, filePath: "/repo/App.Tests.csproj", compilationOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary), metadataReferences: [MetadataReference.CreateFromFile(typeof(object).Assembly.Location)], projectReferences: [new ProjectReference(app.Id)] ) ); workspace.AddDocument( app.Id, "Tests.cs", SourceText.From( """ public class App { public static void Target() { } public static void Caller() { Target(); } } """ ) ); workspace.AddDocument( tests.Id, "Production.cs", SourceText.From( """ class Tests { void Start() { Helper(); App.Target(); } void Helper() { } } """ ) ); var solution = workspace.CurrentSolution; var appCompilation = (await solution.GetProject(app.Id)!.GetCompilationAsync()).ShouldNotBeNull(); var testCompilation = (await solution.GetProject(tests.Id)!.GetCompilationAsync()).ShouldNotBeNull(); appCompilation.GetDiagnostics().ShouldBeEmpty(); testCompilation.GetDiagnostics().ShouldBeEmpty(); var start = testCompilation.GetTypeByMetadataName("Tests")!.GetMembers("Start").Single(); var target = appCompilation.GetTypeByMetadataName("App")!.GetMembers("Target").Single(); var builder = new CallGraphBuilder( new ScannerOptions { ExcludePatterns = [new("*Tests*")] }, solution, [appCompilation, testCompilation] ); // Act builder.FindCallees(start, CancellationToken.None); await builder.FindCallers(target, CancellationToken.None); // Assert builder.ReachableFromSymbols[start].ShouldHaveSingleItem().Target.Name.ShouldBe("Target"); builder.ReachesToSymbols[target].ShouldHaveSingleItem().Target.Name.ShouldBe("Caller"); } }