Skip to content

Commit 96e6074

Browse files
linkdotnetegil
authored andcommitted
feat: narrow predicate
1 parent 0ff9122 commit 96e6074

4 files changed

Lines changed: 8 additions & 19 deletions

File tree

src/bunit.generators/README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,3 @@ internal partial class ThidPartyStub { }
7474

7575
Current limitations of this approach:
7676
* The stubbed type is not allowed to be nested inside the test class.
77-
78-
## Developer notes
79-
80-
### Tips for developing with the generator
81-
82-
When changing the source generator, to see the effect, clearing the build cache may be necessary:
83-
84-
```
85-
dotnet build-server shutdown
86-
```
87-
88-
A good way to quickly see if the generate is producing output:
89-
90-
```
91-
dotnet build-server shutdown && dotnet clean && dotnet test -p:TargetFramework=net8.0
92-
```

src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
1919
{
2020
var classesToStub = context.SyntaxProvider
2121
.CreateSyntaxProvider(
22-
predicate: static (s, _) => s is InvocationExpressionSyntax,
22+
predicate: static (s, _) => s is InvocationExpressionSyntax
23+
{
24+
Expression: MemberAccessExpressionSyntax
25+
{
26+
Name.Identifier.Text: "AddStub"
27+
}
28+
},
2329
transform: static (ctx, _) => GetStubClassInfo(ctx))
2430
.Where(static m => m is not null)
2531
.Collect();

src/bunit.generators/Web.Stubs/AttributeStubGenerator/StubAttributeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
2323
var classesToStub = context.SyntaxProvider
2424
.ForAttributeWithMetadataName(
2525
AttributeFullQualifiedName,
26-
predicate: static (s, _) => s is ClassDeclarationSyntax,
26+
predicate: static (s, _) => s is ClassDeclarationSyntax c && c.AttributeLists.SelectMany(a => a.Attributes).Any(at => at.Name.ToString() == "Stub"),
2727
transform: static (ctx, _) => GetStubClassInfo(ctx))
2828
.Where(static m => m is not null);
2929

tests/bunit.generators.tests/Web.Stub/AddStubGeneratorTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Bunit.Web.Stub.Components;
2-
using Microsoft.AspNetCore.Components;
32

43
namespace Bunit.Web.Stub;
54

0 commit comments

Comments
 (0)