Skip to content

Commit 017206b

Browse files
committed
feat: support static equality comparer
1 parent 13eaed8 commit 017206b

340 files changed

Lines changed: 6105 additions & 1692 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Generator.Equals.Tests/Analyzers/CrossAssemblyEquatableTests.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public partial class ExternalType : IEquatable<ExternalType>
6666

6767
var externalCompilation = CSharpCompilation.Create(
6868
"ExternalLib",
69-
new[] { CSharpSyntaxTree.ParseText(externalSource) },
69+
new[] { CSharpSyntaxTree.ParseText(externalSource, cancellationToken: TestContext.Current.CancellationToken) },
7070
CoreReferences,
7171
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
7272

7373
// Verify the external compilation has no errors
74-
var externalDiagnostics = externalCompilation.GetDiagnostics();
74+
var externalDiagnostics = externalCompilation.GetDiagnostics(TestContext.Current.CancellationToken);
7575
var errors = externalDiagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).ToList();
7676
if (errors.Count > 0)
7777
throw new Exception($"External compilation had errors: {string.Join(", ", errors.Select(e => e.GetMessage()))}");
@@ -97,12 +97,12 @@ public partial class Container
9797

9898
var mainCompilation = CSharpCompilation.Create(
9999
"MainApp",
100-
new[] { CSharpSyntaxTree.ParseText(mainSource) },
100+
new[] { CSharpSyntaxTree.ParseText(mainSource, cancellationToken: TestContext.Current.CancellationToken) },
101101
mainReferences,
102102
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
103103

104104
// Verify the main compilation has no errors
105-
var mainDiagnostics = mainCompilation.GetDiagnostics();
105+
var mainDiagnostics = mainCompilation.GetDiagnostics(TestContext.Current.CancellationToken);
106106
var mainErrors = mainDiagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).ToList();
107107
if (mainErrors.Count > 0)
108108
throw new Exception($"Main compilation had errors: {string.Join(", ", mainErrors.Select(e => e.GetMessage()))}");
@@ -153,7 +153,7 @@ public partial class ExternalType : IEquatable<ExternalType>
153153

