Skip to content

Commit a0fa317

Browse files
TheSmallPixelclaude
andcommitted
ci: add build-and-test workflow with smoke test
Adds .github/workflows/ci.yml running on push to main and PRs. Builds the analyzer and runs two xUnit smoke tests that instantiate CodeGraphWalker against trivial C# sources and assert graph output. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 298d373 commit a0fa317

3 files changed

Lines changed: 117 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: actions/setup-dotnet@v4
16+
with:
17+
dotnet-version: '8.0.x'
18+
19+
- name: Build analyzer
20+
run: dotnet build --configuration Release tools/CodeAnalysisTool/CodeAnalysisTool.csproj
21+
22+
- name: Build tests
23+
run: dotnet build --configuration Release tools/CodeAnalysisTool.Tests/CodeAnalysisTool.Tests.csproj
24+
25+
- name: Run tests
26+
run: dotnet test --configuration Release --no-build --logger "console;verbosity=normal" tools/CodeAnalysisTool.Tests/CodeAnalysisTool.Tests.csproj
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<Nullable>enable</Nullable>
7+
<LangVersion>latest</LangVersion>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
12+
<PackageReference Include="xunit" Version="2.9.2" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\CodeAnalysisTool\CodeAnalysisTool.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using Microsoft.CodeAnalysis;
2+
using Microsoft.CodeAnalysis.CSharp;
3+
using Xunit;
4+
5+
namespace CodeAnalysisTool.Tests;
6+
7+
public class WalkerSmokeTests
8+
{
9+
[Fact]
10+
public void Walker_emits_namespace_class_and_method_nodes_for_trivial_source()
11+
{
12+
const string source = @"
13+
namespace Demo
14+
{
15+
public class Greeter
16+
{
17+
public string Hello(string name) => $""hi {name}"";
18+
}
19+
}";
20+
21+
var tree = CSharpSyntaxTree.ParseText(source);
22+
var compilation = CSharpCompilation.Create(
23+
"Smoke",
24+
new[] { tree },
25+
new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) });
26+
27+
var walker = new CodeGraphWalker
28+
{
29+
SemanticModel = compilation.GetSemanticModel(tree)
30+
};
31+
walker.SetCurrentFile("Greeter.cs");
32+
walker.Visit(tree.GetRoot());
33+
34+
var graph = walker.GetGraph();
35+
36+
Assert.NotEmpty(graph.Nodes);
37+
Assert.Contains(graph.Nodes, n => n.Group == "namespace");
38+
Assert.Contains(graph.Nodes, n => n.Group == "class");
39+
Assert.Contains(graph.Nodes, n => n.Group == "method");
40+
}
41+
42+
[Fact]
43+
public void Walker_emits_links_between_namespace_and_class()
44+
{
45+
const string source = @"
46+
namespace MyApp
47+
{
48+
public class Service
49+
{
50+
public void Run() { }
51+
}
52+
}";
53+
54+
var tree = CSharpSyntaxTree.ParseText(source);
55+
var compilation = CSharpCompilation.Create(
56+
"Links",
57+
new[] { tree },
58+
new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) });
59+
60+
var walker = new CodeGraphWalker
61+
{
62+
SemanticModel = compilation.GetSemanticModel(tree)
63+
};
64+
walker.SetCurrentFile("Service.cs");
65+
walker.Visit(tree.GetRoot());
66+
67+
var graph = walker.GetGraph();
68+
69+
Assert.NotEmpty(graph.Links);
70+
}
71+
}

0 commit comments

Comments
 (0)