154154
var externalCompilation = CSharpCompilation.Create(
155155
"ExternalLib",
156-
new[] { CSharpSyntaxTree.ParseText(externalSource) },
156+
new[] { CSharpSyntaxTree.ParseText(externalSource, cancellationToken: TestContext.Current.CancellationToken) },
157157
CoreReferences,
158158
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
159159

@@ -176,7 +176,7 @@ public partial class Container
176176

177177
var mainCompilation = CSharpCompilation.Create(
178178
"MainApp",
179-
new[] { CSharpSyntaxTree.ParseText(mainSource) },
179+
new[] { CSharpSyntaxTree.ParseText(mainSource, cancellationToken: TestContext.Current.CancellationToken) },
180180
mainReferences,
181181
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
182182

@@ -185,7 +185,7 @@ public partial class Container
185185
var compilationWithAnalyzers = mainCompilation.WithAnalyzers(
186186
ImmutableArray.Create(analyzer));
187187

188-
var analyzerDiagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync();
188+
var analyzerDiagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync(TestContext.Current.CancellationToken);
189189

190190
// Filter for GE002 diagnostics
191191
var ge002Diagnostics = analyzerDiagnostics
@@ -214,12 +214,12 @@ public partial record ExternalSettings
214214

215215
var externalCompilation = CSharpCompilation.Create(
216216
"ExternalLib",
217-
new[] { CSharpSyntaxTree.ParseText(externalSource) },
217+
new[] { CSharpSyntaxTree.ParseText(externalSource, cancellationToken: TestContext.Current.CancellationToken) },
218218
CoreReferences,
219219
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
220220

221221
// Verify the external compilation has no errors
222-
var externalDiagnostics = externalCompilation.GetDiagnostics();
222+
var externalDiagnostics = externalCompilation.GetDiagnostics(TestContext.Current.CancellationToken);
223223
var errors = externalDiagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).ToList();
224224
if (errors.Count > 0)
225225
throw new Exception($"External compilation had errors: {string.Join(", ", errors.Select(e => e.GetMessage()))}");
@@ -244,7 +244,7 @@ public readonly partial record struct ContainerState
244244

245245
var mainCompilation = CSharpCompilation.Create(
246246
"MainApp",
247-
new[] { CSharpSyntaxTree.ParseText(mainSource) },
247+
new[] { CSharpSyntaxTree.ParseText(mainSource, cancellationToken: TestContext.Current.CancellationToken) },
248248
mainReferences,
249249
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
250250

@@ -288,7 +288,7 @@ public partial record ExternalSettings
288288

289289
var externalCompilation = CSharpCompilation.Create(
290290
"ExternalLib",
291-
new[] { CSharpSyntaxTree.ParseText(externalSource) },
291+
new[] { CSharpSyntaxTree.ParseText(externalSource, cancellationToken: TestContext.Current.CancellationToken) },
292292
CoreReferences,
293293
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
294294

@@ -311,7 +311,7 @@ public readonly partial record struct ContainerState
311311

312312
var mainCompilation = CSharpCompilation.Create(
313313
"MainApp",
314-
new[] { CSharpSyntaxTree.ParseText(mainSource) },
314+
new[] { CSharpSyntaxTree.ParseText(mainSource, cancellationToken: TestContext.Current.CancellationToken) },
315315
mainReferences,
316316
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
317317

@@ -320,7 +320,7 @@ public readonly partial record struct ContainerState
320320
var compilationWithAnalyzers = mainCompilation.WithAnalyzers(
321321
ImmutableArray.Create(analyzer));
322322

323-
var analyzerDiagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync();
323+
var analyzerDiagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync(TestContext.Current.CancellationToken);
324324

325325
var ge002Diagnostics = analyzerDiagnostics
326326
.Where(d => d.Id == "GE002")
@@ -355,12 +355,12 @@ public partial record ExternalSettings
355355

356356
var externalCompilation = CSharpCompilation.Create(
357357
"ExternalLib",
358-
new[] { CSharpSyntaxTree.ParseText(externalSource) },
358+
new[] { CSharpSyntaxTree.ParseText(externalSource, cancellationToken: TestContext.Current.CancellationToken) },
359359
CoreReferences,
360360
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
361361

362362
// Emit to actual DLL
363-
var emitResult = externalCompilation.Emit(externalDllPath);
363+
var emitResult = externalCompilation.Emit(externalDllPath, cancellationToken: TestContext.Current.CancellationToken);
364364
if (!emitResult.Success)
365365
{
366366
var errors = emitResult.Diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error);
@@ -393,12 +393,12 @@ public readonly partial record struct ContainerState
393393

394394
var mainCompilation = CSharpCompilation.Create(
395395
"MainApp",
396-
new[] { CSharpSyntaxTree.ParseText(mainSource) },
396+
new[] { CSharpSyntaxTree.ParseText(mainSource, cancellationToken: TestContext.Current.CancellationToken) },
397397
mainReferences,
398398
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
399399

400400
// Debug: Check compilation errors first
401-
var mainErrors = mainCompilation.GetDiagnostics().Where(d => d.Severity == DiagnosticSeverity.Error).ToList();
401+
var mainErrors = mainCompilation.GetDiagnostics(TestContext.Current.CancellationToken).Where(d => d.Severity == DiagnosticSeverity.Error).ToList();
402402
if (mainErrors.Count > 0)
403403
throw new Exception($"Main compilation had errors: {string.Join(", ", mainErrors.Select(e => e.GetMessage()))}");
404404

@@ -444,7 +444,7 @@ public readonly partial record struct ContainerState
444444
var compilationWithAnalyzers = mainCompilation.WithAnalyzers(
445445
ImmutableArray.Create(analyzer));
446446

447-
var analyzerDiagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync();
447+
var analyzerDiagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync(TestContext.Current.CancellationToken);
448448

449449
var ge002Diagnostics = analyzerDiagnostics
450450
.Where(d => d.Id == "GE002")
@@ -485,7 +485,7 @@ public AliasAttribute(string name) { }
485485

486486
var mockPackageCompilation = CSharpCompilation.Create(
487487
"MockPackage",
488-
new[] { CSharpSyntaxTree.ParseText(mockPackageSource) },
488+
new[] { CSharpSyntaxTree.ParseText(mockPackageSource, cancellationToken: TestContext.Current.CancellationToken) },
489489
CoreReferences,
490490
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
491491

@@ -509,11 +509,11 @@ public sealed partial record Settings
509509
var externalRefs = CoreReferences.Append(mockPackageReference).ToArray();
510510
var externalCompilation = CSharpCompilation.Create(
511511
"ExternalLib",
512-
new[] { CSharpSyntaxTree.ParseText(externalSource) },
512+
new[] { CSharpSyntaxTree.ParseText(externalSource, cancellationToken: TestContext.Current.CancellationToken) },
513513
externalRefs,
514514
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
515515

516-
var externalErrors = externalCompilation.GetDiagnostics().Where(d => d.Severity == DiagnosticSeverity.Error).ToList();
516+
var externalErrors = externalCompilation.GetDiagnostics(TestContext.Current.CancellationToken).Where(d => d.Severity == DiagnosticSeverity.Error).ToList();
517517
if (externalErrors.Count > 0)
518518
throw new Exception($"External compilation had errors: {string.Join(", ", externalErrors.Select(e => e.GetMessage()))}");
519519

@@ -537,7 +537,7 @@ public readonly partial record struct ContainerState
537537

538538
var mainCompilation = CSharpCompilation.Create(
539539
"MainApp",
540-
new[] { CSharpSyntaxTree.ParseText(mainSource) },
540+
new[] { CSharpSyntaxTree.ParseText(mainSource, cancellationToken: TestContext.Current.CancellationToken) },
541541
mainReferences,
542542
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
543543

@@ -562,7 +562,7 @@ public readonly partial record struct ContainerState
562562
var compilationWithAnalyzers = mainCompilation.WithAnalyzers(
563563
ImmutableArray.Create(analyzer));
564564

565-
var analyzerDiagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync();
565+
var analyzerDiagnostics = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync(TestContext.Current.CancellationToken);
566566

567567
var ge002Diagnostics = analyzerDiagnostics
568568
.Where(d => d.Id == "GE002")
@@ -592,11 +592,11 @@ public sealed partial record ExternalSettings
592592

593593
var externalCompilation = CSharpCompilation.Create(
594594
"ExternalLib",
595-
new[] { CSharpSyntaxTree.ParseText(externalSource) },
595+
new[] { CSharpSyntaxTree.ParseText(externalSource, cancellationToken: TestContext.Current.CancellationToken) },
596596
CoreReferences,
597597
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
598598

599-
var errors = externalCompilation.GetDiagnostics()
599+
var errors = externalCompilation.GetDiagnostics(TestContext.Current.CancellationToken)
600600
.Where(d => d.Severity == DiagnosticSeverity.Error).ToList();
601601
if (errors.Count > 0)
602602
throw new Exception($"Compilation errors: {string.Join(", ", errors.Select(e => e.GetMessage()))}");
@@ -605,7 +605,7 @@ public sealed partial record ExternalSettings
605605

606606
var mainCompilation = CSharpCompilation.Create(
607607
"MainApp",
608-
new[] { CSharpSyntaxTree.ParseText("// empty") },
608+
new[] { CSharpSyntaxTree.ParseText("// empty", cancellationToken: TestContext.Current.CancellationToken) },
609609
CoreReferences.Append(externalReference).ToArray(),
610610
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
611611

Generator.Equals.Tests/Classes/BaseEqualityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void PersonEquality(Person a, Person b, bool expected) =>
6363
[Theory]
6464
[MemberData(nameof(TargetFrameworks))]
6565
public Task VerifyGeneratedCode(TargetFramework fw) =>
66-
VerifyGeneratedSource(SampleSource, fw);
66+
VerifyGeneratedSource(SampleSource, fw, ct: TestContext.Current.CancellationToken);
6767

6868
const string SampleSource = """
6969
using Generator.Equals;

Generator.Equals.Tests/Classes/CustomEqualityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void Equality(Sample a, Sample b, bool expected) =>
5858
[Theory]
5959
[MemberData(nameof(TargetFrameworks))]
6060
public Task VerifyGeneratedCode(TargetFramework fw) =>
61-
VerifyGeneratedSource(SampleSource, fw);
61+
VerifyGeneratedSource(SampleSource, fw, ct: TestContext.Current.CancellationToken);
6262

6363
const string SampleSource = """
6464
using System.Collections.Generic;

Generator.Equals.Tests/Classes/DeepEqualityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void Equality(Sample a, Sample b, bool expected) =>
5959
[Theory]
6060
[MemberData(nameof(TargetFrameworks))]
6161
public Task VerifyGeneratedCode(TargetFramework fw) =>
62-
VerifyGeneratedSource(SampleSource, fw);
62+
VerifyGeneratedSource(SampleSource, fw, ct: TestContext.Current.CancellationToken);
6363

6464
const string SampleSource = """
6565
using Generator.Equals;

Generator.Equals.Tests/Classes/DictionaryEqualityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void Equality(Sample a, Sample b, bool expected) =>
7575
[Theory]
7676
[MemberData(nameof(TargetFrameworks))]
7777
public Task VerifyGeneratedCode(TargetFramework fw) =>
78-
VerifyGeneratedSource(SampleSource, fw);
78+
VerifyGeneratedSource(SampleSource, fw, ct: TestContext.Current.CancellationToken);
7979

8080
const string SampleSource = """
8181
using System.Collections.Generic;

Generator.Equals.Tests/Classes/EnumerableEqualityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void Equality(Sample a, Sample b, bool expected) =>
5656
[Theory]
5757
[MemberData(nameof(TargetFrameworks))]
5858
public Task VerifyGeneratedCode(TargetFramework fw) =>
59-
VerifyGeneratedSource(SampleSource, fw);
59+
VerifyGeneratedSource(SampleSource, fw, ct: TestContext.Current.CancellationToken);
6060

6161
const string SampleSource = """
6262
using System.Collections.Generic;

Generator.Equals.Tests/Classes/ExplicitModeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void Equality(Sample a, Sample b, bool expected) =>
4343
[Theory]
4444
[MemberData(nameof(TargetFrameworks))]
4545
public Task VerifyGeneratedCode(TargetFramework fw) =>
46-
VerifyGeneratedSource(SampleSource, fw);
46+
VerifyGeneratedSource(SampleSource, fw, ct: TestContext.Current.CancellationToken);
4747

4848
const string SampleSource = """
4949
using Generator.Equals;

Generator.Equals.Tests/Classes/FieldEqualityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void Equality(Sample a, Sample b, bool expected) =>
3838
[Theory]
3939
[MemberData(nameof(TargetFrameworks))]
4040
public Task VerifyGeneratedCode(TargetFramework fw) =>
41-
VerifyGeneratedSource(SampleSource, fw);
41+
VerifyGeneratedSource(SampleSource, fw, ct: TestContext.Current.CancellationToken);
4242

4343
const string SampleSource = """
4444
using Generator.Equals;

Generator.Equals.Tests/Classes/GapInheritanceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public partial class Child : Parent
6464

6565
[Theory, MemberData(nameof(TargetFrameworks))]
6666
public Task VerifyGeneratedCode(TargetFramework fw) =>
67-
VerifyGeneratedSource(SampleSource, fw);
67+
VerifyGeneratedSource(SampleSource, fw, ct: TestContext.Current.CancellationToken);
6868

6969
const string SampleSource = """
7070
using Generator.Equals;

Generator.Equals.Tests/Classes/GenericParameterEqualityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void Equality(Sample<string, int> a, Sample<string, int> b, bool expected
4040
[Theory]
4141
[MemberData(nameof(TargetFrameworks))]
4242
public Task VerifyGeneratedCode(TargetFramework fw) =>
43-
VerifyGeneratedSource(SampleSource, fw);
43+
VerifyGeneratedSource(SampleSource, fw, ct: TestContext.Current.CancellationToken);
4444

4545
const string SampleSource = """
4646
using Generator.Equals;

0 commit comments

Comments
 (0)